From 1d1ce36673da388661b09df0c08b284be8d2248f Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 18 Sep 2024 13:19:05 +0000 Subject: [PATCH 1/5] [Librarian] Regenerated @ 1b6718f23da76f150eac392860c66a26de9af713 ceb130295f80bc623f22496076e3dd57e27da2fb --- CHANGES.md | 10 + src/main/java/com/twilio/Domains.java | 1 + .../twilio/rest/assistants/v1/Assistant.java | 566 ++++++++++++++++++ .../rest/assistants/v1/AssistantCreator.java | 101 ++++ .../rest/assistants/v1/AssistantDeleter.java | 69 +++ .../rest/assistants/v1/AssistantFetcher.java | 73 +++ .../rest/assistants/v1/AssistantReader.java | 135 +++++ .../rest/assistants/v1/AssistantUpdater.java | 95 +++ .../twilio/rest/assistants/v1/Knowledge.java | 392 ++++++++++++ .../rest/assistants/v1/KnowledgeCreator.java | 101 ++++ .../rest/assistants/v1/KnowledgeDeleter.java | 69 +++ .../rest/assistants/v1/KnowledgeFetcher.java | 73 +++ .../rest/assistants/v1/KnowledgeReader.java | 144 +++++ .../rest/assistants/v1/KnowledgeUpdater.java | 95 +++ .../com/twilio/rest/assistants/v1/Policy.java | 197 ++++++ .../rest/assistants/v1/PolicyReader.java | 153 +++++ .../twilio/rest/assistants/v1/Session.java | 181 ++++++ .../rest/assistants/v1/SessionFetcher.java | 70 +++ .../rest/assistants/v1/SessionReader.java | 135 +++++ .../com/twilio/rest/assistants/v1/Tool.java | 409 +++++++++++++ .../rest/assistants/v1/ToolCreator.java | 95 +++ .../rest/assistants/v1/ToolDeleter.java | 69 +++ .../twilio/rest/assistants/v1/ToolReader.java | 144 +++++ .../rest/assistants/v1/ToolUpdater.java | 89 +++ .../assistants/v1/assistant/Feedback.java | 274 +++++++++ .../v1/assistant/FeedbackCreator.java | 105 ++++ .../v1/assistant/FeedbackReader.java | 139 +++++ .../rest/assistants/v1/knowledge/Chunk.java | 161 +++++ .../assistants/v1/knowledge/ChunkReader.java | 139 +++++ .../rest/assistants/v1/session/Message.java | 206 +++++++ .../assistants/v1/session/MessageReader.java | 143 +++++ .../content/v1/content/ApprovalFetch.java | 4 +- .../v1/content/ApprovalFetchFetcher.java | 14 +- .../rest/intelligence/v2/OperatorType.java | 45 +- .../marketplace/v1/ModuleDataManagement.java | 17 +- .../v1/ModuleDataManagementUpdater.java | 9 + .../installedaddon/InstalledAddOnUsage.java | 76 +-- 37 files changed, 4713 insertions(+), 85 deletions(-) create mode 100644 src/main/java/com/twilio/rest/assistants/v1/Assistant.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/AssistantCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/AssistantDeleter.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/AssistantFetcher.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/AssistantReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/AssistantUpdater.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/Knowledge.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/KnowledgeCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/KnowledgeDeleter.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/KnowledgeFetcher.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/KnowledgeReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/KnowledgeUpdater.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/Policy.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/PolicyReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/Session.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/SessionFetcher.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/SessionReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/Tool.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/ToolCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/ToolDeleter.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/ToolReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/ToolUpdater.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/Feedback.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/knowledge/Chunk.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/knowledge/ChunkReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/session/Message.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/session/MessageReader.java diff --git a/CHANGES.md b/CHANGES.md index 6010252a3e..c71ed13e07 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,16 @@ twilio-java changelog ===================== +[2024-09-18] Version 10.5.1 +--------------------------- +**Intelligence** +- Remove public from operator_type +- Update operator_type to include general-availablity and deprecated + +**Numbers** +- Remove beta flag for bundle clone API + + [2024-09-05] Version 10.5.0 --------------------------- **Iam** diff --git a/src/main/java/com/twilio/Domains.java b/src/main/java/com/twilio/Domains.java index 1a805dc447..4cea2a4672 100644 --- a/src/main/java/com/twilio/Domains.java +++ b/src/main/java/com/twilio/Domains.java @@ -13,6 +13,7 @@ public enum Domains { ACCOUNTS("accounts"), API("api"), + ASSISTANTS("assistants"), BULKEXPORTS("bulkexports"), CHAT("chat"), CONTENT("content"), diff --git a/src/main/java/com/twilio/rest/assistants/v1/Assistant.java b/src/main/java/com/twilio/rest/assistants/v1/Assistant.java new file mode 100644 index 0000000000..fb4182bab7 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/Assistant.java @@ -0,0 +1,566 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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.converter.Converter; +import com.twilio.converter.DateConverter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Assistant extends Resource { + + private static final long serialVersionUID = 83480490674350L; + + @ToString + public static class AssistantsV1ServiceCustomerAi { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("perception_engine_enabled") + @Getter + @Setter + private Boolean perceptionEngineEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("personalization_engine_enabled") + @Getter + @Setter + private Boolean personalizationEngineEnabled; + + public static AssistantsV1ServiceCustomerAi fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceCustomerAi.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceSegmentCredential { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profile_api_key") + @Getter + @Setter + private String profileApiKey; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("space_id") + @Getter + @Setter + private String spaceId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("write_key") + @Getter + @Setter + private String writeKey; + + public static AssistantsV1ServiceSegmentCredential fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceSegmentCredential.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceCreateAssistantRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_ai") + @Getter + @Setter + private AssistantsV1ServiceCustomerAi customerAi; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("owner") + @Getter + @Setter + private String owner; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("personality_prompt") + @Getter + @Setter + private String personalityPrompt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("segment_credential") + @Getter + @Setter + private AssistantsV1ServiceSegmentCredential segmentCredential; + + public AssistantsV1ServiceCreateAssistantRequest() {} + + public static AssistantsV1ServiceCreateAssistantRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceCreateAssistantRequest.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceUpdateAssistantRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_ai") + @Getter + @Setter + private AssistantsV1ServiceCustomerAi customerAi; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("owner") + @Getter + @Setter + private String owner; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("personality_prompt") + @Getter + @Setter + private String personalityPrompt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("segment_credential") + @Getter + @Setter + private AssistantsV1ServiceSegmentCredential segmentCredential; + + public AssistantsV1ServiceUpdateAssistantRequest() {} + + public static AssistantsV1ServiceUpdateAssistantRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceUpdateAssistantRequest.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceKnowledge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + @Setter + private String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_sid") + @Getter + @Setter + private String accountSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge_source_details") + @Getter + @Setter + private Map knowledgeSourceDetails; + + public String getKnowledgeSourceDetails() { + return Converter.mapToJson(knowledgeSourceDetails); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + @Setter + private String status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_created") + @Getter + @Setter + private ZonedDateTime dateCreated; + + public String getDateCreated() { + return dateCreated.toInstant().toString(); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_updated") + @Getter + @Setter + private ZonedDateTime dateUpdated; + + public String getDateUpdated() { + return dateUpdated.toInstant().toString(); + } + + public static AssistantsV1ServiceKnowledge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceKnowledge.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceTool { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_sid") + @Getter + @Setter + private String accountSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + @Setter + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + @Setter + private String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("meta") + @Getter + @Setter + private Map meta; + + public String getMeta() { + return Converter.mapToJson(meta); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("requires_auth") + @Getter + @Setter + private Boolean requiresAuth; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_created") + @Getter + @Setter + private ZonedDateTime dateCreated; + + public String getDateCreated() { + return dateCreated.toInstant().toString(); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_updated") + @Getter + @Setter + private ZonedDateTime dateUpdated; + + public String getDateUpdated() { + return dateUpdated.toInstant().toString(); + } + + public static AssistantsV1ServiceTool fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, AssistantsV1ServiceTool.class); + } + } + + public static AssistantCreator creator( + final Assistant.AssistantsV1ServiceCreateAssistantRequest assistantsV1ServiceCreateAssistantRequest + ) { + return new AssistantCreator(assistantsV1ServiceCreateAssistantRequest); + } + + public static AssistantDeleter deleter(final String pathId) { + return new AssistantDeleter(pathId); + } + + public static AssistantFetcher fetcher(final String pathId) { + return new AssistantFetcher(pathId); + } + + public static AssistantReader reader() { + return new AssistantReader(); + } + + public static AssistantUpdater updater(final String pathId) { + return new AssistantUpdater(pathId); + } + + /** + * 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); + } 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 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); + } 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 accountSid; + private final Map customerAi; + private final String id; + private final String model; + private final String name; + private final String owner; + private final String personalityPrompt; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + private final List knowledge; + private final List tools; + + @JsonCreator + private Assistant( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("customer_ai") final Map customerAi, + @JsonProperty("id") final String id, + @JsonProperty("model") final String model, + @JsonProperty("name") final String name, + @JsonProperty("owner") final String owner, + @JsonProperty("personality_prompt") final String personalityPrompt, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("knowledge") final List< + AssistantsV1ServiceKnowledge + > knowledge, + @JsonProperty("tools") final List tools + ) { + this.accountSid = accountSid; + this.customerAi = customerAi; + this.id = id; + this.model = model; + this.name = name; + this.owner = owner; + this.personalityPrompt = personalityPrompt; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.knowledge = knowledge; + this.tools = tools; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getCustomerAi() { + return this.customerAi; + } + + public final String getId() { + return this.id; + } + + public final String getModel() { + return this.model; + } + + public final String getName() { + return this.name; + } + + public final String getOwner() { + return this.owner; + } + + public final String getPersonalityPrompt() { + return this.personalityPrompt; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + public final List getKnowledge() { + return this.knowledge; + } + + public final List getTools() { + return this.tools; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Assistant other = (Assistant) o; + + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(customerAi, other.customerAi) && + Objects.equals(id, other.id) && + Objects.equals(model, other.model) && + Objects.equals(name, other.name) && + Objects.equals(owner, other.owner) && + Objects.equals(personalityPrompt, other.personalityPrompt) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(knowledge, other.knowledge) && + Objects.equals(tools, other.tools) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + customerAi, + id, + model, + name, + owner, + personalityPrompt, + dateCreated, + dateUpdated, + knowledge, + tools + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/AssistantCreator.java b/src/main/java/com/twilio/rest/assistants/v1/AssistantCreator.java new file mode 100644 index 0000000000..255b68ce0a --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/AssistantCreator.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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 AssistantCreator extends Creator { + + private Assistant.AssistantsV1ServiceCreateAssistantRequest assistantsV1ServiceCreateAssistantRequest; + + public AssistantCreator( + final Assistant.AssistantsV1ServiceCreateAssistantRequest assistantsV1ServiceCreateAssistantRequest + ) { + this.assistantsV1ServiceCreateAssistantRequest = + assistantsV1ServiceCreateAssistantRequest; + } + + public AssistantCreator setAssistantsV1ServiceCreateAssistantRequest( + final Assistant.AssistantsV1ServiceCreateAssistantRequest assistantsV1ServiceCreateAssistantRequest + ) { + this.assistantsV1ServiceCreateAssistantRequest = + assistantsV1ServiceCreateAssistantRequest; + return this; + } + + @Override + public Assistant create(final TwilioRestClient client) { + String path = "/v1/Assistants"; + + path = + path.replace( + "{" + "AssistantsV1ServiceCreateAssistantRequest" + "}", + this.assistantsV1ServiceCreateAssistantRequest.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + 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() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceCreateAssistantRequest != null) { + request.setBody( + Assistant.toJson( + assistantsV1ServiceCreateAssistantRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/AssistantDeleter.java b/src/main/java/com/twilio/rest/assistants/v1/AssistantDeleter.java new file mode 100644 index 0000000000..fdac762673 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/AssistantDeleter.java @@ -0,0 +1,69 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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 AssistantDeleter extends Deleter { + + private String pathId; + + public AssistantDeleter(final String pathId) { + this.pathId = pathId; + } + + @Override + public boolean delete(final TwilioRestClient client) { + String path = "/v1/Assistants/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.DELETE, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + 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() + ); + 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/assistants/v1/AssistantFetcher.java b/src/main/java/com/twilio/rest/assistants/v1/AssistantFetcher.java new file mode 100644 index 0000000000..f05d4ed235 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/AssistantFetcher.java @@ -0,0 +1,73 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Fetcher; +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 AssistantFetcher extends Fetcher { + + private String pathId; + + public AssistantFetcher(final String pathId) { + this.pathId = pathId; + } + + @Override + public Assistant fetch(final TwilioRestClient client) { + String path = "/v1/Assistants/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + 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() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/AssistantReader.java b/src/main/java/com/twilio/rest/assistants/v1/AssistantReader.java new file mode 100644 index 0000000000..3ab3635317 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/AssistantReader.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 AssistantReader extends Reader { + + private Integer pageSize; + + public AssistantReader() {} + + public AssistantReader 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/Assistants"; + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, 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" + ); + } 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 Page.fromJson( + "assistants", + response.getContent(), + Assistant.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (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/assistants/v1/AssistantUpdater.java b/src/main/java/com/twilio/rest/assistants/v1/AssistantUpdater.java new file mode 100644 index 0000000000..dd27f7c127 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/AssistantUpdater.java @@ -0,0 +1,95 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +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; +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 AssistantUpdater extends Updater { + + private String pathId; + private Assistant.AssistantsV1ServiceUpdateAssistantRequest assistantsV1ServiceUpdateAssistantRequest; + + public AssistantUpdater(final String pathId) { + this.pathId = pathId; + } + + public AssistantUpdater setAssistantsV1ServiceUpdateAssistantRequest( + final Assistant.AssistantsV1ServiceUpdateAssistantRequest assistantsV1ServiceUpdateAssistantRequest + ) { + this.assistantsV1ServiceUpdateAssistantRequest = + assistantsV1ServiceUpdateAssistantRequest; + return this; + } + + @Override + public Assistant update(final TwilioRestClient client) { + String path = "/v1/Assistants/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + 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() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Assistant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceUpdateAssistantRequest != null) { + request.setBody( + Assistant.toJson( + assistantsV1ServiceUpdateAssistantRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/Knowledge.java b/src/main/java/com/twilio/rest/assistants/v1/Knowledge.java new file mode 100644 index 0000000000..ed482235c5 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/Knowledge.java @@ -0,0 +1,392 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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.converter.Converter; +import com.twilio.converter.DateConverter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Knowledge extends Resource { + + private static final long serialVersionUID = 228486068645709L; + + @ToString + public static class AssistantsV1ServiceCreatePolicyRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + @Setter + private String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy_details") + @Getter + @Setter + private Map policyDetails; + + public String getPolicyDetails() { + return Converter.mapToJson(policyDetails); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + public static AssistantsV1ServiceCreatePolicyRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceCreatePolicyRequest.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceCreateKnowledgeRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("assistant_id") + @Getter + @Setter + private String assistantId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge_source_details") + @Getter + @Setter + private Map knowledgeSourceDetails; + + public String getKnowledgeSourceDetails() { + return Converter.mapToJson(knowledgeSourceDetails); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + @Setter + private AssistantsV1ServiceCreatePolicyRequest policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + public AssistantsV1ServiceCreateKnowledgeRequest() {} + + public static AssistantsV1ServiceCreateKnowledgeRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceCreateKnowledgeRequest.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceUpdateKnowledgeRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge_source_details") + @Getter + @Setter + private Map knowledgeSourceDetails; + + public String getKnowledgeSourceDetails() { + return Converter.mapToJson(knowledgeSourceDetails); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + @Setter + private AssistantsV1ServiceCreatePolicyRequest policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + public AssistantsV1ServiceUpdateKnowledgeRequest() {} + + public static AssistantsV1ServiceUpdateKnowledgeRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceUpdateKnowledgeRequest.class + ); + } + } + + public static KnowledgeCreator creator( + final Knowledge.AssistantsV1ServiceCreateKnowledgeRequest assistantsV1ServiceCreateKnowledgeRequest + ) { + return new KnowledgeCreator(assistantsV1ServiceCreateKnowledgeRequest); + } + + public static KnowledgeDeleter deleter(final String pathId) { + return new KnowledgeDeleter(pathId); + } + + public static KnowledgeFetcher fetcher(final String pathId) { + return new KnowledgeFetcher(pathId); + } + + public static KnowledgeReader reader() { + return new KnowledgeReader(); + } + + public static KnowledgeUpdater updater(final String pathId) { + return new KnowledgeUpdater(pathId); + } + + /** + * Converts a JSON String into a Knowledge object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Knowledge object represented by the provided JSON + */ + public static Knowledge fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Knowledge.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 Knowledge object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Knowledge object represented by the provided JSON + */ + public static Knowledge fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Knowledge.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 description; + private final String id; + private final String accountSid; + private final Map knowledgeSourceDetails; + private final String name; + private final String status; + private final String type; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private Knowledge( + @JsonProperty("description") final String description, + @JsonProperty("id") final String id, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("knowledge_source_details") final Map< + String, + Object + > knowledgeSourceDetails, + @JsonProperty("name") final String name, + @JsonProperty("status") final String status, + @JsonProperty("type") final String type, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.description = description; + this.id = id; + this.accountSid = accountSid; + this.knowledgeSourceDetails = knowledgeSourceDetails; + this.name = name; + this.status = status; + this.type = type; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getDescription() { + return this.description; + } + + public final String getId() { + return this.id; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getKnowledgeSourceDetails() { + return this.knowledgeSourceDetails; + } + + public final String getName() { + return this.name; + } + + public final String getStatus() { + return this.status; + } + + public final String getType() { + return this.type; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Knowledge other = (Knowledge) o; + + return ( + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + knowledgeSourceDetails, + other.knowledgeSourceDetails + ) && + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + description, + id, + accountSid, + knowledgeSourceDetails, + name, + status, + type, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/KnowledgeCreator.java b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeCreator.java new file mode 100644 index 0000000000..73da89e2fa --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeCreator.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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 KnowledgeCreator extends Creator { + + private Knowledge.AssistantsV1ServiceCreateKnowledgeRequest assistantsV1ServiceCreateKnowledgeRequest; + + public KnowledgeCreator( + final Knowledge.AssistantsV1ServiceCreateKnowledgeRequest assistantsV1ServiceCreateKnowledgeRequest + ) { + this.assistantsV1ServiceCreateKnowledgeRequest = + assistantsV1ServiceCreateKnowledgeRequest; + } + + public KnowledgeCreator setAssistantsV1ServiceCreateKnowledgeRequest( + final Knowledge.AssistantsV1ServiceCreateKnowledgeRequest assistantsV1ServiceCreateKnowledgeRequest + ) { + this.assistantsV1ServiceCreateKnowledgeRequest = + assistantsV1ServiceCreateKnowledgeRequest; + return this; + } + + @Override + public Knowledge create(final TwilioRestClient client) { + String path = "/v1/Knowledge"; + + path = + path.replace( + "{" + "AssistantsV1ServiceCreateKnowledgeRequest" + "}", + this.assistantsV1ServiceCreateKnowledgeRequest.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Knowledge 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 Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceCreateKnowledgeRequest != null) { + request.setBody( + Knowledge.toJson( + assistantsV1ServiceCreateKnowledgeRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/KnowledgeDeleter.java b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeDeleter.java new file mode 100644 index 0000000000..99a0057c51 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeDeleter.java @@ -0,0 +1,69 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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 KnowledgeDeleter extends Deleter { + + private String pathId; + + public KnowledgeDeleter(final String pathId) { + this.pathId = pathId; + } + + @Override + public boolean delete(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.DELETE, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge 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/assistants/v1/KnowledgeFetcher.java b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeFetcher.java new file mode 100644 index 0000000000..16a9d19745 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeFetcher.java @@ -0,0 +1,73 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Fetcher; +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 KnowledgeFetcher extends Fetcher { + + private String pathId; + + public KnowledgeFetcher(final String pathId) { + this.pathId = pathId; + } + + @Override + public Knowledge fetch(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/KnowledgeReader.java b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeReader.java new file mode 100644 index 0000000000..aa784ccf77 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeReader.java @@ -0,0 +1,144 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 KnowledgeReader extends Reader { + + private String assistantId; + private Integer pageSize; + + public KnowledgeReader() {} + + public KnowledgeReader setAssistantId(final String assistantId) { + this.assistantId = assistantId; + return this; + } + + public KnowledgeReader 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/Knowledge"; + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "knowledge", + response.getContent(), + Knowledge.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (assistantId != null) { + request.addQueryParam("AssistantId", assistantId); + } + 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/assistants/v1/KnowledgeUpdater.java b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeUpdater.java new file mode 100644 index 0000000000..773dbf4099 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/KnowledgeUpdater.java @@ -0,0 +1,95 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +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; +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 KnowledgeUpdater extends Updater { + + private String pathId; + private Knowledge.AssistantsV1ServiceUpdateKnowledgeRequest assistantsV1ServiceUpdateKnowledgeRequest; + + public KnowledgeUpdater(final String pathId) { + this.pathId = pathId; + } + + public KnowledgeUpdater setAssistantsV1ServiceUpdateKnowledgeRequest( + final Knowledge.AssistantsV1ServiceUpdateKnowledgeRequest assistantsV1ServiceUpdateKnowledgeRequest + ) { + this.assistantsV1ServiceUpdateKnowledgeRequest = + assistantsV1ServiceUpdateKnowledgeRequest; + return this; + } + + @Override + public Knowledge update(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Knowledge 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceUpdateKnowledgeRequest != null) { + request.setBody( + Knowledge.toJson( + assistantsV1ServiceUpdateKnowledgeRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/Policy.java b/src/main/java/com/twilio/rest/assistants/v1/Policy.java new file mode 100644 index 0000000000..aad952fdda --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/Policy.java @@ -0,0 +1,197 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Policy extends Resource { + + private static final long serialVersionUID = 15658572271109L; + + public static PolicyReader reader() { + return new PolicyReader(); + } + + /** + * Converts a JSON String into a Policy object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Policy object represented by the provided JSON + */ + public static Policy fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Policy.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 Policy object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Policy object represented by the provided JSON + */ + public static Policy fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Policy.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final String id; + private final String name; + private final String description; + private final String accountSid; + private final String userSid; + private final String type; + private final Map policyDetails; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private Policy( + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("description") final String description, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("type") final String type, + @JsonProperty("policy_details") final Map policyDetails, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.id = id; + this.name = name; + this.description = description; + this.accountSid = accountSid; + this.userSid = userSid; + this.type = type; + this.policyDetails = policyDetails; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getId() { + return this.id; + } + + public final String getName() { + return this.name; + } + + public final String getDescription() { + return this.description; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getType() { + return this.type; + } + + public final Map getPolicyDetails() { + return this.policyDetails; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Policy other = (Policy) o; + + return ( + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(userSid, other.userSid) && + Objects.equals(type, other.type) && + Objects.equals(policyDetails, other.policyDetails) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + name, + description, + accountSid, + userSid, + type, + policyDetails, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/PolicyReader.java b/src/main/java/com/twilio/rest/assistants/v1/PolicyReader.java new file mode 100644 index 0000000000..c216cafe42 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/PolicyReader.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 PolicyReader extends Reader { + + private String toolId; + private String knowledgeId; + private Integer pageSize; + + public PolicyReader() {} + + public PolicyReader setToolId(final String toolId) { + this.toolId = toolId; + return this; + } + + public PolicyReader setKnowledgeId(final String knowledgeId) { + this.knowledgeId = knowledgeId; + return this; + } + + public PolicyReader 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/Policies"; + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Policy 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "policies", + response.getContent(), + Policy.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (toolId != null) { + request.addQueryParam("ToolId", toolId); + } + if (knowledgeId != null) { + request.addQueryParam("KnowledgeId", knowledgeId); + } + 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/assistants/v1/Session.java b/src/main/java/com/twilio/rest/assistants/v1/Session.java new file mode 100644 index 0000000000..c42f56ba6e --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/Session.java @@ -0,0 +1,181 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +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 Session extends Resource { + + private static final long serialVersionUID = 32443356464816L; + + public static SessionFetcher fetcher(final String pathId) { + return new SessionFetcher(pathId); + } + + public static SessionReader reader() { + return new SessionReader(); + } + + /** + * 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); + } 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 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); + } catch (final JsonMappingException | JsonParseException 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 assistantId; + private final Boolean verified; + private final String identity; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private Session( + @JsonProperty("id") final String id, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_id") final String assistantId, + @JsonProperty("verified") final Boolean verified, + @JsonProperty("identity") final String identity, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.id = id; + this.accountSid = accountSid; + this.assistantId = assistantId; + this.verified = verified; + this.identity = identity; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getId() { + return this.id; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantId() { + return this.assistantId; + } + + public final Boolean getVerified() { + return this.verified; + } + + public final String getIdentity() { + return this.identity; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Session other = (Session) o; + + return ( + Objects.equals(id, other.id) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantId, other.assistantId) && + Objects.equals(verified, other.verified) && + Objects.equals(identity, other.identity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + accountSid, + assistantId, + verified, + identity, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/SessionFetcher.java b/src/main/java/com/twilio/rest/assistants/v1/SessionFetcher.java new file mode 100644 index 0000000000..92eaa1f146 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/SessionFetcher.java @@ -0,0 +1,70 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Fetcher; +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 SessionFetcher extends Fetcher { + + private String pathId; + + public SessionFetcher(final String pathId) { + this.pathId = pathId; + } + + @Override + public Session fetch(final TwilioRestClient client) { + String path = "/v1/Sessions/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + 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() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Session.fromJson(response.getStream(), client.getObjectMapper()); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/SessionReader.java b/src/main/java/com/twilio/rest/assistants/v1/SessionReader.java new file mode 100644 index 0000000000..05a8c72660 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/SessionReader.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 SessionReader extends Reader { + + private Integer pageSize; + + public SessionReader() {} + + public SessionReader 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/Sessions"; + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, 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" + ); + } 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 Page.fromJson( + "sessions", + response.getContent(), + Session.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (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/assistants/v1/Tool.java b/src/main/java/com/twilio/rest/assistants/v1/Tool.java new file mode 100644 index 0000000000..6347579d67 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/Tool.java @@ -0,0 +1,409 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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.converter.Converter; +import com.twilio.converter.DateConverter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Tool extends Resource { + + private static final long serialVersionUID = 250744757874592L; + + @ToString + public static class AssistantsV1ServiceCreatePolicyRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + @Setter + private String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy_details") + @Getter + @Setter + private Map policyDetails; + + public String getPolicyDetails() { + return Converter.mapToJson(policyDetails); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + public static AssistantsV1ServiceCreatePolicyRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceCreatePolicyRequest.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceCreateToolRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("assistant_id") + @Getter + @Setter + private String assistantId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + @Setter + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("meta") + @Getter + @Setter + private Map meta; + + public String getMeta() { + return Converter.mapToJson(meta); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + @Setter + private AssistantsV1ServiceCreatePolicyRequest policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + public AssistantsV1ServiceCreateToolRequest() {} + + public static AssistantsV1ServiceCreateToolRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceCreateToolRequest.class + ); + } + } + + @ToString + public static class AssistantsV1ServiceUpdateToolRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("assistant_id") + @Getter + @Setter + private String assistantId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + @Setter + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("meta") + @Getter + @Setter + private Map meta; + + public String getMeta() { + return Converter.mapToJson(meta); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + @Setter + private AssistantsV1ServiceCreatePolicyRequest policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + public AssistantsV1ServiceUpdateToolRequest() {} + + public static AssistantsV1ServiceUpdateToolRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceUpdateToolRequest.class + ); + } + } + + public static ToolCreator creator( + final Tool.AssistantsV1ServiceCreateToolRequest assistantsV1ServiceCreateToolRequest + ) { + return new ToolCreator(assistantsV1ServiceCreateToolRequest); + } + + public static ToolDeleter deleter(final String pathId) { + return new ToolDeleter(pathId); + } + + public static ToolReader reader() { + return new ToolReader(); + } + + public static ToolUpdater updater(final String pathId) { + return new ToolUpdater(pathId); + } + + /** + * Converts a JSON String into a Tool object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Tool object represented by the provided JSON + */ + public static Tool fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Tool.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 Tool object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Tool object represented by the provided JSON + */ + public static Tool fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Tool.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 accountSid; + private final String description; + private final Boolean enabled; + private final String id; + private final Map meta; + private final String name; + private final Boolean requiresAuth; + private final String type; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private Tool( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("description") final String description, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("id") final String id, + @JsonProperty("meta") final Map meta, + @JsonProperty("name") final String name, + @JsonProperty("requires_auth") final Boolean requiresAuth, + @JsonProperty("type") final String type, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.accountSid = accountSid; + this.description = description; + this.enabled = enabled; + this.id = id; + this.meta = meta; + this.name = name; + this.requiresAuth = requiresAuth; + this.type = type; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDescription() { + return this.description; + } + + public final Boolean getEnabled() { + return this.enabled; + } + + public final String getId() { + return this.id; + } + + public final Map getMeta() { + return this.meta; + } + + public final String getName() { + return this.name; + } + + public final Boolean getRequiresAuth() { + return this.requiresAuth; + } + + public final String getType() { + return this.type; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Tool other = (Tool) o; + + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(description, other.description) && + Objects.equals(enabled, other.enabled) && + Objects.equals(id, other.id) && + Objects.equals(meta, other.meta) && + Objects.equals(name, other.name) && + Objects.equals(requiresAuth, other.requiresAuth) && + Objects.equals(type, other.type) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + description, + enabled, + id, + meta, + name, + requiresAuth, + type, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/ToolCreator.java b/src/main/java/com/twilio/rest/assistants/v1/ToolCreator.java new file mode 100644 index 0000000000..0b841a7264 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/ToolCreator.java @@ -0,0 +1,95 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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 ToolCreator extends Creator { + + private Tool.AssistantsV1ServiceCreateToolRequest assistantsV1ServiceCreateToolRequest; + + public ToolCreator( + final Tool.AssistantsV1ServiceCreateToolRequest assistantsV1ServiceCreateToolRequest + ) { + this.assistantsV1ServiceCreateToolRequest = + assistantsV1ServiceCreateToolRequest; + } + + public ToolCreator setAssistantsV1ServiceCreateToolRequest( + final Tool.AssistantsV1ServiceCreateToolRequest assistantsV1ServiceCreateToolRequest + ) { + this.assistantsV1ServiceCreateToolRequest = + assistantsV1ServiceCreateToolRequest; + return this; + } + + @Override + public Tool create(final TwilioRestClient client) { + String path = "/v1/Tools"; + + path = + path.replace( + "{" + "AssistantsV1ServiceCreateToolRequest" + "}", + this.assistantsV1ServiceCreateToolRequest.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Tool 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 Tool.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceCreateToolRequest != null) { + request.setBody( + Tool.toJson(assistantsV1ServiceCreateToolRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/ToolDeleter.java b/src/main/java/com/twilio/rest/assistants/v1/ToolDeleter.java new file mode 100644 index 0000000000..7ef83721f7 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/ToolDeleter.java @@ -0,0 +1,69 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +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 ToolDeleter extends Deleter { + + private String pathId; + + public ToolDeleter(final String pathId) { + this.pathId = pathId; + } + + @Override + public boolean delete(final TwilioRestClient client) { + String path = "/v1/Tools/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.DELETE, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Tool 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/assistants/v1/ToolReader.java b/src/main/java/com/twilio/rest/assistants/v1/ToolReader.java new file mode 100644 index 0000000000..7b8e49a7d8 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/ToolReader.java @@ -0,0 +1,144 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 ToolReader extends Reader { + + private String assistantId; + private Integer pageSize; + + public ToolReader() {} + + public ToolReader setAssistantId(final String assistantId) { + this.assistantId = assistantId; + return this; + } + + public ToolReader 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/Tools"; + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Tool 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "tools", + response.getContent(), + Tool.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (assistantId != null) { + request.addQueryParam("AssistantId", assistantId); + } + 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/assistants/v1/ToolUpdater.java b/src/main/java/com/twilio/rest/assistants/v1/ToolUpdater.java new file mode 100644 index 0000000000..eb5293917b --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/ToolUpdater.java @@ -0,0 +1,89 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +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; +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 ToolUpdater extends Updater { + + private String pathId; + private Tool.AssistantsV1ServiceUpdateToolRequest assistantsV1ServiceUpdateToolRequest; + + public ToolUpdater(final String pathId) { + this.pathId = pathId; + } + + public ToolUpdater setAssistantsV1ServiceUpdateToolRequest( + final Tool.AssistantsV1ServiceUpdateToolRequest assistantsV1ServiceUpdateToolRequest + ) { + this.assistantsV1ServiceUpdateToolRequest = + assistantsV1ServiceUpdateToolRequest; + return this; + } + + @Override + public Tool update(final TwilioRestClient client) { + String path = "/v1/Tools/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Tool 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Tool.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceUpdateToolRequest != null) { + request.setBody( + Tool.toJson(assistantsV1ServiceUpdateToolRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/Feedback.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/Feedback.java new file mode 100644 index 0000000000..c607c9c472 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/Feedback.java @@ -0,0 +1,274 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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.converter.DateConverter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Feedback extends Resource { + + private static final long serialVersionUID = 81835402394387L; + + @ToString + public static class AssistantsV1ServiceCreateFeedbackRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("message_id") + @Getter + @Setter + private String messageId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("score") + @Getter + @Setter + private Float score; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + @Getter + @Setter + private String sessionId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + @Setter + private String text; + + public AssistantsV1ServiceCreateFeedbackRequest( + final String sessionId + ) { + this.sessionId = sessionId; + } + + public static AssistantsV1ServiceCreateFeedbackRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceCreateFeedbackRequest.class + ); + } + } + + public static FeedbackCreator creator( + final String pathId, + final Feedback.AssistantsV1ServiceCreateFeedbackRequest assistantsV1ServiceCreateFeedbackRequest + ) { + return new FeedbackCreator( + pathId, + assistantsV1ServiceCreateFeedbackRequest + ); + } + + public static FeedbackReader reader(final String pathId) { + return new FeedbackReader(pathId); + } + + /** + * 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); + } 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 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); + } 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 assistantId; + private final String id; + private final String accountSid; + private final String userSid; + private final String messageId; + private final Float score; + private final String sessionId; + private final String text; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private Feedback( + @JsonProperty("assistant_id") final String assistantId, + @JsonProperty("id") final String id, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("message_id") final String messageId, + @JsonProperty("score") final Float score, + @JsonProperty("session_id") final String sessionId, + @JsonProperty("text") final String text, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.assistantId = assistantId; + this.id = id; + this.accountSid = accountSid; + this.userSid = userSid; + this.messageId = messageId; + this.score = score; + this.sessionId = sessionId; + this.text = text; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getAssistantId() { + return this.assistantId; + } + + public final String getId() { + return this.id; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getUserSid() { + return this.userSid; + } + + public final String getMessageId() { + return this.messageId; + } + + public final Float getScore() { + return this.score; + } + + public final String getSessionId() { + return this.sessionId; + } + + public final String getText() { + return this.text; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Feedback other = (Feedback) o; + + return ( + Objects.equals(assistantId, other.assistantId) && + Objects.equals(id, other.id) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(userSid, other.userSid) && + Objects.equals(messageId, other.messageId) && + Objects.equals(score, other.score) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(text, other.text) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + assistantId, + id, + accountSid, + userSid, + messageId, + score, + sessionId, + text, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackCreator.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackCreator.java new file mode 100644 index 0000000000..86a729120d --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackCreator.java @@ -0,0 +1,105 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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 FeedbackCreator extends Creator { + + private String pathId; + private Feedback.AssistantsV1ServiceCreateFeedbackRequest assistantsV1ServiceCreateFeedbackRequest; + + public FeedbackCreator( + final String pathId, + final Feedback.AssistantsV1ServiceCreateFeedbackRequest assistantsV1ServiceCreateFeedbackRequest + ) { + this.pathId = pathId; + this.assistantsV1ServiceCreateFeedbackRequest = + assistantsV1ServiceCreateFeedbackRequest; + } + + public FeedbackCreator setAssistantsV1ServiceCreateFeedbackRequest( + final Feedback.AssistantsV1ServiceCreateFeedbackRequest assistantsV1ServiceCreateFeedbackRequest + ) { + this.assistantsV1ServiceCreateFeedbackRequest = + assistantsV1ServiceCreateFeedbackRequest; + return this; + } + + @Override + public Feedback create(final TwilioRestClient client) { + String path = "/v1/Assistants/{id}/Feedbacks"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + path = + path.replace( + "{" + "AssistantsV1ServiceCreateFeedbackRequest" + "}", + this.assistantsV1ServiceCreateFeedbackRequest.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + 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() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Feedback.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceCreateFeedbackRequest != null) { + request.setBody( + Feedback.toJson( + assistantsV1ServiceCreateFeedbackRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackReader.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackReader.java new file mode 100644 index 0000000000..4dee076a8b --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/FeedbackReader.java @@ -0,0 +1,139 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 FeedbackReader extends Reader { + + private String pathId; + private Integer pageSize; + + public FeedbackReader(final String pathId) { + this.pathId = pathId; + } + + public FeedbackReader 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/Assistants/{id}/Feedbacks"; + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Feedback 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "feedbacks", + response.getContent(), + Feedback.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (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/assistants/v1/knowledge/Chunk.java b/src/main/java/com/twilio/rest/assistants/v1/knowledge/Chunk.java new file mode 100644 index 0000000000..85668dd2c2 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/knowledge/Chunk.java @@ -0,0 +1,161 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.knowledge; + +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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Chunk extends Resource { + + private static final long serialVersionUID = 152804488582909L; + + public static ChunkReader reader(final String pathId) { + return new ChunkReader(pathId); + } + + /** + * Converts a JSON String into a Chunk object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Chunk object represented by the provided JSON + */ + public static Chunk fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Chunk.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 Chunk object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Chunk object represented by the provided JSON + */ + public static Chunk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Chunk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final String accountSid; + private final String content; + private final Map metadata; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private Chunk( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("content") final String content, + @JsonProperty("metadata") final Map metadata, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.accountSid = accountSid; + this.content = content; + this.metadata = metadata; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getContent() { + return this.content; + } + + public final Map getMetadata() { + return this.metadata; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Chunk other = (Chunk) o; + + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(content, other.content) && + Objects.equals(metadata, other.metadata) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + content, + metadata, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/knowledge/ChunkReader.java b/src/main/java/com/twilio/rest/assistants/v1/knowledge/ChunkReader.java new file mode 100644 index 0000000000..ed0d3a7b2d --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/knowledge/ChunkReader.java @@ -0,0 +1,139 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.knowledge; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 ChunkReader extends Reader { + + private String pathId; + private Integer pageSize; + + public ChunkReader(final String pathId) { + this.pathId = pathId; + } + + public ChunkReader 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/Knowledge/{id}/Chunks"; + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Chunk 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "chunks", + response.getContent(), + Chunk.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (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/assistants/v1/session/Message.java b/src/main/java/com/twilio/rest/assistants/v1/session/Message.java new file mode 100644 index 0000000000..8f5ade962d --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/session/Message.java @@ -0,0 +1,206 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.session; + +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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +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 = 88120971522058L; + + public static MessageReader reader(final String pathSessionId) { + return new MessageReader(pathSessionId); + } + + /** + * 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); + } 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 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); + } catch (final JsonMappingException | JsonParseException 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 assistantId; + private final String sessionId; + private final String identity; + private final String role; + private final Map content; + private final Map meta; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private Message( + @JsonProperty("id") final String id, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assistant_id") final String assistantId, + @JsonProperty("session_id") final String sessionId, + @JsonProperty("identity") final String identity, + @JsonProperty("role") final String role, + @JsonProperty("content") final Map content, + @JsonProperty("meta") final Map meta, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.id = id; + this.accountSid = accountSid; + this.assistantId = assistantId; + this.sessionId = sessionId; + this.identity = identity; + this.role = role; + this.content = content; + this.meta = meta; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getId() { + return this.id; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getAssistantId() { + return this.assistantId; + } + + public final String getSessionId() { + return this.sessionId; + } + + public final String getIdentity() { + return this.identity; + } + + public final String getRole() { + return this.role; + } + + public final Map getContent() { + return this.content; + } + + public final Map getMeta() { + return this.meta; + } + + public final ZonedDateTime getDateCreated() { + return this.dateCreated; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Message other = (Message) o; + + return ( + Objects.equals(id, other.id) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assistantId, other.assistantId) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(identity, other.identity) && + Objects.equals(role, other.role) && + Objects.equals(content, other.content) && + Objects.equals(meta, other.meta) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + accountSid, + assistantId, + sessionId, + identity, + role, + content, + meta, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/session/MessageReader.java b/src/main/java/com/twilio/rest/assistants/v1/session/MessageReader.java new file mode 100644 index 0000000000..a4efe9d8ac --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/session/MessageReader.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.session; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 MessageReader extends Reader { + + private String pathSessionId; + private Integer pageSize; + + public MessageReader(final String pathSessionId) { + this.pathSessionId = pathSessionId; + } + + public MessageReader 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/Sessions/{sessionId}/Messages"; + path = + path.replace( + "{" + "sessionId" + "}", + this.pathSessionId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, 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" + ); + } 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 Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (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/content/v1/content/ApprovalFetch.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java index 983eb5308d..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 @@ -38,8 +38,8 @@ public class ApprovalFetch extends Resource { private static final long serialVersionUID = 266557741388539L; - public static ApprovalFetchFetcher fetcher(final String pathContentSid) { - return new ApprovalFetchFetcher(pathContentSid); + public static ApprovalFetchFetcher fetcher(final String pathSid) { + return new ApprovalFetchFetcher(pathSid); } /** 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 317508063a..656e2d6ee1 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 @@ -27,21 +27,17 @@ public class ApprovalFetchFetcher extends Fetcher { - private String pathContentSid; + private String pathSid; - public ApprovalFetchFetcher(final String pathContentSid) { - this.pathContentSid = pathContentSid; + public ApprovalFetchFetcher(final String pathSid) { + this.pathSid = pathSid; } @Override public ApprovalFetch fetch(final TwilioRestClient client) { - String path = "/v1/Content/{ContentSid}/ApprovalRequests"; + String path = "/v1/Content/{Sid}/ApprovalRequests"; - path = - path.replace( - "{" + "ContentSid" + "}", - this.pathContentSid.toString() - ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); Request request = new Request( HttpMethod.GET, diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorType.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorType.java index 1adf6058e1..2142f4f135 100644 --- a/src/main/java/com/twilio/rest/intelligence/v2/OperatorType.java +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorType.java @@ -251,28 +251,6 @@ public int hashCode() { ); } - public enum Availability { - INTERNAL("internal"), - BETA("beta"), - PUBLIC("public"), - RETIRED("retired"); - - private final String value; - - private Availability(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static Availability forValue(final String value) { - return Promoter.enumFromString(value, Availability.values()); - } - } - public enum Provider { TWILIO("twilio"), AMAZON("amazon"), @@ -315,4 +293,27 @@ public static OutputType forValue(final String value) { return Promoter.enumFromString(value, OutputType.values()); } } + + public enum Availability { + INTERNAL("internal"), + BETA("beta"), + GENERAL_AVAILABILITY("general-availability"), + RETIRED("retired"), + DEPRECATED("deprecated"); + + private final String value; + + private Availability(final String value) { + this.value = value; + } + + public String toString() { + return value; + } + + @JsonCreator + public static Availability forValue(final String value) { + return Promoter.enumFromString(value, Availability.values()); + } + } } diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagement.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagement.java index a23d2a6d47..4030edb955 100644 --- a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagement.java +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagement.java @@ -36,7 +36,7 @@ @ToString public class ModuleDataManagement extends Resource { - private static final long serialVersionUID = 187208983422591L; + private static final long serialVersionUID = 28686366019019L; public static ModuleDataManagementFetcher fetcher(final String pathSid) { return new ModuleDataManagementFetcher(pathSid); @@ -97,6 +97,7 @@ public static ModuleDataManagement fromJson( private final Map moduleInfo; private final Map documentation; private final Map configuration; + private final Map pricing; @JsonCreator private ModuleDataManagement( @@ -107,7 +108,8 @@ private ModuleDataManagement( @JsonProperty("policies") final Map policies, @JsonProperty("module_info") final Map moduleInfo, @JsonProperty("documentation") final Map documentation, - @JsonProperty("configuration") final Map configuration + @JsonProperty("configuration") final Map configuration, + @JsonProperty("pricing") final Map pricing ) { this.url = url; this.sid = sid; @@ -117,6 +119,7 @@ private ModuleDataManagement( this.moduleInfo = moduleInfo; this.documentation = documentation; this.configuration = configuration; + this.pricing = pricing; } public final URI getUrl() { @@ -151,6 +154,10 @@ public final Map getConfiguration() { return this.configuration; } + public final Map getPricing() { + return this.pricing; + } + @Override public boolean equals(final Object o) { if (this == o) { @@ -171,7 +178,8 @@ public boolean equals(final Object o) { Objects.equals(policies, other.policies) && Objects.equals(moduleInfo, other.moduleInfo) && Objects.equals(documentation, other.documentation) && - Objects.equals(configuration, other.configuration) + Objects.equals(configuration, other.configuration) && + Objects.equals(pricing, other.pricing) ); } @@ -185,7 +193,8 @@ public int hashCode() { policies, moduleInfo, documentation, - configuration + configuration, + pricing ); } } diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementUpdater.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementUpdater.java index 3236bc2ec8..98a678bc01 100644 --- a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementUpdater.java +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementUpdater.java @@ -34,6 +34,7 @@ public class ModuleDataManagementUpdater extends Updater { private String policies; private String support; private String configuration; + private String pricing; public ModuleDataManagementUpdater(final String pathSid) { this.pathSid = pathSid; @@ -75,6 +76,11 @@ public ModuleDataManagementUpdater setConfiguration( return this; } + public ModuleDataManagementUpdater setPricing(final String pricing) { + this.pricing = pricing; + return this; + } + @Override public ModuleDataManagement update(final TwilioRestClient client) { String path = "/v1/Listing/{Sid}"; @@ -132,5 +138,8 @@ private void addPostParams(final Request request) { if (configuration != null) { request.addPostParam("Configuration", configuration); } + if (pricing != null) { + request.addPostParam("Pricing", pricing); + } } } diff --git a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsage.java b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsage.java index ceb98d272e..26949939ae 100644 --- a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsage.java +++ b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsage.java @@ -39,7 +39,7 @@ @ToString public class InstalledAddOnUsage extends Resource { - private static final long serialVersionUID = 244026319744874L; + private static final long serialVersionUID = 201246203121312L; @ToString public static class MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems { @@ -56,6 +56,12 @@ public static class MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems @Setter private String sid; + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("submitted") + @Getter + @Setter + private Boolean submitted; + public static MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems fromJson( String jsonString, ObjectMapper mapper @@ -71,7 +77,13 @@ public static MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems fromJs public static class MarketplaceV1InstalledAddOnInstalledAddOnUsage { @JsonInclude(JsonInclude.Include.NON_EMPTY) - @JsonProperty("billable_items") + @JsonProperty("totalSubmitted") + @Getter + @Setter + private BigDecimal totalSubmitted; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("billableItems") @Getter @Setter private List< @@ -97,38 +109,6 @@ public static MarketplaceV1InstalledAddOnInstalledAddOnUsage fromJson( } } - @ToString - public static class MarketplaceV1InstalledAddOnBillingUsageResponseBillableItems { - - @JsonInclude(JsonInclude.Include.NON_EMPTY) - @JsonProperty("quantity") - @Getter - @Setter - private BigDecimal quantity; - - @JsonInclude(JsonInclude.Include.NON_EMPTY) - @JsonProperty("sid") - @Getter - @Setter - private String sid; - - @JsonInclude(JsonInclude.Include.NON_EMPTY) - @JsonProperty("submitted") - @Getter - @Setter - private Boolean submitted; - - public static MarketplaceV1InstalledAddOnBillingUsageResponseBillableItems fromJson( - String jsonString, - ObjectMapper mapper - ) throws IOException { - return mapper.readValue( - jsonString, - MarketplaceV1InstalledAddOnBillingUsageResponseBillableItems.class - ); - } - } - public static InstalledAddOnUsageCreator creator( final String pathInstalledAddOnSid, final InstalledAddOnUsage.MarketplaceV1InstalledAddOnInstalledAddOnUsage marketplaceV1InstalledAddOnInstalledAddOnUsage @@ -194,32 +174,32 @@ public static String toJson(Object object, ObjectMapper mapper) { } } + private final BigDecimal totalSubmitted; private final List< - MarketplaceV1InstalledAddOnBillingUsageResponseBillableItems + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems > billableItems; - private final BigDecimal totalSubmitted; @JsonCreator private InstalledAddOnUsage( + @JsonProperty("total_submitted") final BigDecimal totalSubmitted, @JsonProperty("billable_items") final List< - MarketplaceV1InstalledAddOnBillingUsageResponseBillableItems - > billableItems, - @JsonProperty("total_submitted") final BigDecimal totalSubmitted + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems + > billableItems ) { - this.billableItems = billableItems; this.totalSubmitted = totalSubmitted; + this.billableItems = billableItems; + } + + public final BigDecimal getTotalSubmitted() { + return this.totalSubmitted; } public final List< - MarketplaceV1InstalledAddOnBillingUsageResponseBillableItems + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems > getBillableItems() { return this.billableItems; } - public final BigDecimal getTotalSubmitted() { - return this.totalSubmitted; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -233,13 +213,13 @@ public boolean equals(final Object o) { InstalledAddOnUsage other = (InstalledAddOnUsage) o; return ( - Objects.equals(billableItems, other.billableItems) && - Objects.equals(totalSubmitted, other.totalSubmitted) + Objects.equals(totalSubmitted, other.totalSubmitted) && + Objects.equals(billableItems, other.billableItems) ); } @Override public int hashCode() { - return Objects.hash(billableItems, totalSubmitted); + return Objects.hash(totalSubmitted, billableItems); } } From a8976a3ad3b9cd02a1ada207188d1c9526e534d7 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 18 Sep 2024 13:22:09 +0000 Subject: [PATCH 2/5] Release 10.5.1 --- pom.xml | 4 ++-- src/main/java/com/twilio/Twilio.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 82693c469e..b21fb49f8e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ twilio jar twilio - 10.5.0 + 10.5.1 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 - 10.5.0 + 10.5.1 diff --git a/src/main/java/com/twilio/Twilio.java b/src/main/java/com/twilio/Twilio.java index 7f1c1130b2..2457d0aa53 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 = "10.5.0"; + public static final String VERSION = "10.5.1"; 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"); From bb8ec5f0a3302328bddfee6bf9e22a68bc756dd8 Mon Sep 17 00:00:00 2001 From: sbansla <104902068+sbansla@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:22:49 +0530 Subject: [PATCH 3/5] chore: updated readme for Beta flag (#815) --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index f2bccb2ce0..5e228b2645 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,26 @@ This library supports the following Java implementations: For Java 7 support, use `twilio-java` major version `7.X.X`. +### Beta Annotation + +To indicate that a class or method is in beta and subject to change, we use the `@Beta` annotation. For example: + +```java + +@Beta +public class ClassName { + // Class implementation +} + + +public class ClassName { + @Beta + public void init() { + // Implementation + } +} +``` + ## Installation `twilio-java` uses Maven. At present the jars _are_ available from a public [maven](https://mvnrepository.com/artifact/com.twilio.sdk/twilio) repository. From d5806b1fb602e5351f530049ee6e66ff4c91ad25 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 25 Sep 2024 11:48:59 +0000 Subject: [PATCH 4/5] [Librarian] Regenerated @ 08245333f4a8c9235d547b189cd9c422f73e0e7e 7bb98153c25ebfee95e6e85bd4c57969e6d02435 --- CHANGES.md | 14 + .../twilio/rest/accounts/v1/BulkConsents.java | 122 +++++++++ .../rest/accounts/v1/BulkConsentsCreator.java | 97 +++++++ .../twilio/rest/accounts/v1/BulkContacts.java | 122 +++++++++ .../rest/accounts/v1/BulkContactsCreator.java | 97 +++++++ .../twilio/rest/assistants/v1/Assistant.java | 23 +- .../twilio/rest/assistants/v1/Knowledge.java | 11 +- .../com/twilio/rest/assistants/v1/Tool.java | 111 +++++++- .../rest/assistants/v1/ToolFetcher.java | 70 +++++ .../v1/assistant/AssistantsKnowledge.java | 228 ++++++++++++++++ .../assistant/AssistantsKnowledgeCreator.java | 82 ++++++ .../assistant/AssistantsKnowledgeDeleter.java | 79 ++++++ .../assistant/AssistantsKnowledgeReader.java | 145 ++++++++++ .../v1/assistant/AssistantsTool.java | 229 ++++++++++++++++ .../v1/assistant/AssistantsToolCreator.java | 82 ++++++ .../v1/assistant/AssistantsToolDeleter.java | 79 ++++++ .../v1/assistant/AssistantsToolReader.java | 143 ++++++++++ .../rest/assistants/v1/assistant/Message.java | 249 ++++++++++++++++++ .../v1/assistant/MessageCreator.java | 102 +++++++ .../v1/knowledge/KnowledgeStatus.java | 145 ++++++++++ .../v1/knowledge/KnowledgeStatusFetcher.java | 73 +++++ ...okConfigurationFetch.java => Webhook.java} | 33 +-- ...nFetchFetcher.java => WebhookFetcher.java} | 16 +- .../environment/DeploymentCreator.java | 9 + 24 files changed, 2324 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/twilio/rest/accounts/v1/BulkConsents.java create mode 100644 src/main/java/com/twilio/rest/accounts/v1/BulkConsentsCreator.java create mode 100644 src/main/java/com/twilio/rest/accounts/v1/BulkContacts.java create mode 100644 src/main/java/com/twilio/rest/accounts/v1/BulkContactsCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/ToolFetcher.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledge.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeDeleter.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsTool.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolDeleter.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolReader.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/Message.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/assistant/MessageCreator.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatus.java create mode 100644 src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatusFetcher.java rename src/main/java/com/twilio/rest/numbers/v1/{PortingWebhookConfigurationFetch.java => Webhook.java} (82%) rename src/main/java/com/twilio/rest/numbers/v1/{PortingWebhookConfigurationFetchFetcher.java => WebhookFetcher.java} (79%) diff --git a/CHANGES.md b/CHANGES.md index c71ed13e07..8e466d202e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,20 @@ twilio-java changelog ===================== +[2024-09-25] Version 10.5.2 +--------------------------- +**Library - Chore** +- [PR #815](https://github.com/twilio/twilio-java/pull/815): updated readme for Beta flag. Thanks to [@sbansla](https://github.com/sbansla)! + +**Accounts** +- Update docs and mounts. +- Change library visibility to public +- Enable consent and contact bulk upsert APIs in prod. + +**Serverless** +- Add is_plugin parameter in deployments api to check if it is plugins deployment + + [2024-09-18] Version 10.5.1 --------------------------- **Intelligence** diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkConsents.java b/src/main/java/com/twilio/rest/accounts/v1/BulkConsents.java new file mode 100644 index 0000000000..2ef3ff3e24 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkConsents.java @@ -0,0 +1,122 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * 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.accounts.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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +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 BulkConsents extends Resource { + + private static final long serialVersionUID = 126137950684284L; + + public static BulkConsentsCreator creator( + final List> items + ) { + return new BulkConsentsCreator(items); + } + + /** + * Converts a JSON String into a BulkConsents object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BulkConsents object represented by the provided JSON + */ + public static BulkConsents fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkConsents.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 BulkConsents object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BulkConsents object represented by the provided JSON + */ + public static BulkConsents fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkConsents.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final Map items; + + @JsonCreator + private BulkConsents( + @JsonProperty("items") final Map items + ) { + this.items = items; + } + + public final Map getItems() { + return this.items; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BulkConsents other = (BulkConsents) o; + + return Objects.equals(items, other.items); + } + + @Override + public int hashCode() { + return Objects.hash(items); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkConsentsCreator.java b/src/main/java/com/twilio/rest/accounts/v1/BulkConsentsCreator.java new file mode 100644 index 0000000000..93a1b73bbf --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkConsentsCreator.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * 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.accounts.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.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; +import java.util.Map; +import java.util.Map; + +public class BulkConsentsCreator extends Creator { + + private List> items; + + public BulkConsentsCreator(final List> items) { + this.items = items; + } + + public BulkConsentsCreator setItems(final List> items) { + this.items = items; + return this; + } + + public BulkConsentsCreator setItems(final Map items) { + return setItems(Promoter.listOfOne(items)); + } + + @Override + public BulkConsents create(final TwilioRestClient client) { + String path = "/v1/Consents/Bulk"; + + path = path.replace("{" + "Items" + "}", this.items.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( + "BulkConsents 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 BulkConsents.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request) { + if (items != null) { + for (Map prop : items) { + request.addPostParam("Items", Converter.mapToJson(prop)); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkContacts.java b/src/main/java/com/twilio/rest/accounts/v1/BulkContacts.java new file mode 100644 index 0000000000..fbb28d1b7f --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkContacts.java @@ -0,0 +1,122 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * 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.accounts.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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +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 BulkContacts extends Resource { + + private static final long serialVersionUID = 126137950684284L; + + public static BulkContactsCreator creator( + final List> items + ) { + return new BulkContactsCreator(items); + } + + /** + * Converts a JSON String into a BulkContacts object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BulkContacts object represented by the provided JSON + */ + public static BulkContacts fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkContacts.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 BulkContacts object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BulkContacts object represented by the provided JSON + */ + public static BulkContacts fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkContacts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final Map items; + + @JsonCreator + private BulkContacts( + @JsonProperty("items") final Map items + ) { + this.items = items; + } + + public final Map getItems() { + return this.items; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BulkContacts other = (BulkContacts) o; + + return Objects.equals(items, other.items); + } + + @Override + public int hashCode() { + return Objects.hash(items); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkContactsCreator.java b/src/main/java/com/twilio/rest/accounts/v1/BulkContactsCreator.java new file mode 100644 index 0000000000..0f3653b994 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkContactsCreator.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * 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.accounts.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.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; +import java.util.Map; +import java.util.Map; + +public class BulkContactsCreator extends Creator { + + private List> items; + + public BulkContactsCreator(final List> items) { + this.items = items; + } + + public BulkContactsCreator setItems(final List> items) { + this.items = items; + return this; + } + + public BulkContactsCreator setItems(final Map items) { + return setItems(Promoter.listOfOne(items)); + } + + @Override + public BulkContacts create(final TwilioRestClient client) { + String path = "/v1/Contacts/Bulk"; + + path = path.replace("{" + "Items" + "}", this.items.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( + "BulkContacts 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 BulkContacts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request) { + if (items != null) { + for (Map prop : items) { + request.addPostParam("Items", Converter.mapToJson(prop)); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/Assistant.java b/src/main/java/com/twilio/rest/assistants/v1/Assistant.java index fb4182bab7..65f4a5b759 100644 --- a/src/main/java/com/twilio/rest/assistants/v1/Assistant.java +++ b/src/main/java/com/twilio/rest/assistants/v1/Assistant.java @@ -43,7 +43,7 @@ @ToString public class Assistant extends Resource { - private static final long serialVersionUID = 83480490674350L; + private static final long serialVersionUID = 5177924616338L; @ToString public static class AssistantsV1ServiceCustomerAi { @@ -244,6 +244,12 @@ public String getKnowledgeSourceDetails() { @Setter private String type; + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + @Setter + private String url; + @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("date_created") @Getter @@ -330,6 +336,12 @@ public String getMeta() { @Setter private String type; + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + @Setter + private String url; + @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("date_created") @Getter @@ -441,6 +453,7 @@ public static String toJson(Object object, ObjectMapper mapper) { private final String model; private final String name; private final String owner; + private final String url; private final String personalityPrompt; private final ZonedDateTime dateCreated; private final ZonedDateTime dateUpdated; @@ -455,6 +468,7 @@ private Assistant( @JsonProperty("model") final String model, @JsonProperty("name") final String name, @JsonProperty("owner") final String owner, + @JsonProperty("url") final String url, @JsonProperty("personality_prompt") final String personalityPrompt, @JsonProperty("date_created") final String dateCreated, @JsonProperty("date_updated") final String dateUpdated, @@ -469,6 +483,7 @@ private Assistant( this.model = model; this.name = name; this.owner = owner; + this.url = url; this.personalityPrompt = personalityPrompt; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); @@ -500,6 +515,10 @@ public final String getOwner() { return this.owner; } + public final String getUrl() { + return this.url; + } + public final String getPersonalityPrompt() { return this.personalityPrompt; } @@ -539,6 +558,7 @@ public boolean equals(final Object o) { Objects.equals(model, other.model) && Objects.equals(name, other.name) && Objects.equals(owner, other.owner) && + Objects.equals(url, other.url) && Objects.equals(personalityPrompt, other.personalityPrompt) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) && @@ -556,6 +576,7 @@ public int hashCode() { model, name, owner, + url, personalityPrompt, dateCreated, dateUpdated, diff --git a/src/main/java/com/twilio/rest/assistants/v1/Knowledge.java b/src/main/java/com/twilio/rest/assistants/v1/Knowledge.java index ed482235c5..2944126a82 100644 --- a/src/main/java/com/twilio/rest/assistants/v1/Knowledge.java +++ b/src/main/java/com/twilio/rest/assistants/v1/Knowledge.java @@ -42,7 +42,7 @@ @ToString public class Knowledge extends Resource { - private static final long serialVersionUID = 228486068645709L; + private static final long serialVersionUID = 102491745229273L; @ToString public static class AssistantsV1ServiceCreatePolicyRequest { @@ -282,6 +282,7 @@ public static String toJson(Object object, ObjectMapper mapper) { private final String name; private final String status; private final String type; + private final String url; private final ZonedDateTime dateCreated; private final ZonedDateTime dateUpdated; @@ -297,6 +298,7 @@ private Knowledge( @JsonProperty("name") final String name, @JsonProperty("status") final String status, @JsonProperty("type") final String type, + @JsonProperty("url") final String url, @JsonProperty("date_created") final String dateCreated, @JsonProperty("date_updated") final String dateUpdated ) { @@ -307,6 +309,7 @@ private Knowledge( this.name = name; this.status = status; this.type = type; + this.url = url; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); } @@ -339,6 +342,10 @@ public final String getType() { return this.type; } + public final String getUrl() { + return this.url; + } + public final ZonedDateTime getDateCreated() { return this.dateCreated; } @@ -370,6 +377,7 @@ public boolean equals(final Object o) { Objects.equals(name, other.name) && Objects.equals(status, other.status) && Objects.equals(type, other.type) && + Objects.equals(url, other.url) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(dateUpdated, other.dateUpdated) ); @@ -385,6 +393,7 @@ public int hashCode() { name, status, type, + url, dateCreated, dateUpdated ); diff --git a/src/main/java/com/twilio/rest/assistants/v1/Tool.java b/src/main/java/com/twilio/rest/assistants/v1/Tool.java index 6347579d67..1744594cd6 100644 --- a/src/main/java/com/twilio/rest/assistants/v1/Tool.java +++ b/src/main/java/com/twilio/rest/assistants/v1/Tool.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.time.ZonedDateTime; +import java.util.List; import java.util.Map; import java.util.Map; import java.util.Objects; @@ -42,7 +43,7 @@ @ToString public class Tool extends Resource { - private static final long serialVersionUID = 250744757874592L; + private static final long serialVersionUID = 65943663776562L; @ToString public static class AssistantsV1ServiceCreatePolicyRequest { @@ -216,6 +217,86 @@ public static AssistantsV1ServiceUpdateToolRequest fromJson( } } + @ToString + public static class AssistantsV1ServicePolicy { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + @Setter + private String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + @Setter + private String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + @Setter + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountSid") + @Getter + @Setter + private String accountSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("userSid") + @Getter + @Setter + private String userSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + @Setter + private String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policyDetails") + @Getter + @Setter + private Map policyDetails; + + public String getPolicyDetails() { + return Converter.mapToJson(policyDetails); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateCreated") + @Getter + @Setter + private ZonedDateTime dateCreated; + + public String getDateCreated() { + return dateCreated.toInstant().toString(); + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateUpdated") + @Getter + @Setter + private ZonedDateTime dateUpdated; + + public String getDateUpdated() { + return dateUpdated.toInstant().toString(); + } + + public static AssistantsV1ServicePolicy fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServicePolicy.class + ); + } + } + public static ToolCreator creator( final Tool.AssistantsV1ServiceCreateToolRequest assistantsV1ServiceCreateToolRequest ) { @@ -226,6 +307,10 @@ public static ToolDeleter deleter(final String pathId) { return new ToolDeleter(pathId); } + public static ToolFetcher fetcher(final String pathId) { + return new ToolFetcher(pathId); + } + public static ToolReader reader() { return new ToolReader(); } @@ -297,8 +382,10 @@ public static String toJson(Object object, ObjectMapper mapper) { private final String name; private final Boolean requiresAuth; private final String type; + private final String url; private final ZonedDateTime dateCreated; private final ZonedDateTime dateUpdated; + private final List policies; @JsonCreator private Tool( @@ -310,8 +397,10 @@ private Tool( @JsonProperty("name") final String name, @JsonProperty("requires_auth") final Boolean requiresAuth, @JsonProperty("type") final String type, + @JsonProperty("url") final String url, @JsonProperty("date_created") final String dateCreated, - @JsonProperty("date_updated") final String dateUpdated + @JsonProperty("date_updated") final String dateUpdated, + @JsonProperty("policies") final List policies ) { this.accountSid = accountSid; this.description = description; @@ -321,8 +410,10 @@ private Tool( this.name = name; this.requiresAuth = requiresAuth; this.type = type; + this.url = url; this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.policies = policies; } public final String getAccountSid() { @@ -357,6 +448,10 @@ public final String getType() { return this.type; } + public final String getUrl() { + return this.url; + } + public final ZonedDateTime getDateCreated() { return this.dateCreated; } @@ -365,6 +460,10 @@ public final ZonedDateTime getDateUpdated() { return this.dateUpdated; } + public final List getPolicies() { + return this.policies; + } + @Override public boolean equals(final Object o) { if (this == o) { @@ -386,8 +485,10 @@ public boolean equals(final Object o) { Objects.equals(name, other.name) && Objects.equals(requiresAuth, other.requiresAuth) && Objects.equals(type, other.type) && + Objects.equals(url, other.url) && Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(policies, other.policies) ); } @@ -402,8 +503,10 @@ public int hashCode() { name, requiresAuth, type, + url, dateCreated, - dateUpdated + dateUpdated, + policies ); } } diff --git a/src/main/java/com/twilio/rest/assistants/v1/ToolFetcher.java b/src/main/java/com/twilio/rest/assistants/v1/ToolFetcher.java new file mode 100644 index 0000000000..d1adfc8f4a --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/ToolFetcher.java @@ -0,0 +1,70 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1; + +import com.twilio.base.Fetcher; +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 ToolFetcher extends Fetcher { + + private String pathId; + + public ToolFetcher(final String pathId) { + this.pathId = pathId; + } + + @Override + public Tool fetch(final TwilioRestClient client) { + String path = "/v1/Tools/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Tool 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Tool.fromJson(response.getStream(), client.getObjectMapper()); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledge.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledge.java new file mode 100644 index 0000000000..80681cc9d0 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledge.java @@ -0,0 +1,228 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AssistantsKnowledge extends Resource { + + private static final long serialVersionUID = 102491745229273L; + + public static AssistantsKnowledgeCreator creator( + final String pathAssistantId, + final String pathId + ) { + return new AssistantsKnowledgeCreator(pathAssistantId, pathId); + } + + public static AssistantsKnowledgeDeleter deleter( + final String pathAssistantId, + final String pathId + ) { + return new AssistantsKnowledgeDeleter(pathAssistantId, pathId); + } + + public static AssistantsKnowledgeReader reader( + final String pathAssistantId + ) { + return new AssistantsKnowledgeReader(pathAssistantId); + } + + /** + * Converts a JSON String into a AssistantsKnowledge object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssistantsKnowledge object represented by the provided JSON + */ + public static AssistantsKnowledge fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AssistantsKnowledge.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 AssistantsKnowledge object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssistantsKnowledge object represented by the provided JSON + */ + public static AssistantsKnowledge fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AssistantsKnowledge.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final String description; + private final String id; + private final String accountSid; + private final Map knowledgeSourceDetails; + private final String name; + private final String status; + private final String type; + private final String url; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private AssistantsKnowledge( + @JsonProperty("description") final String description, + @JsonProperty("id") final String id, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("knowledge_source_details") final Map< + String, + Object + > knowledgeSourceDetails, + @JsonProperty("name") final String name, + @JsonProperty("status") final String status, + @JsonProperty("type") final String type, + @JsonProperty("url") final String url, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.description = description; + this.id = id; + this.accountSid = accountSid; + this.knowledgeSourceDetails = knowledgeSourceDetails; + this.name = name; + this.status = status; + this.type = type; + this.url = url; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getDescription() { + return this.description; + } + + public final String getId() { + return this.id; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final Map getKnowledgeSourceDetails() { + return this.knowledgeSourceDetails; + } + + public final String getName() { + return this.name; + } + + public final String getStatus() { + return this.status; + } + + public final String getType() { + return this.type; + } + + public final String 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) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AssistantsKnowledge other = (AssistantsKnowledge) o; + + return ( + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + knowledgeSourceDetails, + other.knowledgeSourceDetails + ) && + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + description, + id, + accountSid, + knowledgeSourceDetails, + name, + status, + type, + url, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeCreator.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeCreator.java new file mode 100644 index 0000000000..06accb38c0 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeCreator.java @@ -0,0 +1,82 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.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; +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 AssistantsKnowledgeCreator extends Creator { + + private String pathAssistantId; + private String pathId; + + public AssistantsKnowledgeCreator( + final String pathAssistantId, + final String pathId + ) { + this.pathAssistantId = pathAssistantId; + this.pathId = pathId; + } + + @Override + public AssistantsKnowledge create(final TwilioRestClient client) { + String path = "/v1/Assistants/{assistantId}/Knowledge/{id}"; + + path = + path.replace( + "{" + "assistantId" + "}", + this.pathAssistantId.toString() + ); + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AssistantsKnowledge 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 AssistantsKnowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeDeleter.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeDeleter.java new file mode 100644 index 0000000000..112ecccd82 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeDeleter.java @@ -0,0 +1,79 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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 AssistantsKnowledgeDeleter extends Deleter { + + private String pathAssistantId; + private String pathId; + + public AssistantsKnowledgeDeleter( + final String pathAssistantId, + final String pathId + ) { + this.pathAssistantId = pathAssistantId; + this.pathId = pathId; + } + + @Override + public boolean delete(final TwilioRestClient client) { + String path = "/v1/Assistants/{assistantId}/Knowledge/{id}"; + + path = + path.replace( + "{" + "assistantId" + "}", + this.pathAssistantId.toString() + ); + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.DELETE, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AssistantsKnowledge 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/assistants/v1/assistant/AssistantsKnowledgeReader.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeReader.java new file mode 100644 index 0000000000..a605002d0e --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsKnowledgeReader.java @@ -0,0 +1,145 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 AssistantsKnowledgeReader extends Reader { + + private String pathAssistantId; + private Integer pageSize; + + public AssistantsKnowledgeReader(final String pathAssistantId) { + this.pathAssistantId = pathAssistantId; + } + + public AssistantsKnowledgeReader 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/Assistants/{assistantId}/Knowledge"; + path = + path.replace( + "{" + "assistantId" + "}", + this.pathAssistantId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AssistantsKnowledge 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "knowledge", + response.getContent(), + AssistantsKnowledge.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (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/assistants/v1/assistant/AssistantsTool.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsTool.java new file mode 100644 index 0000000000..c3114a8a11 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsTool.java @@ -0,0 +1,229 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Map; +import java.util.Objects; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AssistantsTool extends Resource { + + private static final long serialVersionUID = 65943663776562L; + + public static AssistantsToolCreator creator( + final String pathAssistantId, + final String pathId + ) { + return new AssistantsToolCreator(pathAssistantId, pathId); + } + + public static AssistantsToolDeleter deleter( + final String pathAssistantId, + final String pathId + ) { + return new AssistantsToolDeleter(pathAssistantId, pathId); + } + + public static AssistantsToolReader reader(final String pathAssistantId) { + return new AssistantsToolReader(pathAssistantId); + } + + /** + * Converts a JSON String into a AssistantsTool object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssistantsTool object represented by the provided JSON + */ + public static AssistantsTool fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AssistantsTool.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 AssistantsTool object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssistantsTool object represented by the provided JSON + */ + public static AssistantsTool fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AssistantsTool.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final String accountSid; + private final String description; + private final Boolean enabled; + private final String id; + private final Map meta; + private final String name; + private final Boolean requiresAuth; + private final String type; + private final String url; + private final ZonedDateTime dateCreated; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private AssistantsTool( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("description") final String description, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("id") final String id, + @JsonProperty("meta") final Map meta, + @JsonProperty("name") final String name, + @JsonProperty("requires_auth") final Boolean requiresAuth, + @JsonProperty("type") final String type, + @JsonProperty("url") final String url, + @JsonProperty("date_created") final String dateCreated, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.accountSid = accountSid; + this.description = description; + this.enabled = enabled; + this.id = id; + this.meta = meta; + this.name = name; + this.requiresAuth = requiresAuth; + this.type = type; + this.url = url; + this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getDescription() { + return this.description; + } + + public final Boolean getEnabled() { + return this.enabled; + } + + public final String getId() { + return this.id; + } + + public final Map getMeta() { + return this.meta; + } + + public final String getName() { + return this.name; + } + + public final Boolean getRequiresAuth() { + return this.requiresAuth; + } + + public final String getType() { + return this.type; + } + + public final String 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) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AssistantsTool other = (AssistantsTool) o; + + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(description, other.description) && + Objects.equals(enabled, other.enabled) && + Objects.equals(id, other.id) && + Objects.equals(meta, other.meta) && + Objects.equals(name, other.name) && + Objects.equals(requiresAuth, other.requiresAuth) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + description, + enabled, + id, + meta, + name, + requiresAuth, + type, + url, + dateCreated, + dateUpdated + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolCreator.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolCreator.java new file mode 100644 index 0000000000..8b2b1a87d5 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolCreator.java @@ -0,0 +1,82 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.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; +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 AssistantsToolCreator extends Creator { + + private String pathAssistantId; + private String pathId; + + public AssistantsToolCreator( + final String pathAssistantId, + final String pathId + ) { + this.pathAssistantId = pathAssistantId; + this.pathId = pathId; + } + + @Override + public AssistantsTool create(final TwilioRestClient client) { + String path = "/v1/Assistants/{assistantId}/Tools/{id}"; + + path = + path.replace( + "{" + "assistantId" + "}", + this.pathAssistantId.toString() + ); + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AssistantsTool 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 AssistantsTool.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolDeleter.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolDeleter.java new file mode 100644 index 0000000000..7093946dc7 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolDeleter.java @@ -0,0 +1,79 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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 AssistantsToolDeleter extends Deleter { + + private String pathAssistantId; + private String pathId; + + public AssistantsToolDeleter( + final String pathAssistantId, + final String pathId + ) { + this.pathAssistantId = pathAssistantId; + this.pathId = pathId; + } + + @Override + public boolean delete(final TwilioRestClient client) { + String path = "/v1/Assistants/{assistantId}/Tools/{id}"; + + path = + path.replace( + "{" + "assistantId" + "}", + this.pathAssistantId.toString() + ); + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.DELETE, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AssistantsTool 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/assistants/v1/assistant/AssistantsToolReader.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolReader.java new file mode 100644 index 0000000000..73fed075b1 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/AssistantsToolReader.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +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 AssistantsToolReader extends Reader { + + private String pathAssistantId; + private Integer pageSize; + + public AssistantsToolReader(final String pathAssistantId) { + this.pathAssistantId = pathAssistantId; + } + + public AssistantsToolReader 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/Assistants/{assistantId}/Tools"; + path = + path.replace( + "{" + "assistantId" + "}", + this.pathAssistantId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AssistantsTool 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Page.fromJson( + "tools", + response.getContent(), + AssistantsTool.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.ASSISTANTS.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.ASSISTANTS.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 (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/assistants/v1/assistant/Message.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/Message.java new file mode 100644 index 0000000000..3891e48b3e --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/Message.java @@ -0,0 +1,249 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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 java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Message extends Resource { + + private static final long serialVersionUID = 131790089402244L; + + @ToString + public static class AssistantsV1ServiceAssistantSendMessageRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("identity") + @Getter + @Setter + private String identity; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + @Getter + @Setter + private String sessionId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + @Setter + private String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("webhook") + @Getter + @Setter + private String webhook; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mode") + @Getter + @Setter + private String mode; + + public AssistantsV1ServiceAssistantSendMessageRequest( + final String identity, + final String body + ) { + this.identity = identity; + this.body = body; + } + + public static AssistantsV1ServiceAssistantSendMessageRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AssistantsV1ServiceAssistantSendMessageRequest.class + ); + } + } + + public static MessageCreator creator( + final String pathId, + final Message.AssistantsV1ServiceAssistantSendMessageRequest assistantsV1ServiceAssistantSendMessageRequest + ) { + return new MessageCreator( + pathId, + assistantsV1ServiceAssistantSendMessageRequest + ); + } + + /** + * 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); + } 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 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); + } 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 status; + private final Boolean flagged; + private final Boolean aborted; + private final String sessionId; + private final String accountSid; + private final String body; + private final String error; + + @JsonCreator + private Message( + @JsonProperty("status") final String status, + @JsonProperty("flagged") final Boolean flagged, + @JsonProperty("aborted") final Boolean aborted, + @JsonProperty("session_id") final String sessionId, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("body") final String body, + @JsonProperty("error") final String error + ) { + this.status = status; + this.flagged = flagged; + this.aborted = aborted; + this.sessionId = sessionId; + this.accountSid = accountSid; + this.body = body; + this.error = error; + } + + public final String getStatus() { + return this.status; + } + + public final Boolean getFlagged() { + return this.flagged; + } + + public final Boolean getAborted() { + return this.aborted; + } + + public final String getSessionId() { + return this.sessionId; + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getBody() { + return this.body; + } + + public final String getError() { + return this.error; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Message other = (Message) o; + + return ( + Objects.equals(status, other.status) && + Objects.equals(flagged, other.flagged) && + Objects.equals(aborted, other.aborted) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(body, other.body) && + Objects.equals(error, other.error) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + status, + flagged, + aborted, + sessionId, + accountSid, + body, + error + ); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/assistant/MessageCreator.java b/src/main/java/com/twilio/rest/assistants/v1/assistant/MessageCreator.java new file mode 100644 index 0000000000..3862f76d3e --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/assistant/MessageCreator.java @@ -0,0 +1,102 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.assistant; + +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 MessageCreator extends Creator { + + private String pathId; + private Message.AssistantsV1ServiceAssistantSendMessageRequest assistantsV1ServiceAssistantSendMessageRequest; + + public MessageCreator( + final String pathId, + final Message.AssistantsV1ServiceAssistantSendMessageRequest assistantsV1ServiceAssistantSendMessageRequest + ) { + this.pathId = pathId; + this.assistantsV1ServiceAssistantSendMessageRequest = + assistantsV1ServiceAssistantSendMessageRequest; + } + + public MessageCreator setAssistantsV1ServiceAssistantSendMessageRequest( + final Message.AssistantsV1ServiceAssistantSendMessageRequest assistantsV1ServiceAssistantSendMessageRequest + ) { + this.assistantsV1ServiceAssistantSendMessageRequest = + assistantsV1ServiceAssistantSendMessageRequest; + return this; + } + + @Override + public Message create(final TwilioRestClient client) { + String path = "/v1/Assistants/{id}/Messages"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + path = + path.replace( + "{" + "AssistantsV1ServiceAssistantSendMessageRequest" + "}", + this.assistantsV1ServiceAssistantSendMessageRequest.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + 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() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Message.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (assistantsV1ServiceAssistantSendMessageRequest != null) { + request.setBody( + Message.toJson( + assistantsV1ServiceAssistantSendMessageRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatus.java b/src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatus.java new file mode 100644 index 0000000000..53b6a90e58 --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatus.java @@ -0,0 +1,145 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.knowledge; + +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.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +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 KnowledgeStatus extends Resource { + + private static final long serialVersionUID = 178959927465400L; + + public static KnowledgeStatusFetcher fetcher(final String pathId) { + return new KnowledgeStatusFetcher(pathId); + } + + /** + * Converts a JSON String into a KnowledgeStatus object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return KnowledgeStatus object represented by the provided JSON + */ + public static KnowledgeStatus fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, KnowledgeStatus.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 KnowledgeStatus object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return KnowledgeStatus object represented by the provided JSON + */ + public static KnowledgeStatus fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, KnowledgeStatus.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private final String accountSid; + private final String status; + private final String lastStatus; + private final ZonedDateTime dateUpdated; + + @JsonCreator + private KnowledgeStatus( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("status") final String status, + @JsonProperty("last_status") final String lastStatus, + @JsonProperty("date_updated") final String dateUpdated + ) { + this.accountSid = accountSid; + this.status = status; + this.lastStatus = lastStatus; + this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + } + + public final String getAccountSid() { + return this.accountSid; + } + + public final String getStatus() { + return this.status; + } + + public final String getLastStatus() { + return this.lastStatus; + } + + public final ZonedDateTime getDateUpdated() { + return this.dateUpdated; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeStatus other = (KnowledgeStatus) o; + + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(status, other.status) && + Objects.equals(lastStatus, other.lastStatus) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, status, lastStatus, dateUpdated); + } +} diff --git a/src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatusFetcher.java b/src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatusFetcher.java new file mode 100644 index 0000000000..bfd9bc2dac --- /dev/null +++ b/src/main/java/com/twilio/rest/assistants/v1/knowledge/KnowledgeStatusFetcher.java @@ -0,0 +1,73 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Assistants + * 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.assistants.v1.knowledge; + +import com.twilio.base.Fetcher; +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 KnowledgeStatusFetcher extends Fetcher { + + private String pathId; + + public KnowledgeStatusFetcher(final String pathId) { + this.pathId = pathId; + } + + @Override + public KnowledgeStatus fetch(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}/Status"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.ASSISTANTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "KnowledgeStatus 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", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return KnowledgeStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationFetch.java b/src/main/java/com/twilio/rest/numbers/v1/Webhook.java similarity index 82% rename from src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationFetch.java rename to src/main/java/com/twilio/rest/numbers/v1/Webhook.java index 53c0f02a23..6e9c6921dd 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationFetch.java +++ b/src/main/java/com/twilio/rest/numbers/v1/Webhook.java @@ -35,31 +35,28 @@ @JsonIgnoreProperties(ignoreUnknown = true) @ToString -public class PortingWebhookConfigurationFetch extends Resource { +public class Webhook extends Resource { private static final long serialVersionUID = 270526030240961L; - public static PortingWebhookConfigurationFetchFetcher fetcher() { - return new PortingWebhookConfigurationFetchFetcher(); + public static WebhookFetcher fetcher() { + return new WebhookFetcher(); } /** - * Converts a JSON String into a PortingWebhookConfigurationFetch object using the provided ObjectMapper. + * Converts a JSON String into a Webhook object using the provided ObjectMapper. * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper - * @return PortingWebhookConfigurationFetch object represented by the provided JSON + * @return Webhook object represented by the provided JSON */ - public static PortingWebhookConfigurationFetch fromJson( + public static Webhook fromJson( final String json, final ObjectMapper objectMapper ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue( - json, - PortingWebhookConfigurationFetch.class - ); + return objectMapper.readValue(json, Webhook.class); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -68,23 +65,20 @@ public static PortingWebhookConfigurationFetch fromJson( } /** - * Converts a JSON InputStream into a PortingWebhookConfigurationFetch object using the provided + * Converts a JSON InputStream into a Webhook object using the provided * ObjectMapper. * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper - * @return PortingWebhookConfigurationFetch object represented by the provided JSON + * @return Webhook object represented by the provided JSON */ - public static PortingWebhookConfigurationFetch fromJson( + public static Webhook fromJson( final InputStream json, final ObjectMapper objectMapper ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue( - json, - PortingWebhookConfigurationFetch.class - ); + return objectMapper.readValue(json, Webhook.class); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -100,7 +94,7 @@ public static PortingWebhookConfigurationFetch fromJson( private final ZonedDateTime portOutTargetDateCreated; @JsonCreator - private PortingWebhookConfigurationFetch( + private Webhook( @JsonProperty("url") final URI url, @JsonProperty("port_in_target_url") final URI portInTargetUrl, @JsonProperty("port_out_target_url") final URI portOutTargetUrl, @@ -156,8 +150,7 @@ public boolean equals(final Object o) { return false; } - PortingWebhookConfigurationFetch other = - (PortingWebhookConfigurationFetch) o; + Webhook other = (Webhook) o; return ( Objects.equals(url, other.url) && diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationFetchFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/WebhookFetcher.java similarity index 79% rename from src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationFetchFetcher.java rename to src/main/java/com/twilio/rest/numbers/v1/WebhookFetcher.java index 59d0dc599f..ccffc00624 100644 --- a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationFetchFetcher.java +++ b/src/main/java/com/twilio/rest/numbers/v1/WebhookFetcher.java @@ -25,15 +25,12 @@ import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -public class PortingWebhookConfigurationFetchFetcher - extends Fetcher { +public class WebhookFetcher extends Fetcher { - public PortingWebhookConfigurationFetchFetcher() {} + public WebhookFetcher() {} @Override - public PortingWebhookConfigurationFetch fetch( - final TwilioRestClient client - ) { + public Webhook fetch(final TwilioRestClient client) { String path = "/v1/Porting/Configuration/Webhook"; Request request = new Request( @@ -46,7 +43,7 @@ public PortingWebhookConfigurationFetch fetch( if (response == null) { throw new ApiConnectionException( - "PortingWebhookConfigurationFetch fetch failed: Unable to connect to server" + "Webhook fetch failed: Unable to connect to server" ); } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson( @@ -62,9 +59,6 @@ public PortingWebhookConfigurationFetch fetch( throw new ApiException(restException); } - return PortingWebhookConfigurationFetch.fromJson( - response.getStream(), - client.getObjectMapper() - ); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } } 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 788e9bf1eb..cf96fdb3aa 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 @@ -30,6 +30,7 @@ public class DeploymentCreator extends Creator { private String pathServiceSid; private String pathEnvironmentSid; private String buildSid; + private Boolean isPlugin; public DeploymentCreator( final String pathServiceSid, @@ -44,6 +45,11 @@ public DeploymentCreator setBuildSid(final String buildSid) { return this; } + public DeploymentCreator setIsPlugin(final Boolean isPlugin) { + this.isPlugin = isPlugin; + return this; + } + @Override public Deployment create(final TwilioRestClient client) { String path = @@ -96,5 +102,8 @@ private void addPostParams(final Request request) { if (buildSid != null) { request.addPostParam("BuildSid", buildSid); } + if (isPlugin != null) { + request.addPostParam("IsPlugin", isPlugin.toString()); + } } } From fab34c10459c57188421047f341d26e996c53060 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 25 Sep 2024 11:52:04 +0000 Subject: [PATCH 5/5] Release 10.5.2 --- pom.xml | 4 ++-- src/main/java/com/twilio/Twilio.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b21fb49f8e..5033f4047d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ twilio jar twilio - 10.5.1 + 10.5.2 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 - 10.5.1 + 10.5.2 diff --git a/src/main/java/com/twilio/Twilio.java b/src/main/java/com/twilio/Twilio.java index 2457d0aa53..2f98b0a52d 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 = "10.5.1"; + public static final String VERSION = "10.5.2"; 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");