From 1cabb9be0d3ae58de72e654f5c88f791c48f4ec5 Mon Sep 17 00:00:00 2001 From: Manisha Singh Date: Tue, 14 Jan 2025 15:35:02 +0530 Subject: [PATCH] chore: add variant class (#829) --- .../java/com/twilio/rest/voice/v2/Client.java | 261 ++++++++++++++++++ .../twilio/rest/voice/v2/ClientCreator.java | 84 ++++++ .../twilio/rest/voice/v2/ClientDeleter.java | 73 +++++ .../com/twilio/rest/voice/v2/Default.java | 120 ++++++++ .../twilio/rest/voice/v2/DefaultCreator.java | 84 ++++++ .../com/twilio/compliance/ComplianceTest.java | 3 +- 6 files changed, 624 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/twilio/rest/voice/v2/Client.java create mode 100644 src/main/java/com/twilio/rest/voice/v2/ClientCreator.java create mode 100644 src/main/java/com/twilio/rest/voice/v2/ClientDeleter.java create mode 100644 src/main/java/com/twilio/rest/voice/v2/Default.java create mode 100644 src/main/java/com/twilio/rest/voice/v2/DefaultCreator.java diff --git a/src/main/java/com/twilio/rest/voice/v2/Client.java b/src/main/java/com/twilio/rest/voice/v2/Client.java new file mode 100644 index 000000000..3b7c77777 --- /dev/null +++ b/src/main/java/com/twilio/rest/voice/v2/Client.java @@ -0,0 +1,261 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio API definition for public-api voice + * Powers Twilio public-api voice + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.voice.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.http.HttpMethod; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Client extends Resource { + + private static final long serialVersionUID = 20407420146524L; + + @ToString + public static class VoiceV2ClientConfigurationResponseConfigurationCallnotification { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + @Setter + private URI url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + @Getter + @Setter + private HttpMethod method; + + public static VoiceV2ClientConfigurationResponseConfigurationCallnotification fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + VoiceV2ClientConfigurationResponseConfigurationCallnotification.class + ); + } + } + + @ToString + public static class VoiceV2ClientConfigurationResponseConfiguration { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("callnotification") + @Getter + @Setter + private VoiceV2ClientConfigurationResponseConfigurationCallnotification callnotification; + + public static VoiceV2ClientConfigurationResponseConfiguration fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + VoiceV2ClientConfigurationResponseConfiguration.class + ); + } + } + + @ToString + public static class VoiceV2ClientConfigurationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + @Setter + private String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + @Getter + @Setter + private VoiceV2ClientConfigurationResponseConfiguration configuration; + + public VoiceV2ClientConfigurationRequest() {} + + public static VoiceV2ClientConfigurationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + VoiceV2ClientConfigurationRequest.class + ); + } + } + + public static ClientCreator creator() { + return new ClientCreator(); + } + + public static ClientDeleter deleter(final String pathIdOrFriendlyName) { + return new ClientDeleter(pathIdOrFriendlyName); + } + + /** + * Converts a JSON String into a Client object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Client object represented by the provided JSON + */ + public static Client fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Client.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 Client object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Client object represented by the provided JSON + */ + public static Client fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Client.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final String id; + private final String accountSid; + private final String friendlyName; + private final String description; + private final VoiceV2ClientConfigurationResponseConfiguration configuration; + + @JsonCreator + private Client( + @JsonProperty("id") final String id, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("description") final String description, + @JsonProperty( + "configuration" + ) final VoiceV2ClientConfigurationResponseConfiguration configuration + ) { + this.id = id; + this.accountSid = accountSid; + this.friendlyName = friendlyName; + this.description = description; + this.configuration = configuration; + } + + public final String getId() { + return this.id; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getFriendlyName() { + return this.friendlyName; + } + + public final String getDescription() { + return this.description; + } + + public final VoiceV2ClientConfigurationResponseConfiguration getConfiguration() { + return this.configuration; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Client other = (Client) o; + + return ( + Objects.equals(id, other.id) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(description, other.description) && + Objects.equals(configuration, other.configuration) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + accountSid, + friendlyName, + description, + configuration + ); + } +} diff --git a/src/main/java/com/twilio/rest/voice/v2/ClientCreator.java b/src/main/java/com/twilio/rest/voice/v2/ClientCreator.java new file mode 100644 index 000000000..3fb5778e2 --- /dev/null +++ b/src/main/java/com/twilio/rest/voice/v2/ClientCreator.java @@ -0,0 +1,84 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio API definition for public-api voice + * Powers Twilio public-api voice + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.voice.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +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; +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 ClientCreator extends Creator { + + private Client.VoiceV2ClientConfigurationRequest voiceV2ClientConfigurationRequest; + + public ClientCreator() {} + + public ClientCreator setVoiceV2ClientConfigurationRequest( + final Client.VoiceV2ClientConfigurationRequest voiceV2ClientConfigurationRequest + ) { + this.voiceV2ClientConfigurationRequest = + voiceV2ClientConfigurationRequest; + return this; + } + + @Override + public Client create(final TwilioRestClient client) { + String path = "/v2/Configurations/Client"; + + Request request = new Request( + HttpMethod.POST, + Domains.VOICE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Client 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Client.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (voiceV2ClientConfigurationRequest != null) { + request.setBody( + Client.toJson(voiceV2ClientConfigurationRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/voice/v2/ClientDeleter.java b/src/main/java/com/twilio/rest/voice/v2/ClientDeleter.java new file mode 100644 index 000000000..732d5a0c7 --- /dev/null +++ b/src/main/java/com/twilio/rest/voice/v2/ClientDeleter.java @@ -0,0 +1,73 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio API definition for public-api voice + * Powers Twilio public-api voice + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.voice.v2; + +import com.twilio.base.Deleter; +import com.twilio.constant.EnumConstants; +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 ClientDeleter extends Deleter { + + private String pathIdOrFriendlyName; + + public ClientDeleter(final String pathIdOrFriendlyName) { + this.pathIdOrFriendlyName = pathIdOrFriendlyName; + } + + @Override + public boolean delete(final TwilioRestClient client) { + String path = "/v2/Configurations/Client/{IdOrFriendlyName}"; + + path = + path.replace( + "{" + "IdOrFriendlyName" + "}", + this.pathIdOrFriendlyName.toString() + ); + + Request request = new Request( + HttpMethod.DELETE, + Domains.VOICE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Client delete 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response.getStatusCode() == 204; + } +} diff --git a/src/main/java/com/twilio/rest/voice/v2/Default.java b/src/main/java/com/twilio/rest/voice/v2/Default.java new file mode 100644 index 000000000..0248966f6 --- /dev/null +++ b/src/main/java/com/twilio/rest/voice/v2/Default.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio API definition for public-api voice + * Powers Twilio public-api voice + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.voice.v2; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Default extends Resource { + + private static final long serialVersionUID = 0L; + + @ToString + public static class DefaultClientConfigurationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("config_id") + @Getter + @Setter + private String configId; + + public DefaultClientConfigurationRequest() {} + + public static DefaultClientConfigurationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + DefaultClientConfigurationRequest.class + ); + } + } + + public static DefaultCreator creator() { + return new DefaultCreator(); + } + + /** + * Converts a JSON String into a Default object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Default object represented by the provided JSON + */ + public static Default fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Default.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 Default object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Default object represented by the provided JSON + */ + public static Default fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Default.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } +} diff --git a/src/main/java/com/twilio/rest/voice/v2/DefaultCreator.java b/src/main/java/com/twilio/rest/voice/v2/DefaultCreator.java new file mode 100644 index 000000000..53ca3b86b --- /dev/null +++ b/src/main/java/com/twilio/rest/voice/v2/DefaultCreator.java @@ -0,0 +1,84 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio API definition for public-api voice + * Powers Twilio public-api voice + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.voice.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +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; +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 DefaultCreator extends Creator { + + private Default.DefaultClientConfigurationRequest defaultClientConfigurationRequest; + + public DefaultCreator() {} + + public DefaultCreator setDefaultClientConfigurationRequest( + final Default.DefaultClientConfigurationRequest defaultClientConfigurationRequest + ) { + this.defaultClientConfigurationRequest = + defaultClientConfigurationRequest; + return this; + } + + @Override + public Default create(final TwilioRestClient client) { + String path = "/v2/Configurations/Client/Default"; + + Request request = new Request( + HttpMethod.POST, + Domains.VOICE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Default 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Default.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (defaultClientConfigurationRequest != null) { + request.setBody( + Default.toJson(defaultClientConfigurationRequest, objectMapper) + ); + } + } +} diff --git a/src/test/java/com/twilio/compliance/ComplianceTest.java b/src/test/java/com/twilio/compliance/ComplianceTest.java index 7b1372706..ec9b5d284 100644 --- a/src/test/java/com/twilio/compliance/ComplianceTest.java +++ b/src/test/java/com/twilio/compliance/ComplianceTest.java @@ -50,6 +50,7 @@ public void setUp() { variantClasses.add(com.twilio.rest.voice.v1.ArchivedCall.class); variantClasses.add(com.twilio.rest.numbers.v1.PortingPortInPhoneNumber.class); variantClasses.add(com.twilio.rest.numbers.v1.PortingWebhookConfigurationDelete.class); + variantClasses.add(com.twilio.rest.voice.v2.Default.class); } @Test @@ -113,4 +114,4 @@ private static ArchRule disallowPackage(final String packageIdentifier) { return noClasses() .should(dependOnClassesThat(resideInAPackage(packageIdentifier))); } -} \ No newline at end of file +}