diff --git a/client/src/main/com/sinch/sdk/domains/numbers/models/Capability.java b/client/src/main/com/sinch/sdk/domains/numbers/models/Capability.java index 597999fb..801d3137 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/models/Capability.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/models/Capability.java @@ -10,14 +10,14 @@ * * @since 1.0 */ -public final class Capability extends EnumDynamic { +public final class Capability extends EnumDynamic { /** The SMS product can use the number. */ public static final Capability SMS = new Capability("SMS"); /** The Voice product can use the number. */ public static final Capability VOICE = new Capability("VOICE"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>(Capability.class, Capability::new, Arrays.asList(SMS, VOICE)); private Capability(String value) { diff --git a/client/src/main/com/sinch/sdk/domains/numbers/models/NumberType.java b/client/src/main/com/sinch/sdk/domains/numbers/models/NumberType.java index e4d58982..54e4e3bd 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/models/NumberType.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/models/NumberType.java @@ -10,7 +10,7 @@ * * @since 1.0 */ -public final class NumberType extends EnumDynamic { +public final class NumberType extends EnumDynamic { /** Numbers that belong to a specific range. */ public static final NumberType MOBILE = new NumberType("MOBILE"); @@ -20,7 +20,7 @@ public final class NumberType extends EnumDynamic { /** Numbers that are free of charge for the calling party but billed for all arriving calls. */ public static final NumberType TOLL_FREE = new NumberType("TOLL_FREE"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>( NumberType.class, NumberType::new, Arrays.asList(MOBILE, LOCAL, TOLL_FREE)); diff --git a/client/src/main/com/sinch/sdk/domains/numbers/models/OrderBy.java b/client/src/main/com/sinch/sdk/domains/numbers/models/OrderBy.java index 9717c3e8..9dacfc1d 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/models/OrderBy.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/models/OrderBy.java @@ -10,13 +10,13 @@ * * @since 1.0 */ -public final class OrderBy extends EnumDynamic { +public final class OrderBy extends EnumDynamic { /** Ordering by phoneNumber */ public static final OrderBy PHONE_NUMBER = new OrderBy("phoneNumber"); /** Ordering by displayName */ public static final OrderBy DISPLAY_NAME = new OrderBy("displayName"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>( OrderBy.class, OrderBy::new, Arrays.asList(PHONE_NUMBER, DISPLAY_NAME)); diff --git a/client/src/main/com/sinch/sdk/domains/numbers/models/ProvisioningStatus.java b/client/src/main/com/sinch/sdk/domains/numbers/models/ProvisioningStatus.java index 4b9cd6a6..4bd5e95b 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/models/ProvisioningStatus.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/models/ProvisioningStatus.java @@ -12,7 +12,7 @@ * href="https://developers.sinch.com/docs/numbers/api-reference/error-codes/provisioning-errors/">https://developers.sinch.com/docs/numbers/api-reference/error-codes/provisioning-errors/ * @since 1.0 */ -public final class ProvisioningStatus extends EnumDynamic { +public final class ProvisioningStatus extends EnumDynamic { public static final ProvisioningStatus PROVISIONING_STATUS_UNSPECIFIED = new ProvisioningStatus("PROVISIONING_STATUS_UNSPECIFIED"); @@ -22,7 +22,7 @@ public final class ProvisioningStatus extends EnumDynamic { public static final ProvisioningStatus UNKNOWN_DEFAULT_OPEN_API = new ProvisioningStatus("UNKNOWN_DEFAULT_OPEN_API"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>( ProvisioningStatus.class, ProvisioningStatus::new, diff --git a/client/src/main/com/sinch/sdk/domains/numbers/models/SearchPattern.java b/client/src/main/com/sinch/sdk/domains/numbers/models/SearchPattern.java index f5e2323c..47a69b85 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/models/SearchPattern.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/models/SearchPattern.java @@ -9,7 +9,7 @@ * * @since 1.0 */ -public final class SearchPattern extends EnumDynamic { +public final class SearchPattern extends EnumDynamic { /** * Numbers that begin with the @see NumberPattern.getPattern entered. * @@ -26,7 +26,7 @@ public final class SearchPattern extends EnumDynamic { /** The number ends with the number pattern entered. */ public static final SearchPattern END = new SearchPattern("END"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>( SearchPattern.class, SearchPattern::new, Arrays.asList(START, CONTAINS, END)); diff --git a/client/src/main/com/sinch/sdk/domains/numbers/models/SmsErrorCode.java b/client/src/main/com/sinch/sdk/domains/numbers/models/SmsErrorCode.java index 18007c3a..a876fba8 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/models/SmsErrorCode.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/models/SmsErrorCode.java @@ -10,7 +10,7 @@ * href="https://developers.sinch.com/docs/numbers/api-reference/error-codes/provisioning-errors/">https://developers.sinch.com/docs/numbers/api-reference/error-codes/provisioning-errors/ * @since 1.0 */ -public final class SmsErrorCode extends EnumDynamic { +public final class SmsErrorCode extends EnumDynamic { public static final SmsErrorCode ERROR_CODE_UNSPECIFIED = new SmsErrorCode("ERROR_CODE_UNSPECIFIED"); public static final SmsErrorCode INTERNAL_ERROR = new SmsErrorCode("INTERNAL_ERROR"); @@ -42,7 +42,7 @@ public final class SmsErrorCode extends EnumDynamic { public static final SmsErrorCode UNKNOWN_DEFAULT_OPEN_API = new SmsErrorCode("UNKNOWN_DEFAULT_OPEN_API"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>( SmsErrorCode.class, SmsErrorCode::new, diff --git a/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java index f6b2efe6..98174434 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java @@ -1,7 +1,13 @@ package com.sinch.sdk.domains.sms; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.BaseBatch; import com.sinch.sdk.domains.sms.models.Batch; +import com.sinch.sdk.domains.sms.models.DryRun; +import com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest; +import com.sinch.sdk.domains.sms.models.responses.BatchesListResponse; +import java.util.Collection; /** * Batches Service @@ -13,11 +19,135 @@ public interface BatchesService { /** - * Get a batch message + * Get a batch message
+ * This operation returns a specific batch that matches the provided batch ID. * * @param batchId The batch ID you received from sending a message + * @param A type of Batch * @return Batch information + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/GetBatchMessage * @since 1.0 */ > T get(String batchId) throws ApiException; + + /** + * Send a message or a batch of messages
+ * Depending on the length of the body, one message might be split into multiple parts and charged + * accordingly.
+ * Any groups targeted in a scheduled batch will be evaluated at the time of sending. If a group + * is deleted between batch creation and scheduled date, it will be considered empty.
+ * Be sure to use the correct region in the server URL. + * + * @param batch The batch to be created + * @param A type of Batch + * @return Batch information + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/SendSMS + * @since 1.0 + */ + > T send(BaseBatch batch) throws ApiException; + + /** + * Dry run
+ * This operation will perform a dry run of a batch which calculates the bodies and number of + * parts for all messages in the batch without actually sending any messages. + * + * @param perRecipient Whether to include per recipient details in the response + * @param numberOfRecipient Max number of recipients to include per recipient details for in the + * response + * @param batch The batch to be send + * @return Details about dryRun execution + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/Dry_Run + * @since 1.0 + */ + DryRun dryRun(boolean perRecipient, int numberOfRecipient, BaseBatch batch) + throws ApiException; + + /** + * List Batches
+ * With the list operation you can list batch messages created in the last 14 days that you have + * created. This operation supports pagination. + * + * @param parameters Query parameters filtering returned batches + * @return Paginated list of Batches + * @since 1.0 + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/ListBatches + */ + BatchesListResponse list(BatchesListRequestParameters parameters) throws ApiException; + + /** + * Update a Batch message
+ * This operation updates all specified parameters of a batch that matches the provided batch ID. + * + * @param batchId The batch ID you received from sending a message + * @param batch Batch parameters to be updated + * @param A type of Batch + * @return Batch information + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/UpdateBatchMessage + * @since 1.0 + */ + > T update(String batchId, UpdateBaseBatchRequest batch) + throws ApiException; + + /** + * Replace a batch
+ * This operation will replace all the parameters of a batch with the provided values. It is the + * same as cancelling a batch and sending a new one instead. + * + * @param batchId The batch ID you received from sending a message + * @param batch Batch parameters to be used + * @param A type of Batch + * @return Batch information + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/ReplaceBatch + * @since 1.0 + */ + > T replace(String batchId, BaseBatch batch) throws ApiException; + + /** + * Cancel a batch message
+ * A batch can be canceled at any point. If a batch is canceled while it's currently being + * delivered some messages currently being processed might still be delivered. The delivery report + * will indicate which messages were canceled and which weren't.
+ * Canceling a batch scheduled in the future will result in an empty delivery report while + * canceling an already sent batch would result in no change to the completed delivery report. + * + * @param batchId The batch ID you received from sending a message + * @param A type of Batch + * @return Batch information + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/CancelBatchMessage + * @since 1.0 + */ + > T cancel(String batchId) throws ApiException; + + /** + * Send delivery feedback for a message + * + *

Send feedback if your system can confirm successful message delivery. + * + *

Feedback can only be provided if feedback_enabled was set when batch was submitted. + * + *

Batches: It is possible to submit feedback multiple times for the same batch for + * different recipients. Feedback without specified recipients is treated as successful message + * delivery to all recipients referenced in the batch. Note that the recipients key is still + * required even if the value is empty. + * + *

Groups: If the batch message was creating using a group ID, at least one recipient + * is required. Excluding recipients (an empty recipient list) does not work and will result in a + * failed request. + * + * @param batchId The batch ID you received from sending a message + * @param recipients A list of phone numbers (MSISDNs) that have successfully received the + * message. The key is required, however, the value can be an empty array ([]) for a batch. If + * the feedback was enabled for a group, at least one phone number is required. + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/deliveryFeedback + * @since 1.0 + */ + void sendDeliveryFeedback(String batchId, Collection recipients) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/DeliveryReportsService.java new file mode 100644 index 00000000..49c3cd36 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/DeliveryReportsService.java @@ -0,0 +1,68 @@ +package com.sinch.sdk.domains.sms; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportBatchGetRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.DeliveryReportsListResponse; + +/** + * Delivery reports Service + * + *

The REST API uses message statuses and error codes in delivery reports, which refer to the + * state of the batch and can be present in either Retrieve + * a delivery report or sent as a callback. + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports + * @since 1.0 + */ +public interface DeliveryReportsService { + + /** + * Retrieve a batch delivery report
+ * Delivery reports can be retrieved even if no callback was requested. The difference between a + * summary and a full report is only that the full report contains the phone numbers in E.164 format for each status + * code. + * + * @param batchId The batch ID you received from sending a message param type param status param + * code + * @param parameters Filtering parameters + * @return Delivery report related to batchId according to filters + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByBatchId + * @since 1.0 + */ + DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestParameters parameters) + throws ApiException; + + /** + * Retrieve a recipient delivery report
+ * A recipient delivery report contains the message status for a single recipient phone number. + * + * @param batchId The batch ID you received from sending a message param type param status param + * code + * @param recipient Phone number for which you to want to search + * @return Delivery report related to batchId according to filters + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByPhoneNumber + * @since 1.0 + */ + DeliveryReportRecipient getForNumber(String batchId, String recipient) throws ApiException; + + /** + * Get a list of finished delivery reports.
+ * This operation supports pagination. + * + * @param parameters Filtering parameters + * @return Delivery report related to batchId according to filters + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/getDeliveryReports + * @since 1.0 + */ + DeliveryReportsListResponse list(DeliveryReportListRequestParameters parameters) + throws ApiException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/GroupsService.java new file mode 100644 index 00000000..22c8d857 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/GroupsService.java @@ -0,0 +1,122 @@ +package com.sinch.sdk.domains.sms; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.requests.GroupCreateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupsListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.GroupsListResponse; +import java.util.Collection; + +/** + * Groups Service + * + *

A group is a set of phone numbers (or MSISDNs) that can be used as a target when sending an + * SMS. An phone number (MSISDN) can only occur once in a group and any attempts to add a duplicate + * are ignored but not rejected. + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups + * @since 1.0 + */ +public interface GroupsService { + + /** + * Retrieve a group + * + *

This operation retrieves a specific group with the provided group ID. + * + * @param groupId The inbound ID found when listing inbound messages + * @return Group associated to groupId + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/RetrieveGroup + * @since 1.0 + */ + Group get(String groupId) throws ApiException; + + /** + * Create a group + * + *

A group is a set of phone numbers (MSISDNs) that can be used as a target in the + * send_batch_msg operation. An MSISDN can only occur once in a group and any attempts to + * add a duplicate would be ignored but not rejected. + * + * @param parameters Parameters to be used to define group onto creation + * @return Created group + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/CreateGroup + * @since 1.0 + */ + Group create(GroupCreateRequestParameters parameters) throws ApiException; + + Group create() throws ApiException; + + /** + * List Groups + * + *

With the list operation you can list all groups that you have created. This operation + * supports pagination. + * + *

Groups are returned in reverse chronological order. + * + * @param parameters Filtering parameters + * @return group list + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ListGroups + * @since 1.0 + */ + GroupsListResponse list(GroupsListRequestParameters parameters) throws ApiException; + + GroupsListResponse list() throws ApiException; + + /** + * Replace a group + * + *

The replace operation will replace all parameters, including members, of an existing group + * with new values. + * + *

Replacing a group targeted by a batch message scheduled in the future is allowed and changes + * will be reflected when the batch is sent. + * + * @param groupId ID of a group that you are interested in getting. + * @param parameters Parameters to be replaced for group + * @return Group associated to groupId + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ReplaceGroup + * @since 1.0 + */ + Group replace(String groupId, GroupReplaceRequestParameters parameters) throws ApiException; + + /** + * Update a group + * + * @param groupId ID of a group that you are interested in getting. + * @param parameters Parameters to be used to update group + * @return Modified group associated to groupId + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/UpdateGroup + * @since 1.0 + */ + Group update(String groupId, GroupUpdateRequestParameters parameters) throws ApiException; + + /** + * Delete a group + * + * @param groupId ID of a group that you are interested in getting. + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup + * @since 1.0 + */ + void delete(String groupId) throws ApiException; + + /** + * Get phone numbers for a group + * + * @param groupId ID of a group that you are interested in getting. + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup + * @since 1.0 + */ + Collection listMembers(String groupId) throws ApiException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/InboundsService.java new file mode 100644 index 00000000..8ab75493 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/InboundsService.java @@ -0,0 +1,47 @@ +package com.sinch.sdk.domains.sms; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.Inbound; +import com.sinch.sdk.domains.sms.models.requests.InboundsListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.InboundsListResponse; + +/** + * Inbounds Service + * + *

Inbounds, or Mobile Originated (MO) messages, are incoming messages. Inbound messages can be + * listed and retrieved like batch messages and they can also be delivered by callback requests like + * delivery reports. + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Inbounds/ + * @since 1.0 + */ +public interface InboundsService { + + /** + * List incoming messages + * + *

With the list operation, you can list all inbound messages that you have received. This + * operation supports pagination. Inbounds are returned in reverse chronological order. + * + * @param parameters Filtering parameters + * @return Incoming messages + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/getDeliveryReports + * @since 1.0 + */ + InboundsListResponse list(InboundsListRequestParameters parameters) throws ApiException; + + /** + * Retrieve inbound message + * + *

This operation retrieves a specific inbound message with the provided inbound ID + * + * @param inboundId The inbound ID found when listing inbound messages + * @return Inbound messages- + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Inbounds/#tag/Inbounds/operation/RetrieveInboundMessage + * @since 1.0 + */ + Inbound get(String inboundId) throws ApiException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/SMSService.java index 2947577e..1d0da811 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/SMSService.java @@ -16,4 +16,36 @@ public interface SMSService { * @since 1.0 */ BatchesService batches(); + + /** + * WebHooksService Service instance + * + * @return service instance for project + * @since 1.0 + */ + WebHooksService webHooks(); + + /** + * Delivery Reports Service instance + * + * @return service instance for project + * @since 1.0 + */ + DeliveryReportsService deliveryReports(); + + /** + * Inbounds Service instance + * + * @return service instance for project + * @since 1.0 + */ + InboundsService inbounds(); + + /** + * Groups Service instance + * + * @return service instance for project + * @since 1.0 + */ + GroupsService groups(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/WebHooksService.java new file mode 100644 index 00000000..185ada01 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/WebHooksService.java @@ -0,0 +1,103 @@ +package com.sinch.sdk.domains.sms; + +import com.sinch.sdk.core.exceptions.ApiMappingException; +import com.sinch.sdk.domains.sms.models.BaseDeliveryReport; +import com.sinch.sdk.domains.sms.models.Inbound; + +/** + * WebHooks + * + *

Callbacks + * + *

A callback is an HTTP POST request with a notification made by the Sinch SMS REST API to a URI + * of your choosing. + * + *

The REST API expects the receiving server to respond with a response code within the 2xx + * success range. For 5xx the callback will be retried. For 429 + * the callback will be retried and the throughput will be lowered. For other status codes in the + * 4xx range the callback will not be retried. The first initial retry will happen 5 + * seconds after the first try. The next attempt is after 10 seconds, then after 20 seconds, after + * 40 seconds, after 80 seconds, doubling on every attempt. The last retry will be at 81920 seconds + * (or 22 hours 45 minutes) after the initial failed attempt. + * + *

The SMS REST API offers the following callback options which can be configured for your + * account upon request to your account manager. + * + *

    + *
  • Callback with mutual authentication over TLS (HTTPS) connection by provisioning the + * callback URL with client keystore and password. + *
  • Callback with basic authentication by provisioning the callback URL with username and + * password. + *
  • Callback with OAuth 2.0 by provisioning the callback URL with username, password and the + * URL to fetch OAuth access token. + *
  • Callback using AWS SNS by provisioning the callback URL with an Access Key ID, Secret Key + * and Region. + *
+ * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/ + * @since 1.0 + */ +public interface WebHooksService { + + /** + * Incoming SMS WebHook + * + *

An inbound message is a message sent to one of your short codes or long numbers from a + * mobile phone. To receive inbound message callbacks, a URL needs to be added to your REST API. + * This URL can be specified in your Dashboard. + * + * @param jsonPayload The incoming message to your sinch number + * @return Decoded payload + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/#tag/Webhooks/operation/incomingSMS + * @since 1.0 + */ + Inbound incomingSMS(String jsonPayload) throws ApiMappingException; + + /** + * Delivery Report WebHook + * + *

A delivery report contains the status and status code for each recipient of a batch. To get + * a delivery report callback for a message or batch of messages, set the delivery_report + * field accordingly when creating a batch. + * + *

The following is provided so you can better understand our webhooks/callbacks. Configuration + * of both webhooks and the type of delivery report requested happens when sending a batch. + * + *

Callback URL + * + *

The callback URL can either be provided for each batch or provisioned globally for your + * account in your Sinch Customer + * Dashboard. Learn how to configure a webhook/callback here + * + *

Type + * + *

The type is the type of delivery report webhook. The response will vary + * depending on the webhook delivery report you selected when the batch was sent, so choose the + * appropriate selection under "One of". + * + *

    + *
  • The delivery_report_sms and delivery_report_mms types are + * documented under Delivery report. These are reports containing either + * a full report or summary report, depending on your selection at the time the batch + * was sent. + *
  • The recipient_delivery_report_sms and recipient_delivery_report_mms + * delivery report types are documented under Recipient delivery report. + * These are delivery reports for recipient phone numbers. If you set per_recipient + * for the delivery_report parameter when sending the batch, a + * recipient report gets sent to you for each status change for each recipient in your + * batch. If you set per_recipient_final, a recipient report gets sent to you + * for the final status of each recipient in your batch. + *
+ * + * @param jsonPayload The incoming delivery report + * @return Decoded payload + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/#tag/Webhooks/operation/deliveryReport + * @since 1.0 + */ + BaseDeliveryReport deliveryReport(String jsonPayload) throws ApiMappingException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java index c021da1e..90492287 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java @@ -3,10 +3,22 @@ import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.Pair; import com.sinch.sdk.domains.sms.adapters.api.v1.BatchesApi; import com.sinch.sdk.domains.sms.adapters.converters.BatchDtoConverter; +import com.sinch.sdk.domains.sms.adapters.converters.DryRunDtoConverter; +import com.sinch.sdk.domains.sms.models.BaseBatch; import com.sinch.sdk.domains.sms.models.Batch; +import com.sinch.sdk.domains.sms.models.DryRun; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListDto; +import com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest; +import com.sinch.sdk.domains.sms.models.responses.BatchesListResponse; import com.sinch.sdk.models.Configuration; +import java.time.Instant; +import java.util.Collection; public class BatchesService implements com.sinch.sdk.domains.sms.BatchesService { @@ -28,4 +40,71 @@ public > T get(String batchId) throws ApiException { return BatchDtoConverter.convert( getApi().getBatchMessage(configuration.getProjectId(), batchId)); } + + public > T send(BaseBatch batch) throws ApiException { + return BatchDtoConverter.convert( + getApi().sendSMS(configuration.getProjectId(), BatchDtoConverter.convert(batch))); + } + + public DryRun dryRun(boolean perRecipient, int numberOfRecipient, BaseBatch batch) { + return DryRunDtoConverter.convert( + getApi() + .dryRun( + configuration.getProjectId(), + perRecipient, + numberOfRecipient, + BatchDtoConverter.convert(batch))); + } + + public BatchesListResponse list() throws ApiException { + return this.list(null); + } + + public BatchesListResponse list(BatchesListRequestParameters parameters) throws ApiException { + + BatchesListRequestParameters guardParameters = + null != parameters ? parameters : BatchesListRequestParameters.builder().build(); + + ApiBatchListDto response = + getApi() + .listBatches( + configuration.getProjectId(), + guardParameters.getPage().orElse(null), + guardParameters.getPageSize().orElse(null), + guardParameters.getFrom().orElse(null), + guardParameters.getStartDate().map(Instant::toString).orElse(null), + guardParameters.getEndDate().map(Instant::toString).orElse(null), + guardParameters.getClientReference().orElse(null)); + + Pair>, PageToken> content = BatchDtoConverter.convert(response); + + return new BatchesListResponse( + this, new Page<>(guardParameters, content.getLeft(), content.getRight())); + } + + public > T update(String batchId, UpdateBaseBatchRequest batch) + throws ApiException { + return BatchDtoConverter.convert( + getApi() + .updateBatchMessage( + configuration.getProjectId(), batchId, BatchDtoConverter.convert(batch))); + } + + public > T replace(String batchId, BaseBatch batch) throws ApiException { + return BatchDtoConverter.convert( + getApi() + .replaceBatch(configuration.getProjectId(), batchId, BatchDtoConverter.convert(batch))); + } + + public > T cancel(String batchId) throws ApiException { + return BatchDtoConverter.convert( + getApi().cancelBatchMessage(configuration.getProjectId(), batchId)); + } + + public void sendDeliveryFeedback(String batchId, Collection recipients) + throws ApiException { + getApi() + .deliveryFeedback( + configuration.getProjectId(), batchId, BatchDtoConverter.convert(recipients)); + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java new file mode 100644 index 00000000..833be282 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java @@ -0,0 +1,113 @@ +package com.sinch.sdk.domains.sms.adapters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.adapters.api.v1.DeliveryReportsApi; +import com.sinch.sdk.domains.sms.adapters.converters.DeliveryReportDtoConverter; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportListDto; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportBatchGetRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.DeliveryReportsListResponse; +import com.sinch.sdk.models.Configuration; +import java.time.Instant; +import java.util.Collection; +import java.util.stream.Collectors; + +/** + * Delivery reports Service + * + *

The REST API uses message statuses and error codes in delivery reports, which refer to the + * state of the batch and can be present in either Retrieve + * a delivery report or sent as a callback. + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports + * @since 1.0 + */ +public class DeliveryReportsService implements com.sinch.sdk.domains.sms.DeliveryReportsService { + + private Configuration configuration; + private DeliveryReportsApi api; + + public DeliveryReportsService() {} + + private DeliveryReportsApi getApi() { + return this.api; + } + + public DeliveryReportsService(Configuration configuration, HttpClient httpClient) { + this.configuration = configuration; + this.api = new DeliveryReportsApi(httpClient, configuration.getSmsServer(), new HttpMapper()); + } + + public DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestParameters parameters) + throws ApiException { + + DeliveryReportBatchGetRequestParameters guardParameters = + null != parameters ? parameters : DeliveryReportBatchGetRequestParameters.builder().build(); + + return DeliveryReportDtoConverter.convert( + getApi() + .getDeliveryReportByBatchId( + configuration.getProjectId(), + batchId, + guardParameters.getType().map(DeliveryReportType::value).orElse(null), + guardParameters + .geStatues() + .map(f -> f.stream().map(EnumDynamic::value).collect(Collectors.joining(","))) + .orElse(null), + guardParameters + .getCodes() + .map(f -> f.stream().map(Object::toString).collect(Collectors.joining(","))) + .orElse(null))); + } + + public DeliveryReportRecipient getForNumber(String batchId, String recipient) + throws ApiException { + return DeliveryReportDtoConverter.convert( + getApi().getDeliveryReportByPhoneNumber(configuration.getProjectId(), batchId, recipient)); + } + + public DeliveryReportsListResponse list() throws ApiException { + return this.list(null); + } + + public DeliveryReportsListResponse list(DeliveryReportListRequestParameters parameters) + throws ApiException { + DeliveryReportListRequestParameters guardParameters = + null != parameters ? parameters : DeliveryReportListRequestParameters.builder().build(); + + DeliveryReportListDto response = + getApi() + .getDeliveryReports( + configuration.getProjectId(), + guardParameters.getPage().orElse(null), + guardParameters.getPageSize().orElse(null), + guardParameters.getStartDate().map(Instant::toString).orElse(null), + guardParameters.getEndDate().map(Instant::toString).orElse(null), + guardParameters + .getStatuses() + .map(f -> f.stream().map(EnumDynamic::value).collect(Collectors.joining(","))) + .orElse(null), + guardParameters + .getCodes() + .map(f -> f.stream().map(Object::toString).collect(Collectors.joining(","))) + .orElse(null), + guardParameters.getClientReference().orElse(null)); + + Pair, PageToken> content = + DeliveryReportDtoConverter.convert(response); + + return new DeliveryReportsListResponse( + this, new Page<>(guardParameters, content.getLeft(), content.getRight())); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java new file mode 100644 index 00000000..b13f91c3 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java @@ -0,0 +1,109 @@ +package com.sinch.sdk.domains.sms.adapters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.adapters.api.v1.GroupsApi; +import com.sinch.sdk.domains.sms.adapters.converters.GroupsDtoConverter; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.CreateGroupResponseDto; +import com.sinch.sdk.domains.sms.models.requests.GroupCreateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupsListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.GroupsListResponse; +import com.sinch.sdk.models.Configuration; +import java.util.Collection; + +public class GroupsService implements com.sinch.sdk.domains.sms.GroupsService { + + private Configuration configuration; + private GroupsApi api; + + public GroupsService() {} + + private GroupsApi getApi() { + return this.api; + } + + public GroupsService(Configuration configuration, HttpClient httpClient) { + this.configuration = configuration; + this.api = new GroupsApi(httpClient, configuration.getSmsServer(), new HttpMapper()); + } + + public Group get(String groupId) throws ApiException { + + CreateGroupResponseDto response = getApi().retrieveGroup(configuration.getProjectId(), groupId); + return GroupsDtoConverter.convert(response); + } + + public Group create() throws ApiException { + return this.create(null); + } + + public Group create(GroupCreateRequestParameters parameters) throws ApiException { + GroupCreateRequestParameters guardParameters = + null != parameters ? parameters : GroupCreateRequestParameters.builder().build(); + + CreateGroupResponseDto response = + getApi() + .createGroup(configuration.getProjectId(), GroupsDtoConverter.convert(guardParameters)); + return GroupsDtoConverter.convert(response); + } + + public GroupsListResponse list() throws ApiException { + return this.list(null); + } + + public GroupsListResponse list(GroupsListRequestParameters parameters) throws ApiException { + GroupsListRequestParameters guardParameters = + null != parameters ? parameters : GroupsListRequestParameters.builder().build(); + + ApiGroupListDto response = + getApi() + .listGroups( + configuration.getProjectId(), + guardParameters.getPage().orElse(null), + guardParameters.getPageSize().orElse(null)); + + Pair, PageToken> content = GroupsDtoConverter.convert(response); + + return new GroupsListResponse( + this, new Page<>(guardParameters, content.getLeft(), content.getRight())); + } + + public Group replace(String groupId, GroupReplaceRequestParameters parameters) + throws ApiException { + GroupReplaceRequestParameters guardParameters = + null != parameters ? parameters : GroupReplaceRequestParameters.builder().build(); + + CreateGroupResponseDto response = + getApi() + .replaceGroup( + configuration.getProjectId(), groupId, GroupsDtoConverter.convert(guardParameters)); + return GroupsDtoConverter.convert(response); + } + + public Group update(String groupId, GroupUpdateRequestParameters parameters) throws ApiException { + GroupUpdateRequestParameters guardParameters = + null != parameters ? parameters : GroupUpdateRequestParameters.builder().build(); + + CreateGroupResponseDto response = + getApi() + .updateGroup( + configuration.getProjectId(), groupId, GroupsDtoConverter.convert(guardParameters)); + return GroupsDtoConverter.convert(response); + } + + public void delete(String groupId) throws ApiException { + getApi().deleteGroup(configuration.getProjectId(), groupId); + } + + public Collection listMembers(String groupId) throws ApiException { + return getApi().getMembers(configuration.getProjectId(), groupId); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java new file mode 100644 index 00000000..c43bde1d --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java @@ -0,0 +1,67 @@ +package com.sinch.sdk.domains.sms.adapters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.adapters.api.v1.InboundsApi; +import com.sinch.sdk.domains.sms.adapters.converters.InboundsDtoConverter; +import com.sinch.sdk.domains.sms.models.Inbound; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiInboundListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.InboundDto; +import com.sinch.sdk.domains.sms.models.requests.InboundsListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.InboundsListResponse; +import com.sinch.sdk.models.Configuration; +import java.time.Instant; +import java.util.Collection; + +public class InboundsService implements com.sinch.sdk.domains.sms.InboundsService { + + private Configuration configuration; + private InboundsApi api; + + public InboundsService() {} + + private InboundsApi getApi() { + return this.api; + } + + public InboundsService(Configuration configuration, HttpClient httpClient) { + this.configuration = configuration; + this.api = new InboundsApi(httpClient, configuration.getSmsServer(), new HttpMapper()); + } + + public InboundsListResponse list() throws ApiException { + return this.list(null); + } + + public InboundsListResponse list(InboundsListRequestParameters parameters) throws ApiException { + InboundsListRequestParameters guardParameters = + null != parameters ? parameters : InboundsListRequestParameters.builder().build(); + + ApiInboundListDto response = + getApi() + .listInboundMessages( + configuration.getProjectId(), + guardParameters.getPage().orElse(null), + guardParameters.getPageSize().orElse(null), + guardParameters.getTo().map(f -> String.join(",", f)).orElse(null), + guardParameters.getStartDate().map(Instant::toString).orElse(null), + guardParameters.getEndDate().map(Instant::toString).orElse(null), + guardParameters.getClientReference().orElse(null)); + + Pair>, PageToken> content = + InboundsDtoConverter.convert(response); + + return new InboundsListResponse( + this, new Page<>(guardParameters, content.getLeft(), content.getRight())); + } + + public Inbound get(String inboundId) throws ApiException { + + InboundDto response = getApi().retrieveInboundMessage(configuration.getProjectId(), inboundId); + return InboundsDtoConverter.convert(response); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java index fd2f3a26..bbdd773f 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java @@ -2,6 +2,9 @@ import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.domains.sms.BatchesService; +import com.sinch.sdk.domains.sms.DeliveryReportsService; +import com.sinch.sdk.domains.sms.InboundsService; +import com.sinch.sdk.domains.sms.WebHooksService; import com.sinch.sdk.models.Configuration; public class SMSService implements com.sinch.sdk.domains.sms.SMSService { @@ -9,6 +12,10 @@ public class SMSService implements com.sinch.sdk.domains.sms.SMSService { private final Configuration configuration; private final HttpClient httpClient; private BatchesService batches; + private WebHooksService webHooks; + private DeliveryReportsService deliveryReports; + private InboundsService inbounds; + private GroupsService groups; public SMSService(Configuration configuration, HttpClient httpClient) { this.configuration = configuration; @@ -23,4 +30,38 @@ public BatchesService batches() { } return this.batches; } + + @Override + public WebHooksService webHooks() { + if (null == this.webHooks) { + this.webHooks = new com.sinch.sdk.domains.sms.adapters.WebHooksService(); + } + return this.webHooks; + } + + @Override + public DeliveryReportsService deliveryReports() { + if (null == this.deliveryReports) { + this.deliveryReports = + new com.sinch.sdk.domains.sms.adapters.DeliveryReportsService(configuration, httpClient); + } + return this.deliveryReports; + } + + @Override + public InboundsService inbounds() { + if (null == this.inbounds) { + this.inbounds = + new com.sinch.sdk.domains.sms.adapters.InboundsService(configuration, httpClient); + } + return this.inbounds; + } + + @Override + public GroupsService groups() { + if (null == this.groups) { + this.groups = new com.sinch.sdk.domains.sms.adapters.GroupsService(configuration, httpClient); + } + return this.groups; + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/WebHooksService.java new file mode 100644 index 00000000..7cd2c35e --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/WebHooksService.java @@ -0,0 +1,66 @@ +package com.sinch.sdk.domains.sms.adapters; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.core.exceptions.ApiMappingException; +import com.sinch.sdk.core.utils.databind.Mapper; +import com.sinch.sdk.domains.sms.adapters.converters.DeliveryReportDtoConverter; +import com.sinch.sdk.domains.sms.adapters.converters.InboundsDtoConverter; +import com.sinch.sdk.domains.sms.models.BaseDeliveryReport; +import com.sinch.sdk.domains.sms.models.Inbound; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportDto; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportDto.TypeEnum; +import com.sinch.sdk.domains.sms.models.dto.v1.MOBinaryDto; +import com.sinch.sdk.domains.sms.models.dto.v1.MOTextDto; +import com.sinch.sdk.domains.sms.models.dto.v1.RecipientDeliveryReportDto; +import java.util.Objects; + +public class WebHooksService implements com.sinch.sdk.domains.sms.WebHooksService { + + @Override + public Inbound incomingSMS(String jsonPayload) throws ApiMappingException { + try { + MOBinaryDto binary = Mapper.getInstance().readValue(jsonPayload, MOBinaryDto.class); + if (null != binary + && (Objects.equals(binary.getType(), MOBinaryDto.TypeEnum.MO_BINARY.getValue()))) { + return InboundsDtoConverter.convert(binary); + } + MOTextDto text = Mapper.getInstance().readValue(jsonPayload, MOTextDto.class); + if (null != text && (Objects.equals(text.getType(), MOTextDto.TypeEnum.MO_TEXT.getValue()))) { + return InboundsDtoConverter.convert(text); + } + throw new ApiMappingException(jsonPayload, null); + + } catch (JsonProcessingException e) { + throw new ApiMappingException(jsonPayload, e); + } + } + + @Override + public BaseDeliveryReport deliveryReport(String jsonPayload) throws ApiMappingException { + try { + // Can we convert payload to Recipient DeliveryReport or Batch Delivery Report ? + RecipientDeliveryReportDto recipient = + Mapper.getInstance().readValue(jsonPayload, RecipientDeliveryReportDto.class); + if (null != recipient + && (Objects.equals( + recipient.getType(), RecipientDeliveryReportDto.TypeEnum.MMS.getValue()) + || Objects.equals( + recipient.getType(), RecipientDeliveryReportDto.TypeEnum.SMS.getValue()))) { + return DeliveryReportDtoConverter.convert(recipient); + } + + DeliveryReportDto batch = + Mapper.getInstance().readValue(jsonPayload, DeliveryReportDto.class); + if (null != batch + && (Objects.equals(batch.getType(), TypeEnum.MMS.getValue()) + || Objects.equals(batch.getType(), TypeEnum.SMS.getValue()))) { + return DeliveryReportDtoConverter.convert(batch); + } + + throw new ApiMappingException(jsonPayload, null); + + } catch (JsonProcessingException e) { + throw new ApiMappingException(jsonPayload, e); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java index d792241b..9f1c61d5 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java @@ -1,27 +1,57 @@ package com.sinch.sdk.domains.sms.adapters.converters; import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.domains.sms.models.*; +import com.sinch.sdk.core.models.AbstractOpenApiSchema; +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.models.BaseBatch; +import com.sinch.sdk.domains.sms.models.Batch; +import com.sinch.sdk.domains.sms.models.BatchBinary; +import com.sinch.sdk.domains.sms.models.BatchMedia; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.MediaBody; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListBatchesInnerDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiDeliveryFeedbackDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiUpdateBinaryMtMessageDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiUpdateMmsMtMessageDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiUpdateTextMtMessageDto; +import com.sinch.sdk.domains.sms.models.dto.v1.BinaryRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.BinaryResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.MediaBodyDto; +import com.sinch.sdk.domains.sms.models.dto.v1.MediaRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.MediaResponseDto; -import com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.SendSMSRequestDto; +import com.sinch.sdk.domains.sms.models.dto.v1.TextRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.TextResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateBatchMessageRequestDto; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchBinaryRequest; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchMediaRequest; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchBinaryRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchMediaRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchTextRequest; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.Collection; public class BatchDtoConverter { - public static > T convert(SendSMS201ResponseDto dto) { + public static > T convert(AbstractOpenApiSchema dto) { Object obj = dto.getActualInstance(); if (obj instanceof BinaryResponseDto) { @SuppressWarnings("unchecked") - T t = (T) convertBinary(dto.getBinaryResponseDto()); + T t = (T) convertBinary((BinaryResponseDto) obj); return t; } else if (obj instanceof MediaResponseDto) { @SuppressWarnings("unchecked") - T t = (T) convertMedia(dto.getMediaResponseDto()); + T t = (T) convertMedia((MediaResponseDto) obj); return t; } else if (obj instanceof TextResponseDto) { @SuppressWarnings("unchecked") - T t = (T) convertText(dto.getTextResponseDto()); + T t = (T) convertText((TextResponseDto) obj); return t; } else { throw new ApiException("Unexpected class:" + obj.getClass().getName()); @@ -36,11 +66,11 @@ private static BatchBinary convertBinary(BinaryResponseDto dto) { .setCanceled(dto.getCanceled()) .setBody(dto.getBody()) .setUdh(dto.getUdh()) - .setCreatedAt(dto.getCreatedAt().toInstant()) - .setModifiedAt(dto.getModifiedAt().toInstant()) - .setDeliveryReport(DeliveryReport.from(dto.getDeliveryReport())) - .setSendAt(dto.getSendAt().toInstant()) - .setExpireAt(dto.getExpireAt().toInstant()) + .setCreatedAt(null != dto.getCreatedAt() ? dto.getCreatedAt().toInstant() : null) + .setModifiedAt(null != dto.getModifiedAt() ? dto.getModifiedAt().toInstant() : null) + .setDeliveryReport(DeliveryReportType.from(dto.getDeliveryReport())) + .setSendAt(null != dto.getSendAt() ? dto.getSendAt().toInstant() : null) + .setExpireAt(null != dto.getExpireAt() ? dto.getExpireAt().toInstant() : null) .setCallbackUrl(dto.getCallbackUrl()) .setClientReference(dto.getClientReference()) .setFeedbackEnabled(dto.getFeedbackEnabled()) @@ -59,15 +89,17 @@ private static BatchMedia convertMedia(MediaResponseDto dto) { .setFrom(dto.getFrom()) .setCanceled(dto.getCanceled()) .setBody( - MediaBody.builder() - .setMessage(dto.getBody().getMessage()) - .setUrl(dto.getBody().getUrl()) - .build()) - .setCreatedAt(dto.getCreatedAt().toInstant()) - .setModifiedAt(dto.getModifiedAt().toInstant()) - .setDeliveryReport(DeliveryReport.from(dto.getDeliveryReport())) - .setSendAt(dto.getSendAt().toInstant()) - .setExpireAt(dto.getExpireAt().toInstant()) + null != dto.getBody() + ? MediaBody.builder() + .setMessage(dto.getBody().getMessage()) + .setUrl(dto.getBody().getUrl()) + .build() + : null) + .setCreatedAt(null != dto.getCreatedAt() ? dto.getCreatedAt().toInstant() : null) + .setModifiedAt(null != dto.getModifiedAt() ? dto.getModifiedAt().toInstant() : null) + .setDeliveryReport(DeliveryReportType.from(dto.getDeliveryReport())) + .setSendAt(null != dto.getSendAt() ? dto.getSendAt().toInstant() : null) + .setExpireAt(null != dto.getExpireAt() ? dto.getExpireAt().toInstant() : null) .setCallbackUrl(dto.getCallbackUrl()) .setClientReference(dto.getClientReference()) .setFeedbackEnabled(dto.getFeedbackEnabled()) @@ -82,11 +114,11 @@ private static BatchText convertText(TextResponseDto dto) { .setFrom(dto.getFrom()) .setCanceled(dto.getCanceled()) .setBody(dto.getBody()) - .setCreatedAt(dto.getCreatedAt().toInstant()) - .setModifiedAt(dto.getModifiedAt().toInstant()) - .setDeliveryReport(DeliveryReport.from(dto.getDeliveryReport())) - .setSendAt(dto.getSendAt().toInstant()) - .setExpireAt(dto.getExpireAt().toInstant()) + .setCreatedAt(null != dto.getCreatedAt() ? dto.getCreatedAt().toInstant() : null) + .setModifiedAt(null != dto.getModifiedAt() ? dto.getModifiedAt().toInstant() : null) + .setDeliveryReport(DeliveryReportType.from(dto.getDeliveryReport())) + .setSendAt(null != dto.getSendAt() ? dto.getSendAt().toInstant() : null) + .setExpireAt(null != dto.getExpireAt() ? dto.getExpireAt().toInstant() : null) .setCallbackUrl(dto.getCallbackUrl()) .setClientReference(dto.getClientReference()) .setFeedbackEnabled(dto.getFeedbackEnabled()) @@ -98,4 +130,165 @@ private static BatchText convertText(TextResponseDto dto) { .setParameters(ParametersDtoConverter.convert(dto.getParameters())) .build(); } + + public static SendSMSRequestDto convert(BaseBatch value) { + if (value instanceof SendSmsBatchBinaryRequest) { + return convert((SendSmsBatchBinaryRequest) value); + } else if (value instanceof SendSmsBatchMediaRequest) { + return convert((SendSmsBatchMediaRequest) value); + } else if (value instanceof SendSmsBatchTextRequest) { + return convert((SendSmsBatchTextRequest) value); + } else { + throw new ApiException("Unexpected class:" + value.getClass().getName()); + } + } + + public static UpdateBatchMessageRequestDto convert(UpdateBaseBatchRequest value) { + if (value instanceof UpdateSmsBatchBinaryRequest) { + return convert((UpdateSmsBatchBinaryRequest) value); + } else if (value instanceof UpdateSmsBatchMediaRequest) { + return convert((UpdateSmsBatchMediaRequest) value); + } else if (value instanceof UpdateSmsBatchTextRequest) { + return convert((UpdateSmsBatchTextRequest) value); + } else { + throw new ApiException("Unexpected class:" + value.getClass().getName()); + } + } + + private static SendSMSRequestDto convert(SendSmsBatchBinaryRequest value) { + BinaryRequestDto dto = + new BinaryRequestDto() + .type(BinaryRequestDto.TypeEnum.MT_BINARY.getValue()) + .to(new ArrayList<>(value.getTo())) + .body(value.getBody()); + value.getFrom().ifPresent(dto::from); + value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value())); + value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC))); + value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC))); + value.getCallbackUrl().ifPresent(dto::callbackUrl); + value.getClientReference().ifPresent(dto::clientReference); + value.isFeedbackEnabled().ifPresent(dto::feedbackEnabled); + value.isFlashMessage().ifPresent(dto::flashMessage); + value.isTruncateConcat().ifPresent(dto::truncateConcat); + value.getMaxNumberOfMessageParts().ifPresent(dto::maxNumberOfMessageParts); + value.getFromTon().ifPresent(dto::fromTon); + value.getFromNpi().ifPresent(dto::fromNpi); + dto.udh(value.getUdh()); + return new SendSMSRequestDto(dto); + } + + private static SendSMSRequestDto convert(SendSmsBatchMediaRequest value) { + MediaRequestDto dto = + new MediaRequestDto(MediaRequestDto.TypeEnum.MT_MEDIA.getValue()) + .to(new ArrayList<>(value.getTo())) + .body(convert(value.getBody())); + value.getFrom().ifPresent(dto::from); + value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value())); + value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC))); + value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC))); + value.getCallbackUrl().ifPresent(dto::callbackUrl); + value.getClientReference().ifPresent(dto::clientReference); + value.isFeedbackEnabled().ifPresent(dto::feedbackEnabled); + value.isStrictValidation().ifPresent(dto::strictValidation); + value.getParameters().ifPresent(f -> dto.setParameters(ParametersDtoConverter.convert(f))); + return new SendSMSRequestDto(dto); + } + + private static SendSMSRequestDto convert(SendSmsBatchTextRequest value) { + TextRequestDto dto = + new TextRequestDto() + .type(TextRequestDto.TypeEnum.MT_TEXT.getValue()) + .to(new ArrayList<>(value.getTo())) + .body(value.getBody()); + value.getFrom().ifPresent(dto::from); + value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value())); + value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC))); + value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC))); + value.getCallbackUrl().ifPresent(dto::callbackUrl); + value.getClientReference().ifPresent(dto::clientReference); + value.isFeedbackEnabled().ifPresent(dto::feedbackEnabled); + value.isFlashMessage().ifPresent(dto::flashMessage); + value.isTruncateConcat().ifPresent(dto::truncateConcat); + value.getMaxNumberOfMessageParts().ifPresent(dto::maxNumberOfMessageParts); + value.getFromTon().ifPresent(dto::fromTon); + value.getFromNpi().ifPresent(dto::fromNpi); + value.getParameters().ifPresent(f -> dto.setParameters(ParametersDtoConverter.convert(f))); + return new SendSMSRequestDto(dto); + } + + private static UpdateBatchMessageRequestDto convert(UpdateSmsBatchTextRequest value) { + ApiUpdateTextMtMessageDto dto = + new ApiUpdateTextMtMessageDto().type(ApiUpdateTextMtMessageDto.TypeEnum.MT_TEXT.getValue()); + + value.getToAdd().ifPresent(f -> dto.toAdd(new ArrayList<>(f))); + value.getToRemove().ifPresent(f -> dto.toRemove(new ArrayList<>(f))); + value.getFrom().ifPresent(dto::from); + value.getBody().ifPresent(dto::body); + value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value())); + value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC))); + value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC))); + value.getCallbackUrl().ifPresent(dto::callbackUrl); + value.getParameters().ifPresent(f -> dto.setParameters(ParametersDtoConverter.convert(f))); + return new UpdateBatchMessageRequestDto(dto); + } + + private static UpdateBatchMessageRequestDto convert(UpdateSmsBatchMediaRequest value) { + ApiUpdateMmsMtMessageDto dto = + new ApiUpdateMmsMtMessageDto().type(ApiUpdateMmsMtMessageDto.TypeEnum.MT_MEDIA.getValue()); + + value.getToAdd().ifPresent(f -> dto.toAdd(new ArrayList<>(f))); + value.getToRemove().ifPresent(f -> dto.toRemove(new ArrayList<>(f))); + value.getFrom().ifPresent(dto::from); + value.getBody().ifPresent(f -> dto.setBody(convert(f))); + value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value())); + value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC))); + value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC))); + value.getCallbackUrl().ifPresent(dto::callbackUrl); + value.getParameters().ifPresent(f -> dto.setParameters(ParametersDtoConverter.convert(f))); + value.isStrictValidation().ifPresent(dto::strictValidation); + return new UpdateBatchMessageRequestDto(dto); + } + + private static UpdateBatchMessageRequestDto convert(UpdateSmsBatchBinaryRequest value) { + ApiUpdateBinaryMtMessageDto dto = + new ApiUpdateBinaryMtMessageDto() + .type(ApiUpdateBinaryMtMessageDto.TypeEnum.MT_BINARY.getValue()); + value.getToAdd().ifPresent(f -> dto.toAdd(new ArrayList<>(f))); + value.getToRemove().ifPresent(f -> dto.toRemove(new ArrayList<>(f))); + value.getFrom().ifPresent(dto::from); + value.getBody().ifPresent(dto::setBody); + value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value())); + value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC))); + value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC))); + value.getCallbackUrl().ifPresent(dto::callbackUrl); + value.getUdh().ifPresent(dto::udh); + return new UpdateBatchMessageRequestDto(dto); + } + + private static MediaBodyDto convert(MediaBody value) { + return new MediaBodyDto().url(value.getUrl()).message(value.getMessage().orElse(null)); + } + + public static > Pair, PageToken> convert( + ApiBatchListDto dto) { + // check end of pagination limit reached: (current page number * page size ) cannot be greater + // than "count" to be able to call next page + Integer nextPageToken = + ((dto.getPage() + 1) * Long.valueOf(dto.getPageSize())) >= dto.getCount() + ? null + : dto.getPage() + 1; + Collection collection = dto.getBatches(); + Collection pageContent = new ArrayList<>(); + if (null != collection) { + for (ApiBatchListBatchesInnerDto apiBatchListBatchesInnerDto : collection) { + T convert = convert(apiBatchListBatchesInnerDto); + pageContent.add(convert); + } + } + return new Pair<>(pageContent, new PageToken<>(nextPageToken)); + } + + public static ApiDeliveryFeedbackDto convert(Collection recipients) { + return new ApiDeliveryFeedbackDto().recipients(new ArrayList<>(recipients)); + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportDtoConverter.java new file mode 100644 index 00000000..e9ab0a62 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportDtoConverter.java @@ -0,0 +1,104 @@ +package com.sinch.sdk.domains.sms.adapters.converters; + +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchMMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportErrorCode; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientEncoding; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientMMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatusDetails; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportDto; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.MessageDeliveryStatusDto; +import com.sinch.sdk.domains.sms.models.dto.v1.RecipientDeliveryReportDto; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Objects; +import java.util.stream.Collectors; + +public class DeliveryReportDtoConverter { + + public static DeliveryReportBatch convert(DeliveryReportDto dto) { + DeliveryReportBatch.Builder builder; + + if (Objects.equals(dto.getType(), DeliveryReportDto.TypeEnum.MMS.getValue())) { + builder = DeliveryReportBatchMMS.builder(); + } else if (Objects.equals(dto.getType(), DeliveryReportDto.TypeEnum.SMS.getValue())) { + builder = DeliveryReportBatchSMS.builder(); + } else { + return null; + } + + return builder + .setBatchId(dto.getBatchId()) + .setClientReference(dto.getClientReference()) + .setStatuses( + null != dto.getStatuses() + ? dto.getStatuses().stream() + .map(DeliveryReportDtoConverter::convert) + .collect(Collectors.toList()) + : null) + .setTotalMessageCount(dto.getTotalMessageCount()) + .build(); + } + + public static DeliveryReportRecipient convert(RecipientDeliveryReportDto dto) { + DeliveryReportRecipient.Builder builder; + + if (Objects.equals(dto.getType(), RecipientDeliveryReportDto.TypeEnum.MMS.getValue())) { + builder = DeliveryReportRecipientMMS.builder(); + } else if (Objects.equals(dto.getType(), RecipientDeliveryReportDto.TypeEnum.SMS.getValue())) { + builder = DeliveryReportRecipientSMS.builder(); + } else { + return null; + } + + return builder + .setBatchId(dto.getBatchId()) + .setClientReference(dto.getClientReference()) + .setAt(null != dto.getAt() ? dto.getAt().toInstant() : null) + .setCode(DeliveryReportErrorCode.from(dto.getCode())) + .setRecipient(dto.getRecipient()) + .setStatus(DeliveryReportStatus.from(dto.getStatus())) + .setAppliedOriginator(dto.getAppliedOriginator()) + .setEncoding(DeliveryReportRecipientEncoding.from(dto.getEncoding())) + .setNumberOfMessageParts(dto.getNumberOfMessageParts()) + .setOperator(dto.getOperator()) + .setOperatorStatusAt( + null != dto.getOperatorStatusAt() ? dto.getOperatorStatusAt().toInstant() : null) + .build(); + } + + public static Pair, PageToken> convert( + DeliveryReportListDto dto) { + // check end of pagination limit reached: (current page number * page size ) cannot be greater + // than "count" to be able to call next page + Integer nextPageToken = + ((dto.getPage() + 1) * Long.valueOf(dto.getPageSize())) >= dto.getCount() + ? null + : dto.getPage() + 1; + Collection collection = dto.getDeliveryReports(); + Collection pageContent = new ArrayList<>(); + if (null != collection) { + for (RecipientDeliveryReportDto innerDto : collection) { + DeliveryReportRecipient convert = convert(innerDto); + pageContent.add(convert); + } + } + return new Pair<>(pageContent, new PageToken<>(nextPageToken)); + } + + private static DeliveryReportStatusDetails convert(MessageDeliveryStatusDto dto) { + return DeliveryReportStatusDetails.builder() + .setCode(dto.getCode()) + .setCount(dto.getCount()) + .setStatus(DeliveryReportStatus.from(dto.getStatus())) + .setRecipients(dto.getRecipients()) + .build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverter.java new file mode 100644 index 00000000..16a41b34 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverter.java @@ -0,0 +1,30 @@ +package com.sinch.sdk.domains.sms.adapters.converters; + +import com.sinch.sdk.domains.sms.models.DryRun; +import com.sinch.sdk.domains.sms.models.DryRunPerRecipientDetails; +import com.sinch.sdk.domains.sms.models.dto.v1.DryRun200ResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.DryRun200ResponsePerRecipientInnerDto; +import java.util.stream.Collectors; + +public class DryRunDtoConverter { + + public static DryRun convert(DryRun200ResponseDto dto) { + return DryRun.builder() + .setNumberOfRecipients(dto.getNumberOfRecipients()) + .setNumberOfMessages(dto.getNumberOfMessages()) + .setPerRecipient( + dto.getPerRecipient().stream() + .map(DryRunDtoConverter::convert) + .collect(Collectors.toList())) + .build(); + } + + private static DryRunPerRecipientDetails convert(DryRun200ResponsePerRecipientInnerDto dto) { + return DryRunPerRecipientDetails.builder() + .setRecipient(dto.getRecipient()) + .setMessagePart(dto.getMessagePart()) + .setBody(dto.getBody()) + .setEncoding(dto.getEncoding()) + .build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverter.java new file mode 100644 index 00000000..fa8dda0d --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverter.java @@ -0,0 +1,196 @@ +package com.sinch.sdk.domains.sms.adapters.converters; + +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.DateUtil; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.GroupAutoUpdate; +import com.sinch.sdk.domains.sms.models.GroupAutoUpdateKeyword; +import com.sinch.sdk.domains.sms.models.dto.v1.AddKeywordDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupAutoUpdateDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.CreateGroupResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.GroupAutoUpdateDto; +import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectAutoUpdateDto; +import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectAutoUpdateRemoveDto; +import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectDto; +import com.sinch.sdk.domains.sms.models.dto.v1.RemoveKeywordDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ReplaceGroupRequestDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestAutoUpdateAddDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestAutoUpdateDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestAutoUpdateRemoveDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestDto; +import com.sinch.sdk.domains.sms.models.requests.GroupCreateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Set; +import java.util.stream.Collectors; + +public class GroupsDtoConverter { + + public static Group convert(CreateGroupResponseDto dto) { + return Group.builder() + .setId(dto.getId()) + .setName(dto.getName()) + .setSize(dto.getSize()) + .setCreatedAt(DateUtil.toInstant(dto.getCreatedAt())) + .setModifiedAt(DateUtil.toInstant(dto.getModifiedAt())) + .setChildGroupIds(convertChildGroups(dto.getChildGroups())) + .setAutoUpdate(convert(dto.getAutoUpdate())) + .build(); + } + + public static GroupObjectDto convert(GroupCreateRequestParameters client) { + return new GroupObjectDto() + .name(client.getName().orElse(null)) + .members(client.getMembers().map(ArrayList::new).orElse(null)) + .childGroups(client.getChildGroupIds().map(ArrayList::new).orElse(null)) + .autoUpdate(client.getAutoUpdate().map(GroupsDtoConverter::convert).orElse(null)); + } + + public static Pair, PageToken> convert(ApiGroupListDto dto) { + // check end of pagination limit reached: (current page number * page size ) cannot be greater + // than "count" to be able to call next page + Integer nextPageToken = + ((dto.getPage() + 1) * Long.valueOf(dto.getPageSize())) >= dto.getCount() + ? null + : dto.getPage() + 1; + Collection collection = dto.getGroups(); + Collection pageContent = new ArrayList<>(); + if (null != collection) { + for (ApiGroupDto innerDto : collection) { + Group convert = convert(innerDto); + pageContent.add(convert); + } + } + return new Pair<>(pageContent, new PageToken<>(nextPageToken)); + } + + public static ReplaceGroupRequestDto convert(GroupReplaceRequestParameters client) { + return new ReplaceGroupRequestDto() + .name(client.getName().orElse(null)) + .members(client.getMembers().map(ArrayList::new).orElse(null)); + } + + public static UpdateGroupRequestDto convert(GroupUpdateRequestParameters client) { + return new UpdateGroupRequestDto() + .name(client.getName().orElse(null)) + .add(client.getAdd().map(ArrayList::new).orElse(null)) + .remove(client.getRemove().map(ArrayList::new).orElse(null)) + .addFromGroup(client.getAddFromGroup().orElse(null)) + .removeFromGroup(client.getRemoveFromGroup().orElse(null)) + .autoUpdate(client.getAutoUpdate().map(GroupsDtoConverter::convertForUpdate).orElse(null)); + } + + private static Group convert(ApiGroupDto dto) { + return Group.builder() + .setId(dto.getId()) + .setName(dto.getName()) + .setSize(dto.getSize()) + .setCreatedAt(DateUtil.toInstant(dto.getCreatedAt())) + .setModifiedAt(DateUtil.toInstant(dto.getModifiedAt())) + .setChildGroupIds(convertChildGroups(dto.getChildGroups())) + .setAutoUpdate(convert(dto.getAutoUpdate())) + .build(); + } + + private static Collection convertChildGroups(Set dto) { + if (null == dto) { + return null; + } + return dto.stream().map(f -> (String) f).collect(Collectors.toList()); + } + + private static GroupAutoUpdate convert(GroupAutoUpdateDto dto) { + if (null == dto) { + return null; + } + return GroupAutoUpdate.builder() + .setTo(dto.getTo()) + .setAdd(convert(dto.getAdd())) + .setRemove(convert(dto.getRemove())) + .build(); + } + + private static GroupAutoUpdate convert(ApiGroupAutoUpdateDto dto) { + if (null == dto) { + return null; + } + return GroupAutoUpdate.builder() + .setTo(dto.getTo()) + .setAdd(convert(dto.getAdd())) + .setRemove(convert(dto.getRemove())) + .build(); + } + + private static GroupObjectAutoUpdateDto convert(GroupAutoUpdate client) { + if (null == client) { + return null; + } + return new GroupObjectAutoUpdateDto() + .to(client.getTo()) + .add(convertAdd(client.getAdd())) + .remove(convertRemove(client.getRemove())); + } + + private static UpdateGroupRequestAutoUpdateDto convertForUpdate(GroupAutoUpdate client) { + if (null == client) { + return null; + } + return new UpdateGroupRequestAutoUpdateDto() + .to(client.getTo()) + .add(convertAdd(client.getAdd())) + .remove(convertRemoveForUpdate(client.getRemove())); + } + + private static GroupAutoUpdateKeyword convert(AddKeywordDto dto) { + if (null == dto) { + return null; + } + return GroupAutoUpdateKeyword.builder() + .setFirstWord(dto.getFirstWord()) + .setSecondWord(dto.getSecondWord()) + .build(); + } + + private static UpdateGroupRequestAutoUpdateAddDto convertAdd(GroupAutoUpdateKeyword client) { + if (null == client) { + return null; + } + return new UpdateGroupRequestAutoUpdateAddDto() + .firstWord(client.getFirstWord()) + .secondWord(client.getSecondWord()); + } + + private static GroupAutoUpdateKeyword convert(RemoveKeywordDto dto) { + if (null == dto) { + return null; + } + return GroupAutoUpdateKeyword.builder() + .setFirstWord(dto.getFirstWord()) + .setSecondWord(dto.getSecondWord()) + .build(); + } + + private static GroupObjectAutoUpdateRemoveDto convertRemove(GroupAutoUpdateKeyword client) { + if (null == client) { + return null; + } + return new GroupObjectAutoUpdateRemoveDto() + .firstWord(client.getFirstWord()) + .secondWord(client.getSecondWord()); + } + + private static UpdateGroupRequestAutoUpdateRemoveDto convertRemoveForUpdate( + GroupAutoUpdateKeyword client) { + if (null == client) { + return null; + } + return new UpdateGroupRequestAutoUpdateRemoveDto() + .firstWord(client.getFirstWord()) + .secondWord(client.getSecondWord()); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/InboundsDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/InboundsDtoConverter.java new file mode 100644 index 00000000..1d162b5c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/InboundsDtoConverter.java @@ -0,0 +1,74 @@ +package com.sinch.sdk.domains.sms.adapters.converters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.models.AbstractOpenApiSchema; +import com.sinch.sdk.core.models.pagination.PageToken; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.models.Inbound; +import com.sinch.sdk.domains.sms.models.InboundBinary; +import com.sinch.sdk.domains.sms.models.InboundText; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiInboundListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.InboundDto; +import com.sinch.sdk.domains.sms.models.dto.v1.MOBinaryDto; +import com.sinch.sdk.domains.sms.models.dto.v1.MOTextDto; +import java.util.ArrayList; +import java.util.Collection; + +public class InboundsDtoConverter { + + public static Inbound convert(AbstractOpenApiSchema dto) { + Object obj = dto.getActualInstance(); + if (obj instanceof MOBinaryDto) { + return convert((MOBinaryDto) obj); + } else if (obj instanceof MOTextDto) { + return convert((MOTextDto) obj); + } else { + throw new ApiException("Unexpected class:" + obj.getClass().getName()); + } + } + + public static Pair>, PageToken> convert(ApiInboundListDto dto) { + // check end of pagination limit reached: (current page number * page size ) cannot be greater + // than "count" to be able to call next page + Integer nextPageToken = + ((dto.getPage() + 1) * Long.valueOf(dto.getPageSize())) >= dto.getCount() + ? null + : dto.getPage() + 1; + Collection collection = dto.getInbounds(); + Collection> pageContent = new ArrayList<>(); + if (null != collection) { + for (InboundDto innerDto : collection) { + Inbound convert = convert(innerDto); + pageContent.add(convert); + } + } + return new Pair<>(pageContent, new PageToken<>(nextPageToken)); + } + + public static InboundBinary convert(MOBinaryDto dto) { + return InboundBinary.builder() + .setBody(dto.getBody()) + .setFrom(dto.getFrom()) + .setId(dto.getId()) + .setReceivedAt(null != dto.getReceivedAt() ? dto.getReceivedAt().toInstant() : null) + .setTo(dto.getTo()) + .setClientReference(dto.getClientReference()) + .setOperatorId(dto.getOperatorId()) + .setSentAt(null != dto.getSentAt() ? dto.getSentAt().toInstant() : null) + .setUdh(dto.getUdh()) + .build(); + } + + public static InboundText convert(MOTextDto dto) { + return InboundText.builder() + .setBody(dto.getBody()) + .setFrom(dto.getFrom()) + .setId(dto.getId()) + .setReceivedAt(null != dto.getReceivedAt() ? dto.getReceivedAt().toInstant() : null) + .setTo(dto.getTo()) + .setClientReference(dto.getClientReference()) + .setOperatorId(dto.getOperatorId()) + .setSentAt(null != dto.getSentAt() ? dto.getSentAt().toInstant() : null) + .build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java index 1d4a2bd6..73515eff 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java @@ -4,12 +4,16 @@ import com.sinch.sdk.domains.sms.models.Parameters; import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjDto; import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjParameterKeyDto; +import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; public class ParametersDtoConverter { public static Parameters convert(ParameterObjDto dto) { + if (null == dto) { + return null; + } return new Parameters( dto.entrySet().stream() .map( @@ -43,4 +47,26 @@ public static Parameters convert(ParameterObjDto dto) { }) .collect(Collectors.toList())); } + + public static ParameterObjDto convert(Parameters parameters) { + ParameterObjDto dto = new ParameterObjDto(); + + parameters + .entrySet() + .iterator() + .forEachRemaining( + entry -> { + Map obj = new HashMap<>(); + Pair pair = entry.getValue().getValue(); + obj.put(pair.getLeft(), pair.getRight()); + entry + .getValue() + .getDefaultValue() + .ifPresent( + def -> obj.put(ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, def)); + dto.put(entry.getKey(), obj); + }); + return dto; + } + ; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/BaseBatch.java b/client/src/main/com/sinch/sdk/domains/sms/models/BaseBatch.java new file mode 100644 index 00000000..d04e3a1d --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/BaseBatch.java @@ -0,0 +1,230 @@ +package com.sinch.sdk.domains.sms.models; + +import java.time.Instant; +import java.util.Collection; +import java.util.Objects; +import java.util.Optional; + +/** + * Base class for Batch types + * + * @param Type of batch + * @since 1.0 + */ +public class BaseBatch { + + private final T body; + + private final Collection to; + + private final String from; + + private final DeliveryReportType deliveryReport; + + private final Instant sendAt; + + private final Instant expireAt; + + private final String callbackUrl; + + private final String clientReference; + + private final Boolean feedbackEnabled; + + /** + * @param to List of Phone numbers and group IDs that will receive the batch + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param clientReference The client identifier of a batch message. If set, the identifier will be + * added in the delivery report/callback of this batch + * @param feedbackEnabled If set to true, then feedback is expected after successful delivery. + */ + public BaseBatch( + Collection to, + String from, + T body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + String clientReference, + Boolean feedbackEnabled) { + Objects.requireNonNull(to); + Objects.requireNonNull(body); + this.to = to; + this.from = from; + this.body = body; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + } + + public static BatchBuilder batchBuilder() { + return new BatchBuilder<>(); + } + + public Collection getTo() { + return to; + } + + public T getBody() { + return body; + } + + public Optional getFrom() { + return Optional.ofNullable(from); + } + + public Optional getDeliveryReport() { + return Optional.ofNullable(deliveryReport); + } + + public Optional getSendAt() { + return Optional.ofNullable(sendAt); + } + + public Optional getExpireAt() { + return Optional.ofNullable(expireAt); + } + + public Optional getCallbackUrl() { + return Optional.ofNullable(callbackUrl); + } + + public Optional getClientReference() { + return Optional.ofNullable(clientReference); + } + + public Optional isFeedbackEnabled() { + return Optional.ofNullable(feedbackEnabled); + } + + @Override + public String toString() { + return "BaseBatch{" + + "body=" + + body + + ", to=" + + to + + ", from='" + + from + + '\'' + + ", deliveryReportType=" + + deliveryReport + + ", sendAt=" + + sendAt + + ", expireAt=" + + expireAt + + ", callbackUrl='" + + callbackUrl + + '\'' + + ", clientReference='" + + clientReference + + '\'' + + ", feedbackEnabled=" + + feedbackEnabled + + '}'; + } + + protected static class Builder> { + + public Collection to; + + public String from; + + public T body; + + public DeliveryReportType deliveryReport; + + public Instant sendAt; + + public Instant expireAt; + + public String callbackUrl; + + public String clientReference; + + public Boolean feedbackEnabled; + + public B setTo(Collection to) { + this.to = to; + return self(); + } + + public B setFrom(String from) { + this.from = from; + return self(); + } + + public B setBody(T body) { + this.body = body; + return self(); + } + + public B setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = deliveryReport; + return self(); + } + + public B setSendAt(Instant sendAt) { + this.sendAt = sendAt; + return self(); + } + + public B setExpireAt(Instant expireAt) { + this.expireAt = expireAt; + return self(); + } + + public B setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + return self(); + } + + public B setClientReference(String clientReference) { + this.clientReference = clientReference; + return self(); + } + + public B setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = feedbackEnabled; + return self(); + } + + public BaseBatch build() { + return new BaseBatch<>( + to, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + } + + public static class BatchBuilder extends BaseBatch.Builder> { + @Override + protected BatchBuilder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/BaseDeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/BaseDeliveryReport.java new file mode 100644 index 00000000..2b426013 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/BaseDeliveryReport.java @@ -0,0 +1,66 @@ +package com.sinch.sdk.domains.sms.models; + +import java.util.Objects; +import java.util.Optional; + +/** + * Base class for Delivery Report WebHook + * + * @since 1.0 + */ +public abstract class BaseDeliveryReport { + + private final String batchId; + private final String clientReference; + + /** + * @param batchId Required. The ID of the batch this delivery report belongs to. + * @param clientReference The client identifier of the batch this delivery report belongs to, if + * set when submitting batch. + */ + public BaseDeliveryReport(String batchId, String clientReference) { + Objects.requireNonNull(batchId); + this.batchId = batchId; + this.clientReference = clientReference; + } + + public String getBatchId() { + return batchId; + } + + public Optional getClientReference() { + return Optional.ofNullable(clientReference); + } + + @Override + public String toString() { + return "BaseDeliveryReport{" + + "batchId='" + + batchId + + '\'' + + ", clientReference='" + + clientReference + + '\'' + + '}'; + } + + public abstract static class Builder> { + protected String batchId; + protected String clientReference; + + public B setBatchId(String batchId) { + this.batchId = batchId; + return self(); + } + + public B setClientReference(String clientReference) { + this.clientReference = clientReference; + return self(); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/Batch.java b/client/src/main/com/sinch/sdk/domains/sms/models/Batch.java index 9161adef..5d3d3165 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/Batch.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/Batch.java @@ -17,7 +17,7 @@ public class Batch { private final String from; - private final boolean canceled; + private final Boolean canceled; private final T body; @@ -25,7 +25,7 @@ public class Batch { private final Instant modifiedAt; - private final DeliveryReport deliveryReport; + private final DeliveryReportType deliveryReport; private final Instant sendAt; @@ -35,7 +35,7 @@ public class Batch { private final String clientReference; - private final boolean feedbackEnabled; + private final Boolean feedbackEnabled; /** * @param id Unique identifier for batch @@ -61,16 +61,16 @@ public Batch( String id, Collection to, String from, - boolean canceled, + Boolean canceled, T body, Instant createdAt, Instant modifiedAt, - DeliveryReport deliveryReport, + DeliveryReportType deliveryReport, Instant sendAt, Instant expireAt, String callbackUrl, String clientReference, - boolean feedbackEnabled) { + Boolean feedbackEnabled) { this.id = id; this.to = to; this.from = from; @@ -102,7 +102,7 @@ public String getFrom() { return from; } - public boolean isCanceled() { + public Boolean isCanceled() { return canceled; } @@ -118,7 +118,7 @@ public Instant getModifiedAt() { return modifiedAt; } - public DeliveryReport getDeliveryReport() { + public DeliveryReportType getDeliveryReport() { return deliveryReport; } @@ -138,7 +138,7 @@ public String getClientReference() { return clientReference; } - public boolean isFeedbackEnabled() { + public Boolean isFeedbackEnabled() { return feedbackEnabled; } @@ -161,7 +161,7 @@ public String toString() { + createdAt + ", modifiedAt=" + modifiedAt - + ", deliveryReport=" + + ", deliveryReportType=" + deliveryReport + ", sendAt=" + sendAt @@ -186,7 +186,7 @@ protected static class Builder> { String from; - boolean canceled; + Boolean canceled; T body; @@ -194,7 +194,7 @@ protected static class Builder> { Instant modifiedAt; - DeliveryReport deliveryReport; + DeliveryReportType deliveryReport; Instant sendAt; @@ -204,7 +204,7 @@ protected static class Builder> { String clientReference; - boolean feedbackEnabled; + Boolean feedbackEnabled; public B setId(String id) { this.id = id; @@ -221,7 +221,7 @@ public B setFrom(String from) { return self(); } - public B setCanceled(boolean canceled) { + public B setCanceled(Boolean canceled) { this.canceled = canceled; return self(); } @@ -241,7 +241,7 @@ public B setModifiedAt(Instant modifiedAt) { return self(); } - public B setDeliveryReport(DeliveryReport deliveryReport) { + public B setDeliveryReport(DeliveryReportType deliveryReport) { this.deliveryReport = deliveryReport; return self(); } @@ -266,7 +266,7 @@ public B setClientReference(String clientReference) { return self(); } - public B setFeedbackEnabled(boolean feedbackEnabled) { + public B setFeedbackEnabled(Boolean feedbackEnabled) { this.feedbackEnabled = feedbackEnabled; return self(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/BatchBinary.java b/client/src/main/com/sinch/sdk/domains/sms/models/BatchBinary.java index 650da72d..5d9a989e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/BatchBinary.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/BatchBinary.java @@ -9,11 +9,11 @@ * @since 1.0 */ public class BatchBinary extends Batch { - private final boolean flashMessage; - private final boolean truncateConcat; - private final int maxNumberOfMessageParts; - private final int fromTon; - private final int fromNpi; + private final Boolean flashMessage; + private final Boolean truncateConcat; + private final Integer maxNumberOfMessageParts; + private final Integer fromTon; + private final Integer fromNpi; private final String udh; /** @@ -46,21 +46,21 @@ public BatchBinary( String id, Collection to, String from, - boolean canceled, + Boolean canceled, String body, Instant createdAt, Instant modifiedAt, - DeliveryReport deliveryReport, + DeliveryReportType deliveryReport, Instant sendAt, Instant expireAt, String callbackUrl, String clientReference, - boolean feedbackEnabled, - boolean flashMessage, - boolean truncateConcat, - int maxNumberOfMessageParts, - int fromTon, - int fromNpi, + Boolean feedbackEnabled, + Boolean flashMessage, + Boolean truncateConcat, + Integer maxNumberOfMessageParts, + Integer fromTon, + Integer fromNpi, String udh) { super( id, @@ -84,23 +84,23 @@ public BatchBinary( this.udh = udh; } - public boolean isFlashMessage() { + public Boolean isFlashMessage() { return flashMessage; } - public boolean isTruncateConcat() { + public Boolean isTruncateConcat() { return truncateConcat; } - public int getMaxNumberOfMessageParts() { + public Integer getMaxNumberOfMessageParts() { return maxNumberOfMessageParts; } - public int getFromTon() { + public Integer getFromTon() { return fromTon; } - public int getFromNpi() { + public Integer getFromNpi() { return fromNpi; } @@ -134,36 +134,36 @@ public String toString() { public static class Builder extends Batch.Builder { - private boolean flashMessage; - private boolean truncateConcat; - private int maxNumberOfMessageParts; - private int fromTon; - private int fromNpi; + private Boolean flashMessage; + private Boolean truncateConcat; + private Integer maxNumberOfMessageParts; + private Integer fromTon; + private Integer fromNpi; private String udh; private Builder() {} - public Builder setFlashMessage(boolean flashMessage) { + public Builder setFlashMessage(Boolean flashMessage) { this.flashMessage = flashMessage; return this; } - public Builder setTruncateConcat(boolean truncateConcat) { + public Builder setTruncateConcat(Boolean truncateConcat) { this.truncateConcat = truncateConcat; return this; } - public Builder setMaxNumberOfMessageParts(int maxNumberOfMessageParts) { + public Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts) { this.maxNumberOfMessageParts = maxNumberOfMessageParts; return this; } - public Builder setFromTon(int fromTon) { + public Builder setFromTon(Integer fromTon) { this.fromTon = fromTon; return this; } - public Builder setFromNpi(int fromNpi) { + public Builder setFromNpi(Integer fromNpi) { this.fromNpi = fromNpi; return this; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/BatchMedia.java b/client/src/main/com/sinch/sdk/domains/sms/models/BatchMedia.java index 75a02496..f893963e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/BatchMedia.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/BatchMedia.java @@ -10,7 +10,7 @@ */ public class BatchMedia extends Batch { private final Parameters parameters; - private final boolean strictValidation; + private final Boolean strictValidation; /** * @param id Unique identifier for batch @@ -42,18 +42,18 @@ public BatchMedia( String id, Collection to, String from, - boolean canceled, + Boolean canceled, MediaBody body, Instant createdAt, Instant modifiedAt, - DeliveryReport deliveryReport, + DeliveryReportType deliveryReport, Instant sendAt, Instant expireAt, String callbackUrl, String clientReference, - boolean feedbackEnabled, + Boolean feedbackEnabled, Parameters parameters, - boolean strictValidation) { + Boolean strictValidation) { super( id, to, @@ -76,7 +76,7 @@ public Parameters getParameters() { return parameters; } - public boolean isStrictValidation() { + public Boolean isStrictValidation() { return strictValidation; } @@ -97,7 +97,7 @@ public String toString() { public static class Builder extends Batch.Builder { private Parameters parameters; - private boolean strictValidation; + private Boolean strictValidation; private Builder() {} @@ -106,7 +106,7 @@ public Builder setParameters(Parameters parameters) { return this; } - public Builder setStrictValidation(boolean strictValidation) { + public Builder setStrictValidation(Boolean strictValidation) { this.strictValidation = strictValidation; return this; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/BatchText.java b/client/src/main/com/sinch/sdk/domains/sms/models/BatchText.java index 164a7366..f79c8b08 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/BatchText.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/BatchText.java @@ -9,12 +9,12 @@ * @since 1.0 */ public class BatchText extends Batch { - private final boolean flashMessage; + private final Boolean flashMessage; private final Parameters parameters; - private final boolean truncateConcat; - private final int maxNumberOfMessageParts; - private final int fromTon; - private final int fromNpi; + private final Boolean truncateConcat; + private final Integer maxNumberOfMessageParts; + private final Integer fromTon; + private final Integer fromNpi; /** * @param id Unique identifier for batch @@ -47,22 +47,22 @@ public BatchText( String id, Collection to, String from, - boolean canceled, + Boolean canceled, String body, Instant createdAt, Instant modifiedAt, - DeliveryReport deliveryReport, + DeliveryReportType deliveryReport, Instant sendAt, Instant expireAt, String callbackUrl, String clientReference, - boolean flashMessage, - boolean feedbackEnabled, + Boolean flashMessage, + Boolean feedbackEnabled, Parameters parameters, - boolean truncateConcat, - int maxNumberOfMessageParts, - int fromTon, - int fromNpi) { + Boolean truncateConcat, + Integer maxNumberOfMessageParts, + Integer fromTon, + Integer fromNpi) { super( id, to, @@ -89,23 +89,23 @@ public Parameters getParameters() { return parameters; } - public boolean isFlashMessage() { + public Boolean isFlashMessage() { return flashMessage; } - public boolean isTruncateConcat() { + public Boolean isTruncateConcat() { return truncateConcat; } - public int getMaxNumberOfMessageParts() { + public Integer getMaxNumberOfMessageParts() { return maxNumberOfMessageParts; } - public int getFromTon() { + public Integer getFromTon() { return fromTon; } - public int getFromNpi() { + public Integer getFromNpi() { return fromNpi; } @@ -133,16 +133,16 @@ public static Builder builder() { } public static class Builder extends Batch.Builder { - private boolean flashMessage; + private Boolean flashMessage; private Parameters parameters; - private boolean truncateConcat; - private int maxNumberOfMessageParts; - private int fromTon; - private int fromNpi; + private Boolean truncateConcat; + private Integer maxNumberOfMessageParts; + private Integer fromTon; + private Integer fromNpi; private Builder() {} - public Builder setFlashMessage(boolean flashMessage) { + public Builder setFlashMessage(Boolean flashMessage) { this.flashMessage = flashMessage; return this; } @@ -152,22 +152,22 @@ public Builder setParameters(Parameters parameters) { return this; } - public Builder setTruncateConcat(boolean truncateConcat) { + public Builder setTruncateConcat(Boolean truncateConcat) { this.truncateConcat = truncateConcat; return this; } - public Builder setMaxNumberOfMessageParts(int maxNumberOfMessageParts) { + public Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts) { this.maxNumberOfMessageParts = maxNumberOfMessageParts; return this; } - public Builder setFromTon(int fromTon) { + public Builder setFromTon(Integer fromTon) { this.fromTon = fromTon; return this; } - public Builder setFromNpi(int fromNpi) { + public Builder setFromNpi(Integer fromNpi) { this.fromNpi = fromNpi; return this; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatch.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatch.java new file mode 100644 index 00000000..8496c3c8 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatch.java @@ -0,0 +1,76 @@ +package com.sinch.sdk.domains.sms.models; + +import java.util.Collection; +import java.util.Objects; + +/** + * Common Definition to Delivery Report + * + * @since 1.0 + */ +public abstract class DeliveryReportBatch extends BaseDeliveryReport { + + private final Collection statuses; + private final Integer totalMessageCount; + + /** + * @param batchId Required. The ID of the batch this delivery report belongs to. + * @param clientReference The client identifier of the batch this delivery report belongs to, if + * set when submitting batch. + * @param statuses Required. Array with status objects. Only status codes with at + * least one recipient will be listed. + * @param totalMessageCount Required. The total number of messages in the batch. + */ + public DeliveryReportBatch( + String batchId, + String clientReference, + Collection statuses, + Integer totalMessageCount) { + super(batchId, clientReference); + Objects.requireNonNull(statuses); + Objects.requireNonNull(totalMessageCount); + this.statuses = statuses; + this.totalMessageCount = totalMessageCount; + } + + public Collection getStatuses() { + return statuses; + } + + public Integer getTotalMessageCount() { + return totalMessageCount; + } + + @Override + public String toString() { + return "DeliveryReportBatch{" + + "statuses=" + + statuses + + ", totalMessageCount=" + + totalMessageCount + + "} " + + super.toString(); + } + + public abstract static class Builder> extends BaseDeliveryReport.Builder { + protected Collection statuses; + protected Integer totalMessageCount; + + public B setStatuses(Collection statuses) { + this.statuses = statuses; + return self(); + } + + public B setTotalMessageCount(Integer totalMessageCount) { + this.totalMessageCount = totalMessageCount; + return self(); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + + public abstract DeliveryReportBatch build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatchMMS.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatchMMS.java new file mode 100644 index 00000000..291c0b57 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatchMMS.java @@ -0,0 +1,47 @@ +package com.sinch.sdk.domains.sms.models; + +import java.util.Collection; + +/** + * MMS delivery Report + * + * @since 1.0 + */ +public class DeliveryReportBatchMMS extends DeliveryReportBatch { + + /** + * @param batchId Required. The ID of the batch this delivery report belongs to. + * @param clientReference The client identifier of the batch this delivery report belongs to, if + * set when submitting batch. + * @param statuses Required. Array with status objects. Only status codes with at + * least one recipient will be listed. + * @param totalMessageCount Required. The total number of messages in the batch. + */ + public DeliveryReportBatchMMS( + String batchId, + String clientReference, + Collection statuses, + Integer totalMessageCount) { + super(batchId, clientReference, statuses, totalMessageCount); + } + + @Override + public String toString() { + return "DeliveryReportBatchMMS{} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends DeliveryReportBatch.Builder { + + protected Builder() { + super(); + } + + public DeliveryReportBatchMMS build() { + return new DeliveryReportBatchMMS(batchId, clientReference, statuses, totalMessageCount); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatchSMS.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatchSMS.java new file mode 100644 index 00000000..2c78e779 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportBatchSMS.java @@ -0,0 +1,47 @@ +package com.sinch.sdk.domains.sms.models; + +import java.util.Collection; + +/** + * SMS delivery Report + * + * @since 1.0 + */ +public class DeliveryReportBatchSMS extends DeliveryReportBatch { + + /** + * @param batchId Required. The ID of the batch this delivery report belongs to. + * @param clientReference The client identifier of the batch this delivery report belongs to, if + * set when submitting batch. + * @param statuses Required. Array with status objects. Only status codes with at + * least one recipient will be listed. + * @param totalMessageCount Required. The total number of messages in the batch. + */ + public DeliveryReportBatchSMS( + String batchId, + String clientReference, + Collection statuses, + Integer totalMessageCount) { + super(batchId, clientReference, statuses, totalMessageCount); + } + + @Override + public String toString() { + return "DeliveryReportBatchSMS{} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends DeliveryReportBatch.Builder { + + private Builder() { + super(); + } + + public DeliveryReportBatchSMS build() { + return new DeliveryReportBatchSMS(batchId, clientReference, statuses, totalMessageCount); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportErrorCode.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportErrorCode.java new file mode 100644 index 00000000..5dda5cab --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportErrorCode.java @@ -0,0 +1,126 @@ +package com.sinch.sdk.domains.sms.models; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * Applied encoding for message. + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/deliveryReport!path=1/encoding&t=request + * @since 1.0 + */ +public class DeliveryReportErrorCode extends EnumDynamic { + + /** + * Message is queued within REST API system and will be dispatched according to the rate of the + * account. + */ + public static final DeliveryReportErrorCode QUEUED = new DeliveryReportErrorCode(400); + /** Message has been dispatched to SMSC. */ + public static final DeliveryReportErrorCode DISPATCHED = new DeliveryReportErrorCode(401); + /** SMSC rejected message. Retrying is likely to cause the same error. */ + /** */ + public static final DeliveryReportErrorCode MESSAGE_UNROUTABLE = new DeliveryReportErrorCode(402); + /** An unexpected error caused the message to fail. */ + public static final DeliveryReportErrorCode INTERNAL_ERROR = new DeliveryReportErrorCode(403); + /** Message failed because of temporary delivery failure. Message can be retried. */ + public static final DeliveryReportErrorCode TEMPORARY_DELIVERY_FAILURE = + new DeliveryReportErrorCode(404); + /** + * One or more parameters in the message body has no mapping for this recipient. See Message + * Parameterization + */ + public static final DeliveryReportErrorCode UNMATCHED_PARAMETER = + new DeliveryReportErrorCode(405); + /** + * Message was expired before reaching SMSC. This may happen if the expiry time for the message + * was very short. + */ + public static final DeliveryReportErrorCode INTERNAL_EXPIRY = new DeliveryReportErrorCode(406); + /** Message was cancelled by user before reaching SMSC. */ + public static final DeliveryReportErrorCode CANCELLED = new DeliveryReportErrorCode(407); + /** SMSC rejected the message. Retrying is likely to cause the same error. */ + public static final DeliveryReportErrorCode INTERNAL_REJECT = new DeliveryReportErrorCode(408); + /** + * No default originator exists/configured for this recipient when sending message without + * originator. + */ + public static final DeliveryReportErrorCode UNMATCHED_DEFAULT_ORIGINATOR = + new DeliveryReportErrorCode(410); + /** + * Message failed as the number of message parts exceeds the defined max number of message parts. + */ + public static final DeliveryReportErrorCode EXCEEDED_PARTS_LIMIT = + new DeliveryReportErrorCode(411); + /** SMSC rejected the message. The account hasn't been provisioned for this region. */ + public static final DeliveryReportErrorCode UNPROVISIONED_REGION = + new DeliveryReportErrorCode(412); + /** The account is blocked. Reach out to support for help. Potentially out of credits. */ + public static final DeliveryReportErrorCode BLOCKED = new DeliveryReportErrorCode(413); + /** + * MMS only, the request failed due to a bad media URL. It is possible that the URL was + * unreachable, or sent a bad response. + */ + public static final DeliveryReportErrorCode BAD_MEDIA = new DeliveryReportErrorCode(414); + /** MMS only, message reached MMSC but was rejected by MMS gateway or mobile network. */ + public static final DeliveryReportErrorCode DELIVERY_REPORT_REJECTED = + new DeliveryReportErrorCode(415); + /** MMS only, message reached MMSC but it is not supported. */ + public static final DeliveryReportErrorCode DELIVERY_REPORT_NOT_SUPPORTED = + new DeliveryReportErrorCode(416); + /** + * MMS only, message reached MMSC but the destination network or the mobile subscriber cannot be + * reached. + */ + public static final DeliveryReportErrorCode DELIVERY_REPORT_UNREACHABLE = + new DeliveryReportErrorCode(417); + /** + * MMS only, message reached MMSC but the handset of the mobile subscriber does not recognize the + * message content. + */ + public static final DeliveryReportErrorCode DELIVERY_REPORT_UNRECOGNIZED = + new DeliveryReportErrorCode(418); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + DeliveryReportErrorCode.class, + DeliveryReportErrorCode::new, + Arrays.asList( + QUEUED, + DISPATCHED, + MESSAGE_UNROUTABLE, + INTERNAL_ERROR, + TEMPORARY_DELIVERY_FAILURE, + UNMATCHED_PARAMETER, + INTERNAL_EXPIRY, + CANCELLED, + INTERNAL_REJECT, + UNMATCHED_DEFAULT_ORIGINATOR, + EXCEEDED_PARTS_LIMIT, + UNPROVISIONED_REGION, + BLOCKED, + BAD_MEDIA, + DELIVERY_REPORT_REJECTED, + DELIVERY_REPORT_NOT_SUPPORTED, + DELIVERY_REPORT_UNREACHABLE, + DELIVERY_REPORT_UNRECOGNIZED)); + + private DeliveryReportErrorCode(Integer value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static DeliveryReportErrorCode from(Integer value) { + return ENUM_SUPPORT.from(value); + } + + public static Integer valueOf(DeliveryReportErrorCode e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipient.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipient.java new file mode 100644 index 00000000..16cd5199 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipient.java @@ -0,0 +1,197 @@ +package com.sinch.sdk.domains.sms.models; + +import java.time.Instant; +import java.util.Optional; + +/** + * Common Definition to Delivery Report + * + * @since 1.0 + */ +public abstract class DeliveryReportRecipient extends BaseDeliveryReport { + + private final Instant at; + private final DeliveryReportErrorCode code; + private final String recipient; + private final DeliveryReportStatus status; + private final String appliedOriginator; + private final DeliveryReportRecipientEncoding encoding; + private final Integer numberOfMessageParts; + private final String operator; + private final Instant operatorStatusAt; + + /** + * Recipient Delivery Report Recipient + * + * @param batchId Required. The ID of the batch this delivery report belongs to. + * @param clientReference The client identifier of the batch this delivery report belongs to, if + * set when submitting batch. + * @param at Required. A timestamp of when the Delivery Report was created in the + * Sinch service + * @param code Required. The detailed status + * code. + * @param recipient Required. Phone number that was queried. + * @param status Required. The simplified status as described in Delivery Report + * Statuses + * @param appliedOriginator The default originator used for the recipient this delivery report + * belongs to, if default originator pool configured and no originator set when submitting + * batch. + * @param encoding Applied encoding for message. Present only if smart encoding is enabled. + * @param numberOfMessageParts The number of parts the message was split into. Present only if + * max_number_of_message_parts parameter was set. + * @param operator The operator that was used for delivering the message to this recipient, if + * enabled on the account by Sinch. + * @param operatorStatusAt A timestamp extracted from the Delivery Receipt from the originating + * SMSC + */ + public DeliveryReportRecipient( + String batchId, + String clientReference, + Instant at, + DeliveryReportErrorCode code, + String recipient, + DeliveryReportStatus status, + String appliedOriginator, + DeliveryReportRecipientEncoding encoding, + Integer numberOfMessageParts, + String operator, + Instant operatorStatusAt) { + super(batchId, clientReference); + this.at = at; + this.code = code; + this.recipient = recipient; + this.status = status; + this.appliedOriginator = appliedOriginator; + this.encoding = encoding; + this.numberOfMessageParts = numberOfMessageParts; + this.operator = operator; + this.operatorStatusAt = operatorStatusAt; + } + + public Instant getAt() { + return at; + } + + public DeliveryReportErrorCode getCode() { + return code; + } + + public String getRecipient() { + return recipient; + } + + public DeliveryReportStatus getStatus() { + return status; + } + + public Optional getAppliedOriginator() { + return Optional.ofNullable(appliedOriginator); + } + + public Optional getEncoding() { + return Optional.ofNullable(encoding); + } + + public Optional getNumberOfMessageParts() { + return Optional.ofNullable(numberOfMessageParts); + } + + public Optional getOperator() { + return Optional.ofNullable(operator); + } + + public Optional getOperatorStatusAt() { + return Optional.ofNullable(operatorStatusAt); + } + + @Override + public String toString() { + return "DeliveryReportRecipient{" + + "at=" + + at + + ", code='" + + code + + '\'' + + ", recipient='" + + recipient + + '\'' + + ", status=" + + status + + ", appliedOriginator='" + + appliedOriginator + + '\'' + + ", encoding='" + + encoding + + '\'' + + ", numberOfMessageParts=" + + numberOfMessageParts + + ", operator='" + + operator + + '\'' + + ", operatorStatusAt=" + + operatorStatusAt + + "} " + + super.toString(); + } + + public abstract static class Builder> extends BaseDeliveryReport.Builder { + + protected Instant at; + protected DeliveryReportErrorCode code; + protected String recipient; + protected DeliveryReportStatus status; + protected String appliedOriginator; + protected DeliveryReportRecipientEncoding encoding; + protected Integer numberOfMessageParts; + protected String operator; + protected Instant operatorStatusAt; + + public Builder setAt(Instant at) { + this.at = at; + return this; + } + + public Builder setCode(DeliveryReportErrorCode code) { + this.code = code; + return this; + } + + public Builder setRecipient(String recipient) { + this.recipient = recipient; + return this; + } + + public Builder setStatus(DeliveryReportStatus status) { + this.status = status; + return this; + } + + public Builder setAppliedOriginator(String appliedOriginator) { + this.appliedOriginator = appliedOriginator; + return this; + } + + public Builder setEncoding(DeliveryReportRecipientEncoding encoding) { + this.encoding = encoding; + return this; + } + + public Builder setNumberOfMessageParts(Integer numberOfMessageParts) { + this.numberOfMessageParts = numberOfMessageParts; + return this; + } + + public Builder setOperator(String operator) { + this.operator = operator; + return this; + } + + public Builder setOperatorStatusAt(Instant operatorStatusAt) { + this.operatorStatusAt = operatorStatusAt; + return this; + } + + public abstract DeliveryReportRecipient build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientEncoding.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientEncoding.java new file mode 100644 index 00000000..2726159b --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientEncoding.java @@ -0,0 +1,44 @@ +package com.sinch.sdk.domains.sms.models; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * Applied encoding for message. + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/deliveryReport!path=1/encoding&t=request + * @since 1.0 + */ +public class DeliveryReportRecipientEncoding + extends EnumDynamic { + + public static final DeliveryReportRecipientEncoding GSM = + new DeliveryReportRecipientEncoding("GSM"); + public static final DeliveryReportRecipientEncoding UNICODE = + new DeliveryReportRecipientEncoding("UNICODE"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + DeliveryReportRecipientEncoding.class, + DeliveryReportRecipientEncoding::new, + Arrays.asList(GSM, UNICODE)); + + private DeliveryReportRecipientEncoding(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static DeliveryReportRecipientEncoding from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(DeliveryReportRecipientEncoding e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientMMS.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientMMS.java new file mode 100644 index 00000000..dc80daa7 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientMMS.java @@ -0,0 +1,93 @@ +package com.sinch.sdk.domains.sms.models; + +import java.time.Instant; + +/** + * SMS Delivery Report Recipient for MMS + * + * @since 1.0 + */ +public class DeliveryReportRecipientMMS extends DeliveryReportRecipient { + + /** + * Recipient Delivery Report for MMS + * + * @param batchId Required. The ID of the batch this delivery report belongs to. + * @param clientReference The client identifier of the batch this delivery report belongs to, if + * set when submitting batch. + * @param at Required. A timestamp of when the Delivery Report was created in the + * Sinch service + * @param code Required. The detailed status + * code. + * @param recipient Required. Phone number that was queried. + * @param status Required. The simplified status as described in Delivery Report + * Statuses + * @param appliedOriginator The default originator used for the recipient this delivery report + * belongs to, if default originator pool configured and no originator set when submitting + * batch. + * @param encoding Applied encoding for message. Present only if smart encoding is enabled. + * @param numberOfMessageParts The number of parts the message was split into. Present only if + * max_number_of_message_parts parameter was set. + * @param operator The operator that was used for delivering the message to this recipient, if + * enabled on the account by Sinch. + * @param operatorStatusAt A timestamp extracted from the Delivery Receipt from the originating + * SMSC + */ + public DeliveryReportRecipientMMS( + String batchId, + String clientReference, + Instant at, + DeliveryReportErrorCode code, + String recipient, + DeliveryReportStatus status, + String appliedOriginator, + DeliveryReportRecipientEncoding encoding, + Integer numberOfMessageParts, + String operator, + Instant operatorStatusAt) { + super( + batchId, + clientReference, + at, + code, + recipient, + status, + appliedOriginator, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt); + } + + @Override + public String toString() { + return "DeliveryReportRecipientMMS{} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends DeliveryReportRecipient.Builder { + + protected Builder() { + super(); + } + + public DeliveryReportRecipientMMS build() { + return new DeliveryReportRecipientMMS( + batchId, + clientReference, + at, + code, + recipient, + status, + appliedOriginator, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientSMS.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientSMS.java new file mode 100644 index 00000000..e32a1fd4 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportRecipientSMS.java @@ -0,0 +1,93 @@ +package com.sinch.sdk.domains.sms.models; + +import java.time.Instant; + +/** + * SMS Delivery Report Recipient for SMS + * + * @since 1.0 + */ +public class DeliveryReportRecipientSMS extends DeliveryReportRecipient { + + /** + * Recipient Delivery Report for SMS + * + * @param batchId Required. The ID of the batch this delivery report belongs to. + * @param clientReference The client identifier of the batch this delivery report belongs to, if + * set when submitting batch. + * @param at Required. A timestamp of when the Delivery Report was created in the + * Sinch service + * @param code Required. The detailed status + * code. + * @param recipient Required. Phone number that was queried. + * @param status Required. The simplified status as described in Delivery Report + * Statuses + * @param appliedOriginator The default originator used for the recipient this delivery report + * belongs to, if default originator pool configured and no originator set when submitting + * batch. + * @param encoding Applied encoding for message. Present only if smart encoding is enabled. + * @param numberOfMessageParts The number of parts the message was split into. Present only if + * max_number_of_message_parts parameter was set. + * @param operator The operator that was used for delivering the message to this recipient, if + * enabled on the account by Sinch. + * @param operatorStatusAt A timestamp extracted from the Delivery Receipt from the originating + * SMSC + */ + public DeliveryReportRecipientSMS( + String batchId, + String clientReference, + Instant at, + DeliveryReportErrorCode code, + String recipient, + DeliveryReportStatus status, + String appliedOriginator, + DeliveryReportRecipientEncoding encoding, + Integer numberOfMessageParts, + String operator, + Instant operatorStatusAt) { + super( + batchId, + clientReference, + at, + code, + recipient, + status, + appliedOriginator, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt); + } + + @Override + public String toString() { + return "DeliveryReportRecipientSMS{} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends DeliveryReportRecipient.Builder { + + protected Builder() { + super(); + } + + public DeliveryReportRecipientSMS build() { + return new DeliveryReportRecipientSMS( + batchId, + clientReference, + at, + code, + recipient, + status, + appliedOriginator, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportStatus.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportStatus.java new file mode 100644 index 00000000..501e8aa5 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportStatus.java @@ -0,0 +1,85 @@ +package com.sinch.sdk.domains.sms.models; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * The status field describes which state a particular message is in. Note that statuses of type + * Intermediate will only be reported if you request a status per_recipient or + * per_recipient_final ( @see Retrieve + * a recipient delivery report). + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/section/Delivery-report-statuses + * @since 1.0 + */ +public class DeliveryReportStatus extends EnumDynamic { + + /** + * Message is queued within REST API system and will be dispatched according to the rate of the + * account. + */ + public static final DeliveryReportStatus QUEUED = new DeliveryReportStatus("Queued"); + /** Message has been dispatched and accepted for delivery by the SMSC. */ + public static final DeliveryReportStatus DISPATCHED = new DeliveryReportStatus("Dispatched"); + /** Message was aborted before reaching the SMSC. */ + public static final DeliveryReportStatus ABORTED = new DeliveryReportStatus("Aborted"); + /** Message was cancelled by user before reaching SMSC. */ + public static final DeliveryReportStatus CANCELLED = new DeliveryReportStatus("Cancelled"); + /** Message was rejected by the SMSC. */ + public static final DeliveryReportStatus REJECTED = new DeliveryReportStatus("Rejected"); + /** + * Message has been deleted. Message was deleted by a remote SMSC. This may happen if the + * destination is an invalid MSISDN or opted out subscriber. + */ + public static final DeliveryReportStatus DELETED = new DeliveryReportStatus("Deleted"); + /** Message has been delivered. */ + public static final DeliveryReportStatus DELIVERED = new DeliveryReportStatus("Delivered"); + /** Message failed to be delivered. */ + public static final DeliveryReportStatus FAILED = new DeliveryReportStatus("Failed"); + /** + * Message expired before delivery to the SMSC. This may happen if the expiry time for the message + * was very short. + */ + public static final DeliveryReportStatus EXPIRED = new DeliveryReportStatus("Expired"); + /** + * Message was delivered to the SMSC but no Delivery Receipt has been received or a Delivery + * Receipt that couldn't be interpreted was received. + */ + public static final DeliveryReportStatus UNKNOWN = new DeliveryReportStatus("Unknown"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + DeliveryReportStatus.class, + DeliveryReportStatus::new, + Arrays.asList( + QUEUED, + DISPATCHED, + ABORTED, + CANCELLED, + REJECTED, + DELETED, + DELIVERED, + FAILED, + EXPIRED, + UNKNOWN)); + + private DeliveryReportStatus(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static DeliveryReportStatus from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(DeliveryReportStatus e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportStatusDetails.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportStatusDetails.java new file mode 100644 index 00000000..1a7ae1d4 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportStatusDetails.java @@ -0,0 +1,102 @@ +package com.sinch.sdk.domains.sms.models; + +import java.util.Collection; + +/** + * Details related to a delivery report status + * + * @since 1.0 + */ +public class DeliveryReportStatusDetails { + + private final Integer code; + private final Integer count; + private final Collection recipients; + private final DeliveryReportStatus status; + + /** + * @param code Required. The detailed status + * code. + * @param count Required. The number of messages that currently has this code + * @param recipients Required. Only for full report. A list of the phone number + * recipients which messages has this status code + * @param status Required. The simplified status as described in Delivery Report + * Statuses + */ + public DeliveryReportStatusDetails( + Integer code, Integer count, Collection recipients, String status) { + this.code = code; + this.count = count; + this.recipients = recipients; + this.status = DeliveryReportStatus.from(status); + } + + public Integer getCode() { + return code; + } + + public Integer getCount() { + return count; + } + + public Collection getRecipients() { + return recipients; + } + + public DeliveryReportStatus getStatus() { + return status; + } + + @Override + public String toString() { + return "DeliveryReportStatusDetails{" + + "code=" + + code + + ", count=" + + count + + ", recipients=" + + recipients + + ", status=" + + status + + '}'; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private Integer code; + private Integer count; + private Collection recipients; + private DeliveryReportStatus status; + + private Builder() {} + + public Builder setCode(Integer code) { + this.code = code; + return this; + } + + public Builder setCount(Integer count) { + this.count = count; + return this; + } + + public Builder setRecipients(Collection recipients) { + this.recipients = recipients; + return this; + } + + public Builder setStatus(DeliveryReportStatus status) { + this.status = status; + return this; + } + + public DeliveryReportStatusDetails build() { + return new DeliveryReportStatusDetails(code, count, recipients, status.value()); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportType.java similarity index 58% rename from client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReport.java rename to client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportType.java index e706dafa..b852d3b2 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReport.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DeliveryReportType.java @@ -6,55 +6,55 @@ import java.util.stream.Stream; /** - * DeliveryReport authorized values + * DeliveryReportType authorized values * * @since 1.0 */ -public class DeliveryReport extends EnumDynamic { +public class DeliveryReportType extends EnumDynamic { /** No delivery report callback will be sent. */ - public static final DeliveryReport NONE = new DeliveryReport("none"); + public static final DeliveryReportType NONE = new DeliveryReportType("none"); /** A single delivery report callback will be sent. */ - public static final DeliveryReport SUMMARY = new DeliveryReport("summary"); + public static final DeliveryReportType SUMMARY = new DeliveryReportType("summary"); /** * A single delivery report callback will be sent which includes a list of recipients per delivery * status. */ - public static final DeliveryReport FULL = new DeliveryReport("full"); + public static final DeliveryReportType FULL = new DeliveryReportType("full"); /** * A delivery report callback will be sent for each status change of a message. This could result * in a lot of callbacks and should be used with caution for larger batches. These delivery * reports also include a timestamp of when the Delivery Report originated from the SMSC. */ - public static final DeliveryReport PER_RECIPIENT = new DeliveryReport("per_recipient"); + public static final DeliveryReportType PER_RECIPIENT = new DeliveryReportType("per_recipient"); /** * A delivery report callback representing the final status of a message will be sent for each * recipient. This will send only one callback per recipient, compared to the multiple callbacks * sent when using per_recipient. The delivery report will also include a timestamp of when it * originated from the SMSC. */ - public static final DeliveryReport PER_RECIPIENT_FINAl = - new DeliveryReport("per_recipient_final"); + public static final DeliveryReportType PER_RECIPIENT_FINAl = + new DeliveryReportType("per_recipient_final"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>( - DeliveryReport.class, - DeliveryReport::new, + DeliveryReportType.class, + DeliveryReportType::new, Arrays.asList(NONE, SUMMARY, FULL, PER_RECIPIENT, PER_RECIPIENT_FINAl)); - private DeliveryReport(String value) { + private DeliveryReportType(String value) { super(value); } - public static Stream values() { + public static Stream values() { return ENUM_SUPPORT.values(); } - public static DeliveryReport from(String value) { + public static DeliveryReportType from(String value) { return ENUM_SUPPORT.from(value); } - public static String valueOf(DeliveryReport e) { + public static String valueOf(DeliveryReportType e) { return ENUM_SUPPORT.valueOf(e); } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DryRun.java b/client/src/main/com/sinch/sdk/domains/sms/models/DryRun.java new file mode 100644 index 00000000..e80d2c98 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DryRun.java @@ -0,0 +1,84 @@ +package com.sinch.sdk.domains.sms.models; + +import java.util.Collection; + +/** + * Information related to a dryRun request + * + * @since 1.0 + */ +public class DryRun { + + private final Integer numberOfRecipients; + private final Integer numberOfMessages; + private final Collection perRecipient; + + /** + * @param numberOfRecipients The number of recipients in the batch + * @param numberOfMessages The total number of SMS message parts to be sent in the batch + * @param perRecipient The recipient, the number of message parts to this recipient, the body of + * the message, and the encoding type of each message + */ + public DryRun( + Integer numberOfRecipients, + Integer numberOfMessages, + Collection perRecipient) { + this.numberOfRecipients = numberOfRecipients; + this.numberOfMessages = numberOfMessages; + this.perRecipient = perRecipient; + } + + public Integer getNumberOfRecipients() { + return numberOfRecipients; + } + + public Integer getNumberOfMessages() { + return numberOfMessages; + } + + public Collection getPerRecipient() { + return perRecipient; + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public String toString() { + return "DryRun{" + + "numberOfRecipients=" + + numberOfRecipients + + ", numberOfMessages=" + + numberOfMessages + + ", perRecipient=" + + perRecipient + + '}'; + } + + public static class Builder { + + private Integer numberOfRecipients; + private Integer numberOfMessages; + private Collection perRecipient; + + public Builder setNumberOfRecipients(Integer numberOfRecipients) { + this.numberOfRecipients = numberOfRecipients; + return this; + } + + public Builder setNumberOfMessages(Integer numberOfMessages) { + this.numberOfMessages = numberOfMessages; + return this; + } + + public Builder setPerRecipient(Collection perRecipient) { + this.perRecipient = perRecipient; + return this; + } + + public DryRun build() { + return new DryRun(numberOfRecipients, numberOfMessages, perRecipient); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DryRunPerRecipientDetails.java b/client/src/main/com/sinch/sdk/domains/sms/models/DryRunPerRecipientDetails.java new file mode 100644 index 00000000..2294adfe --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DryRunPerRecipientDetails.java @@ -0,0 +1,94 @@ +package com.sinch.sdk.domains.sms.models; + +/** + * Details related to a dryRun recipient + * + * @since 1.0 + */ +public class DryRunPerRecipientDetails { + + private final String recipient; + private final String messagePart; + private final String body; + private final String encoding; + + public DryRunPerRecipientDetails( + String recipient, String messagePart, String body, String encoding) { + this.recipient = recipient; + this.messagePart = messagePart; + this.body = body; + this.encoding = encoding; + } + + public String getRecipient() { + return recipient; + } + + public String getMessagePart() { + return messagePart; + } + + public String getBody() { + return body; + } + + public String getEncoding() { + return encoding; + } + + @Override + public String toString() { + return "DryRunPerRecipientDetails{" + + "recipient='" + + recipient + + '\'' + + ", messagePart='" + + messagePart + + '\'' + + ", body='" + + body + + '\'' + + ", encoding='" + + encoding + + '\'' + + '}'; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String recipient; + private String messagePart; + private String body; + private String encoding; + + public Builder setRecipient(String recipient) { + this.recipient = recipient; + return this; + } + + public Builder setMessagePart(String messagePart) { + this.messagePart = messagePart; + return this; + } + + public Builder setBody(String body) { + this.body = body; + return this; + } + + public Builder setEncoding(String encoding) { + this.encoding = encoding; + return this; + } + + private Builder() {} + + public DryRunPerRecipientDetails build() { + return new DryRunPerRecipientDetails(recipient, messagePart, body, encoding); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/Group.java b/client/src/main/com/sinch/sdk/domains/sms/models/Group.java new file mode 100644 index 00000000..b7c6b3be --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/Group.java @@ -0,0 +1,151 @@ +package com.sinch.sdk.domains.sms.models; + +import com.sinch.sdk.domains.sms.models.GroupAutoUpdateKeyword.Builder; +import java.time.Instant; +import java.util.Collection; + +public class Group { + + private final String id; + private final String name; + private final Integer size; + private final Instant createdAt; + private final Instant modifiedAt; + private final Collection childGroupIds; + private final GroupAutoUpdate autoUpdate; + + /** + * @param id Unique identifier for the group + * @param name Name of group if set + * @param size The number of members currently in the group + * @param createdAt Timestamp for when the group was created + * @param modifiedAt Timestamp for when the group was created + * @param childGroupIds MSISDNs of child group will be included in this group. If present then + * this group will be auto populated. Constraints: Elements must be group IDs + * @param autoUpdate Describes how this group is auto updated through user interaction. Is + * null if the group is not auto updated. + */ + public Group( + String id, + String name, + Integer size, + Instant createdAt, + Instant modifiedAt, + Collection childGroupIds, + GroupAutoUpdate autoUpdate) { + this.id = id; + this.name = name; + this.size = size; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; + this.childGroupIds = childGroupIds; + this.autoUpdate = autoUpdate; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public Integer getSize() { + return size; + } + + public Instant getCreatedAt() { + return createdAt; + } + + public Instant getModifiedAt() { + return modifiedAt; + } + + public Collection getChildGroupIds() { + return childGroupIds; + } + + public GroupAutoUpdate getAutoUpdate() { + return autoUpdate; + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public String toString() { + return "Group{" + + "id='" + + id + + '\'' + + ", name='" + + name + + '\'' + + ", size=" + + size + + ", createdAt=" + + createdAt + + ", modifiedAt=" + + modifiedAt + + ", childGroupIds=" + + childGroupIds + + ", autoUpdate=" + + autoUpdate + + '}'; + } + + public static class Builder { + + String id; + String name; + Integer size; + Instant createdAt; + Instant modifiedAt; + Collection childGroupIds; + GroupAutoUpdate autoUpdate; + + private Builder() {} + ; + + public Builder setId(String id) { + this.id = id; + return this; + } + + public Builder setName(String name) { + this.name = name; + return this; + } + + public Builder setSize(Integer size) { + this.size = size; + return this; + } + + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = createdAt; + return this; + } + + public Builder setModifiedAt(Instant modifiedAt) { + this.modifiedAt = modifiedAt; + return this; + } + + public Builder setChildGroupIds(Collection childGroupIds) { + this.childGroupIds = childGroupIds; + return this; + } + + public Builder setAutoUpdate(GroupAutoUpdate autoUpdate) { + this.autoUpdate = autoUpdate; + return this; + } + + public Group build() { + return new Group(id, name, size, createdAt, modifiedAt, childGroupIds, autoUpdate); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdate.java b/client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdate.java new file mode 100644 index 00000000..95111419 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdate.java @@ -0,0 +1,71 @@ +package com.sinch.sdk.domains.sms.models; + +import com.sinch.sdk.domains.sms.models.GroupAutoUpdateKeyword.Builder; + +public class GroupAutoUpdate { + private final String to; + private final GroupAutoUpdateKeyword add; + private final GroupAutoUpdateKeyword remove; + + /** + * @param to Short code or long number addressed in MO.
+ * Constraints: Must be valid MSISDN or short code. + * @param add Keyword to be sent in MO to add MSISDN to a group + * @param remove Keyword to be sent in MO to remove MSISDN to a group + */ + public GroupAutoUpdate(String to, GroupAutoUpdateKeyword add, GroupAutoUpdateKeyword remove) { + this.to = to; + this.add = add; + this.remove = remove; + } + + public String getTo() { + return to; + } + + public GroupAutoUpdateKeyword getAdd() { + return add; + } + + public GroupAutoUpdateKeyword getRemove() { + return remove; + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public String toString() { + return "GroupAutoUpdate{" + "to='" + to + '\'' + ", add=" + add + ", remove=" + remove + '}'; + } + + public static class Builder { + + String to; + GroupAutoUpdateKeyword add; + GroupAutoUpdateKeyword remove; + + private Builder() {} + ; + + public Builder setTo(String to) { + this.to = to; + return this; + } + + public Builder setAdd(GroupAutoUpdateKeyword add) { + this.add = add; + return this; + } + + public Builder setRemove(GroupAutoUpdateKeyword remove) { + this.remove = remove; + return this; + } + + public GroupAutoUpdate build() { + return new GroupAutoUpdate(to, add, remove); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdateKeyword.java b/client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdateKeyword.java new file mode 100644 index 00000000..49145883 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdateKeyword.java @@ -0,0 +1,66 @@ +package com.sinch.sdk.domains.sms.models; + +import com.sinch.sdk.domains.sms.models.InboundBinary.Builder; + +public class GroupAutoUpdateKeyword { + + private final String firstWord; + private final String secondWord; + + /** + * @param firstWord Opt-in keyword like "JOIN" if _auto_update.to_ is dedicated long/short number + * or unique brand keyword like "Sinch" if it is a shared short code. + * @param secondWord Opt-in keyword like "JOIN" if _auto_update.to_ is shared short code. + */ + public GroupAutoUpdateKeyword(String firstWord, String secondWord) { + this.firstWord = firstWord; + this.secondWord = secondWord; + } + + public String getFirstWord() { + return firstWord; + } + + public String getSecondWord() { + return secondWord; + } + + @Override + public String toString() { + return "GroupAutoUpdateKeyword{" + + "firstWord='" + + firstWord + + '\'' + + ", secondWord='" + + secondWord + + '\'' + + '}'; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + String firstWord; + String secondWord; + + private Builder() {} + ; + + public Builder setFirstWord(String firstWord) { + this.firstWord = firstWord; + return this; + } + + public Builder setSecondWord(String secondWord) { + this.secondWord = secondWord; + return this; + } + + public GroupAutoUpdateKeyword build() { + return new GroupAutoUpdateKeyword(firstWord, secondWord); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/Inbound.java b/client/src/main/com/sinch/sdk/domains/sms/models/Inbound.java new file mode 100644 index 00000000..2c71c310 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/Inbound.java @@ -0,0 +1,159 @@ +package com.sinch.sdk.domains.sms.models; + +import java.time.Instant; +import java.util.Optional; + +/** + * Base class for Incoming message + * + * @param Type of body + * @since 1.0 + */ +public abstract class Inbound { + + private final T body; + private final String from; + private final String id; + private final Instant receivedAt; + private final String to; + private final String clientReference; + private final String operatorId; + private final Instant sentAt; + + public Inbound( + T body, + String from, + String id, + Instant receivedAt, + String to, + String clientReference, + String operatorId, + Instant sentAt) { + this.body = body; + this.from = from; + this.id = id; + this.receivedAt = receivedAt; + this.to = to; + this.clientReference = clientReference; + this.operatorId = operatorId; + this.sentAt = sentAt; + } + + public T getBody() { + return body; + } + + public String getFrom() { + return from; + } + + public String getId() { + return id; + } + + public Instant getReceivedAt() { + return receivedAt; + } + + public String getTo() { + return to; + } + + public Optional getClientReference() { + return Optional.ofNullable(clientReference); + } + + public Optional getOperatorId() { + return Optional.ofNullable(operatorId); + } + + public Optional getSentAt() { + return Optional.ofNullable(sentAt); + } + + @Override + public String toString() { + return "Inbound{" + + "body=" + + body + + ", from='" + + from + + '\'' + + ", id='" + + id + + '\'' + + ", receivedAt=" + + receivedAt + + ", to='" + + to + + '\'' + + ", clientReference='" + + clientReference + + '\'' + + ", operatorId='" + + operatorId + + '\'' + + ", sentAt=" + + sentAt + + '}'; + } + + public abstract static class Builder> { + + T body; + String from; + String id; + Instant receivedAt; + String to; + String clientReference; + String operatorId; + Instant sentAt; + + public B setBody(T body) { + this.body = body; + return self(); + } + + public B setFrom(String from) { + this.from = from; + return self(); + } + + public B setId(String id) { + this.id = id; + return self(); + } + + public B setReceivedAt(Instant receivedAt) { + this.receivedAt = receivedAt; + return self(); + } + + public B setTo(String to) { + this.to = to; + return self(); + } + + public B setClientReference(String clientReference) { + this.clientReference = clientReference; + return self(); + } + + public B setOperatorId(String operatorId) { + this.operatorId = operatorId; + return self(); + } + + public B setSentAt(Instant sentAt) { + this.sentAt = sentAt; + return self(); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + + public abstract Inbound build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/InboundBinary.java b/client/src/main/com/sinch/sdk/domains/sms/models/InboundBinary.java new file mode 100644 index 00000000..70081c01 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/InboundBinary.java @@ -0,0 +1,82 @@ +package com.sinch.sdk.domains.sms.models; + +import java.time.Instant; + +/** + * Incoming SMS Binary + * + * @since 1.0 + */ +public class InboundBinary extends Inbound { + + private final String udh; + + /** + * Binary MO class + * + * @param body The message content Base64 encoded. Max 140 bytes together with udh. + * @param from The phone number that sent the message. @see https://community.sinch.com/t5/Glossary/MSISDN/ta-p/7628 + * @param id The ID of this inbound message. + * @param receivedAt When the system received the message. + * @param to The Sinch phone number or short code to which the message was sent. + * @param clientReference If this inbound message is in response to a previously sent message that + * contained a client reference, then this field contains that client reference. Utilizing + * this feature requires additional setup on your account. Contact your account manager to + * enable this feature. + * @param operatorId The MCC/MNC of the sender's operator if known. + * @param sendAt When the message left the originating device. Only available if provided by + * operator. + * @param udh The UDH header of a binary message HEX encoded. Max 140 bytes together with body. + */ + public InboundBinary( + String body, + String from, + String id, + Instant receivedAt, + String to, + String clientReference, + String operatorId, + Instant sendAt, + String udh) { + super(body, from, id, receivedAt, to, clientReference, operatorId, sendAt); + this.udh = udh; + } + + public String getUdh() { + return udh; + } + + @Override + public String toString() { + return "InboundBinary{" + "udh='" + udh + '\'' + "} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Inbound.Builder { + + String udh; + + protected Builder() { + super(); + } + + public Builder setUdh(String udh) { + this.udh = udh; + return this; + } + + public InboundBinary build() { + return new InboundBinary( + body, from, id, receivedAt, to, clientReference, operatorId, sentAt, udh); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/InboundText.java b/client/src/main/com/sinch/sdk/domains/sms/models/InboundText.java new file mode 100644 index 00000000..9d68027f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/InboundText.java @@ -0,0 +1,65 @@ +package com.sinch.sdk.domains.sms.models; + +import java.time.Instant; + +/** + * Incoming SMS Text + * + * @since 1.0 + */ +public class InboundText extends Inbound { + + /** + * Text MO class + * + * @param body The message content Base64 encoded. Max 140 bytes together with udh. + * @param from The phone number that sent the message. @see https://community.sinch.com/t5/Glossary/MSISDN/ta-p/7628 + * @param id The ID of this inbound message. + * @param receivedAt When the system received the message. + * @param to The Sinch phone number or short code to which the message was sent. + * @param clientReference If this inbound message is in response to a previously sent message that + * contained a client reference, then this field contains that client reference. Utilizing + * this feature requires additional setup on your account. Contact your account manager to + * enable this feature. + * @param operatorId The MCC/MNC of the sender's operator if known. + * @param sentAt When the message left the originating device. Only available if provided by + * operator. + */ + public InboundText( + String body, + String from, + String id, + Instant receivedAt, + String to, + String clientReference, + String operatorId, + Instant sentAt) { + super(body, from, id, receivedAt, to, clientReference, operatorId, sentAt); + } + + @Override + public String toString() { + return "InboundText{} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Inbound.Builder { + + protected Builder() { + super(); + } + + public InboundText build() { + return new InboundText(body, from, id, receivedAt, to, clientReference, operatorId, sentAt); + } + + @Override + protected InboundText.Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/MediaBody.java b/client/src/main/com/sinch/sdk/domains/sms/models/MediaBody.java index acbc67ff..f12056cf 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/MediaBody.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/MediaBody.java @@ -1,5 +1,7 @@ package com.sinch.sdk.domains.sms.models; +import java.util.Optional; + /** * MediaBody object * @@ -19,14 +21,18 @@ public MediaBody(String url, String message) { this.url = url; } - public String getMessage() { - return message; + public MediaBody(String url) { + this(url, null); } public String getUrl() { return url; } + public Optional getMessage() { + return Optional.ofNullable(message); + } + @Override public String toString() { return "MediaBody{" + "message='" + message + '\'' + ", url='" + url + '\'' + '}'; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/BatchesListRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/BatchesListRequestParameters.java new file mode 100644 index 00000000..f374782b --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/BatchesListRequestParameters.java @@ -0,0 +1,133 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import java.time.Instant; +import java.util.Optional; + +/** + * Parameters request to list batches for a project + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Batches/#tag/Batches/operation/ListBatches/ + * @since 1.0 + */ +public class BatchesListRequestParameters { + + private final String from; + private final Instant startDate; + private final Instant endDate; + private final String clientReference; + private final Integer page; + private final Integer pageSize; + + /** + * @param from Only list messages sent from this sender number. Multiple originating numbers can + * be comma separated. Must be phone numbers or short code. + * @param startDate Only list messages received at or after this date/time. + * @param endDate Only list messages received before this date/time + * @param clientReference Client reference to include + * @param page The page number starting from 0 + * @param pageSize Determines the size of a page + */ + public BatchesListRequestParameters( + String from, + Instant startDate, + Instant endDate, + String clientReference, + Integer page, + Integer pageSize) { + this.from = from; + this.startDate = startDate; + this.endDate = endDate; + this.clientReference = clientReference; + this.page = page; + this.pageSize = pageSize; + } + + public Optional getFrom() { + return Optional.ofNullable(from); + } + + public Optional getStartDate() { + return Optional.ofNullable(startDate); + } + + public Optional getEndDate() { + return Optional.ofNullable(endDate); + } + + public Optional getClientReference() { + return Optional.ofNullable(clientReference); + } + + public Optional getPage() { + return Optional.ofNullable(page); + } + + public Optional getPageSize() { + return Optional.ofNullable(pageSize); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(BatchesListRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + String from; + Instant startDate; + Instant endDate; + String clientReference; + Integer page; + Integer pageSize; + + private Builder() {} + + private Builder(BatchesListRequestParameters parameters) { + this.from = parameters.from; + this.startDate = parameters.startDate; + this.endDate = parameters.endDate; + this.clientReference = parameters.clientReference; + this.page = parameters.page; + this.pageSize = parameters.pageSize; + } + + public Builder setFrom(String from) { + this.from = from; + return this; + } + + public Builder setStartDate(Instant startDate) { + this.startDate = startDate; + return this; + } + + public Builder setEndDate(Instant endDate) { + this.endDate = endDate; + return this; + } + + public Builder setClientReference(String clientReference) { + this.clientReference = clientReference; + return this; + } + + public Builder setPage(Integer page) { + this.page = page; + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public BatchesListRequestParameters build() { + return new BatchesListRequestParameters( + from, startDate, endDate, clientReference, page, pageSize); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportBatchGetRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportBatchGetRequestParameters.java new file mode 100644 index 00000000..c2ed7608 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportBatchGetRequestParameters.java @@ -0,0 +1,96 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import java.util.Collection; +import java.util.Optional; + +/** + * Parameters request to get a Batch Delivery Report + * + * @since 1.0 + */ +public class DeliveryReportBatchGetRequestParameters { + + private final DeliveryReportType type; + private final Collection statuses; + private final Collection codes; + + /** + * @param type Filter by type of delivery report. + *
    + *
  • A summary will count the number of messages sent per status. + *
  • A full report give that of a summary report but in addition, lists phone + * numbers. + *
+ * + * @param statuses Filter by list of statuses + * to include + * @param codes Filter by list of codes + * to include + */ + public DeliveryReportBatchGetRequestParameters( + DeliveryReportType type, + Collection statuses, + Collection codes) { + this.type = type; + this.statuses = statuses; + this.codes = codes; + } + + public Optional getType() { + return Optional.ofNullable(type); + } + + public Optional> geStatues() { + return Optional.ofNullable(statuses); + } + + public Optional> getCodes() { + return Optional.ofNullable(codes); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(DeliveryReportBatchGetRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + DeliveryReportType type; + Collection statuses; + Collection codes; + + private Builder() {} + + private Builder(DeliveryReportBatchGetRequestParameters parameters) { + this.type = parameters.type; + this.statuses = parameters.statuses; + this.codes = parameters.codes; + } + + public Builder setType(DeliveryReportType type) { + this.type = type; + return this; + } + + public Builder setStatuses(Collection statuses) { + this.statuses = statuses; + return this; + } + + public Builder setCodes(Collection codes) { + this.codes = codes; + return this; + } + + public DeliveryReportBatchGetRequestParameters build() { + return new DeliveryReportBatchGetRequestParameters(type, statuses, codes); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParameters.java new file mode 100644 index 00000000..566b4667 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParameters.java @@ -0,0 +1,150 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReportErrorCode; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +/** + * Parameters request to list delivery reports for a project + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/getDeliveryReports + * @since 1.0 + */ +public class DeliveryReportListRequestParameters { + + private final Instant startDate; + private final Instant endDate; + private final String clientReference; + private final Integer page; + private final Integer pageSize; + private final Collection statuses; + private final Collection codes; + + /** + * @param startDate Only list messages received at or after this date/time. Default: 24h ago + * @param endDate Only list messages received before this date/time. + * @param clientReference Client reference to include + * @param page The page number starting from 0. + * @param pageSize Determines the size of a page. + * @param statuses List of delivery report statuses to include + * @param codes List of delivery receipt error codes to include + */ + public DeliveryReportListRequestParameters( + Instant startDate, + Instant endDate, + String clientReference, + Integer page, + Integer pageSize, + Collection statuses, + Collection codes) { + this.startDate = startDate; + this.endDate = endDate; + this.clientReference = clientReference; + this.page = page; + this.pageSize = pageSize; + this.statuses = statuses; + this.codes = codes; + } + + public Optional getStartDate() { + return Optional.ofNullable(startDate); + } + + public Optional getEndDate() { + return Optional.ofNullable(endDate); + } + + public Optional getClientReference() { + return Optional.ofNullable(clientReference); + } + + public Optional getPage() { + return Optional.ofNullable(page); + } + + public Optional getPageSize() { + return Optional.ofNullable(pageSize); + } + + public Optional> getStatuses() { + return Optional.ofNullable(statuses); + } + + public Optional> getCodes() { + return Optional.ofNullable(codes); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(DeliveryReportListRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + Instant startDate; + Instant endDate; + String clientReference; + Integer page; + Integer pageSize; + Collection statuses; + Collection codes; + + private Builder() {} + + private Builder(DeliveryReportListRequestParameters parameters) { + this.startDate = parameters.startDate; + this.endDate = parameters.endDate; + this.clientReference = parameters.clientReference; + this.page = parameters.page; + this.pageSize = parameters.pageSize; + this.statuses = parameters.statuses; + this.codes = parameters.codes; + } + + public Builder setStartDate(Instant startDate) { + this.startDate = startDate; + return this; + } + + public Builder setEndDate(Instant endDate) { + this.endDate = endDate; + return this; + } + + public Builder setClientReference(String clientReference) { + this.clientReference = clientReference; + return this; + } + + public Builder setPage(Integer page) { + this.page = page; + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public Builder setStatuses(Collection statuses) { + this.statuses = statuses; + return this; + } + + public Builder setCodes(Collection codes) { + this.codes = codes; + return this; + } + + public DeliveryReportListRequestParameters build() { + return new DeliveryReportListRequestParameters( + startDate, endDate, clientReference, page, pageSize, statuses, codes); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupCreateRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupCreateRequestParameters.java new file mode 100644 index 00000000..ffd12e2c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupCreateRequestParameters.java @@ -0,0 +1,117 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.GroupAutoUpdate; +import java.util.Collection; +import java.util.Optional; + +/** + * Parameters request to create a group + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/CreateGroup + * @since 1.0 + */ +public class GroupCreateRequestParameters { + + private final String name; + private final Collection members; + private final Collection childGroupIds; + private final GroupAutoUpdate autoUpdate; + + /** + * @param name Name of the group + * @param members Initial list of phone numbers in E.164 format MSISDNs for the group + * @param childGroupIds Child group IDs + * @param autoUpdate Auto update settings + */ + public GroupCreateRequestParameters( + String name, + Collection members, + Collection childGroupIds, + GroupAutoUpdate autoUpdate) { + this.name = name; + this.members = members; + this.childGroupIds = childGroupIds; + this.autoUpdate = autoUpdate; + } + + public Optional getName() { + return Optional.ofNullable(name); + } + + public Optional> getMembers() { + return Optional.ofNullable(members); + } + + public Optional> getChildGroupIds() { + return Optional.ofNullable(childGroupIds); + } + + public Optional getAutoUpdate() { + return Optional.ofNullable(autoUpdate); + } + + @Override + public String toString() { + return "GroupCreateRequestParameters{" + + "name='" + + name + + '\'' + + ", members=" + + members + + ", childGroupIds=" + + childGroupIds + + ", autoUpdate=" + + autoUpdate + + '}'; + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(GroupCreateRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + String name; + Collection members; + Collection childGroupIds; + GroupAutoUpdate autoUpdate; + + private Builder() {} + + private Builder(GroupCreateRequestParameters parameters) { + this.name = parameters.getName().orElse(null); + this.members = parameters.getMembers().orElse(null); + this.childGroupIds = parameters.getChildGroupIds().orElse(null); + this.autoUpdate = parameters.getAutoUpdate().orElse(null); + } + + public Builder setName(String name) { + this.name = name; + return this; + } + + public Builder setMembers(Collection members) { + this.members = members; + return this; + } + + public Builder setChildGroupIds(Collection childGroupIds) { + this.childGroupIds = childGroupIds; + return this; + } + + public Builder setAutoUpdate(GroupAutoUpdate autoUpdate) { + this.autoUpdate = autoUpdate; + return this; + } + + public GroupCreateRequestParameters build() { + return new GroupCreateRequestParameters(name, members, childGroupIds, autoUpdate); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupReplaceRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupReplaceRequestParameters.java new file mode 100644 index 00000000..f9d3def7 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupReplaceRequestParameters.java @@ -0,0 +1,75 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import java.util.Collection; +import java.util.Optional; + +/** + * Parameters request to replace a group + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ReplaceGroup + * @since 1.0 + */ +public class GroupReplaceRequestParameters { + + private final String name; + private final Collection members; + + /** + * @param name Name of the group + * @param members The initial members of the group. + *

Constraints: Elements must be phone numbers in E.164 format MSISDNs. + */ + public GroupReplaceRequestParameters(String name, Collection members) { + this.name = name; + this.members = members; + } + + public Optional getName() { + return Optional.ofNullable(name); + } + + public Optional> getMembers() { + return Optional.ofNullable(members); + } + + @Override + public String toString() { + return "GroupCreateRequestParameters{" + "name='" + name + '\'' + ", members=" + members + '}'; + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(GroupReplaceRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + String name; + Collection members; + + private Builder() {} + + private Builder(GroupReplaceRequestParameters parameters) { + this.name = parameters.getName().orElse(null); + this.members = parameters.getMembers().orElse(null); + } + + public Builder setName(String name) { + this.name = name; + return this; + } + + public Builder setMembers(Collection members) { + this.members = members; + return this; + } + + public GroupReplaceRequestParameters build() { + return new GroupReplaceRequestParameters(name, members); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupUpdateRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupUpdateRequestParameters.java new file mode 100644 index 00000000..ae63293b --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupUpdateRequestParameters.java @@ -0,0 +1,156 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.GroupAutoUpdate; +import java.util.Collection; +import java.util.Optional; + +/** + * Parameters request to updat" a group + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/UpdateGroup + * @since 1.0 + */ +public class GroupUpdateRequestParameters { + + private final String name; + private final Collection add; + private final Collection remove; + private final String addFromGroup; + private final String removeFromGroup; + private final GroupAutoUpdate autoUpdate; + + public GroupUpdateRequestParameters( + String name, + Collection add, + Collection remove, + String addFromGroup, + String removeFromGroup, + GroupAutoUpdate autoUpdate) { + this.name = name; + this.add = add; + this.remove = remove; + this.addFromGroup = addFromGroup; + this.removeFromGroup = removeFromGroup; + this.autoUpdate = autoUpdate; + } + + public Optional getName() { + return Optional.ofNullable(name); + } + + public Optional> getAdd() { + return Optional.ofNullable(add); + } + + public Optional> getRemove() { + return Optional.ofNullable(remove); + } + + public Optional getAddFromGroup() { + return Optional.ofNullable(addFromGroup); + } + + public Optional getRemoveFromGroup() { + return Optional.ofNullable(removeFromGroup); + } + + public Optional getAutoUpdate() { + return Optional.ofNullable(autoUpdate); + } + + @Override + public String toString() { + return "GroupUpdateRequestParameters{" + + "name='" + + name + + '\'' + + ", add=" + + add + + ", remove=" + + remove + + ", addFromGroup='" + + addFromGroup + + '\'' + + ", removeFromGroup='" + + removeFromGroup + + '\'' + + ", autoUpdate=" + + autoUpdate + + '}'; + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(GroupUpdateRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + String name; + + Collection add; + + Collection remove; + + String addFromGroup; + + String removeFromGroup; + + GroupAutoUpdate autoUpdate; + + private Builder() {} + + private Builder(GroupUpdateRequestParameters parameters) { + this.name = parameters.getName().orElse(null); + + this.add = parameters.getAdd().orElse(null); + + this.remove = parameters.getRemove().orElse(null); + + this.addFromGroup = parameters.getAddFromGroup().orElse(null); + + this.removeFromGroup = parameters.getRemoveFromGroup().orElse(null); + + this.autoUpdate = parameters.getAutoUpdate().orElse(null); + } + + public Builder setName(String name) { + this.name = name; + return this; + } + + public Builder setAdd(Collection add) { + this.add = add; + return this; + } + + public Builder setRemove(Collection remove) { + this.remove = remove; + return this; + } + + public Builder setAddFromGroup(String addFromGroup) { + this.addFromGroup = addFromGroup; + return this; + } + + public Builder setRemoveFromGroup(String removeFromGroup) { + this.removeFromGroup = removeFromGroup; + return this; + } + + public Builder setAutoUpdate(GroupAutoUpdate autoUpdate) { + this.autoUpdate = autoUpdate; + return this; + } + + public GroupUpdateRequestParameters build() { + return new GroupUpdateRequestParameters( + name, add, remove, addFromGroup, removeFromGroup, autoUpdate); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupsListRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupsListRequestParameters.java new file mode 100644 index 00000000..88a695d3 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupsListRequestParameters.java @@ -0,0 +1,68 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import java.util.Optional; + +/** + * Parameters request to list groups + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ListGroups + * @since 1.0 + */ +public class GroupsListRequestParameters { + + private final Integer page; + private final Integer pageSize; + + /** + * @param page The page number starting from 0. + * @param pageSize Determines the size of a page. + */ + public GroupsListRequestParameters(Integer page, Integer pageSize) { + this.page = page; + this.pageSize = pageSize; + } + + public Optional getPage() { + return Optional.ofNullable(page); + } + + public Optional getPageSize() { + return Optional.ofNullable(pageSize); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(GroupsListRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + Integer page; + Integer pageSize; + + private Builder() {} + + private Builder(GroupsListRequestParameters parameters) { + this.page = parameters.page; + this.pageSize = parameters.pageSize; + } + + public Builder setPage(Integer page) { + this.page = page; + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public GroupsListRequestParameters build() { + return new GroupsListRequestParameters(page, pageSize); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/InboundsListRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/InboundsListRequestParameters.java new file mode 100644 index 00000000..70f1c3d9 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/InboundsListRequestParameters.java @@ -0,0 +1,135 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +/** + * Parameters request to list delivery reports for a project + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/getDeliveryReports + * @since 1.0 + */ +public class InboundsListRequestParameters { + + private final Instant startDate; + private final Instant endDate; + private final String clientReference; + private final Integer page; + private final Integer pageSize; + private final Collection to; + + /** + * @param startDate Only list messages received at or after this date/time + * @param endDate Only list messages received before this date/time + * @param clientReference Using a client reference in inbound messages requires additional setup + * on your account. Contact your account manager to enable this feature. Only list inbound + * messages that are in response to messages with a previously provided client reference. + * @param page The page number starting from 0. + * @param pageSize Determines the size of a page. + * @param to Only list messages sent to these destinations + */ + public InboundsListRequestParameters( + Instant startDate, + Instant endDate, + String clientReference, + Integer page, + Integer pageSize, + Collection to) { + this.startDate = startDate; + this.endDate = endDate; + this.clientReference = clientReference; + this.page = page; + this.pageSize = pageSize; + this.to = to; + } + + public Optional getStartDate() { + return Optional.ofNullable(startDate); + } + + public Optional getEndDate() { + return Optional.ofNullable(endDate); + } + + public Optional getClientReference() { + return Optional.ofNullable(clientReference); + } + + public Optional getPage() { + return Optional.ofNullable(page); + } + + public Optional getPageSize() { + return Optional.ofNullable(pageSize); + } + + public Optional> getTo() { + return Optional.ofNullable(to); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(InboundsListRequestParameters parameters) { + return new Builder(parameters); + } + + public static class Builder { + + Instant startDate; + Instant endDate; + String clientReference; + Integer page; + Integer pageSize; + Collection to; + + private Builder() {} + + private Builder(InboundsListRequestParameters parameters) { + this.startDate = parameters.startDate; + this.endDate = parameters.endDate; + this.clientReference = parameters.clientReference; + this.page = parameters.page; + this.pageSize = parameters.pageSize; + this.to = parameters.to; + } + + public Builder setStartDate(Instant startDate) { + this.startDate = startDate; + return this; + } + + public Builder setEndDate(Instant endDate) { + this.endDate = endDate; + return this; + } + + public Builder setClientReference(String clientReference) { + this.clientReference = clientReference; + return this; + } + + public Builder setPage(Integer page) { + this.page = page; + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public Builder setTo(Collection to) { + this.to = to; + return this; + } + + public InboundsListRequestParameters build() { + return new InboundsListRequestParameters( + startDate, endDate, clientReference, page, pageSize, to); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java new file mode 100644 index 00000000..7ec6593b --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java @@ -0,0 +1,185 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.BaseBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class SendSmsBatchBinaryRequest extends BaseBatch { + private final Boolean flashMessage; + private final Boolean truncateConcat; + private final Integer maxNumberOfMessageParts; + private final Integer fromTon; + private final Integer fromNpi; + private final String udh; + /** + * @param to List of Phone numbers and group IDs that will receive the batch + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param clientReference The client identifier of a batch message. If set, the identifier will be + * added in the delivery report/callback of this batch + * @param feedbackEnabled If set to true, then feedback is expected after successful delivery. + * @param flashMessage If sent as a flash message, displays true. + * @param truncateConcat If set to true, the message was shortened when exceeding one part. + * @param maxNumberOfMessageParts Displays the number of message parts set in the request. + * @param fromTon The type of number for the sender number. + * @param fromNpi Number Plan Indicator for the sender number. + * @param udh The UDH header of a binary message HEX encoded. Max 140 bytes including the body. + */ + public SendSmsBatchBinaryRequest( + Collection to, + String from, + String body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + String clientReference, + Boolean flashMessage, + Boolean feedbackEnabled, + Boolean truncateConcat, + Integer maxNumberOfMessageParts, + Integer fromTon, + Integer fromNpi, + String udh) { + super( + to, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled); + this.flashMessage = flashMessage; + this.truncateConcat = truncateConcat; + this.maxNumberOfMessageParts = maxNumberOfMessageParts; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + this.udh = udh; + } + + public Optional isFlashMessage() { + return Optional.ofNullable(flashMessage); + } + + public Optional isTruncateConcat() { + return Optional.ofNullable(truncateConcat); + } + + public Optional getMaxNumberOfMessageParts() { + return Optional.ofNullable(maxNumberOfMessageParts); + } + + public Optional getFromTon() { + return Optional.ofNullable(fromTon); + } + + public Optional getFromNpi() { + return Optional.ofNullable(fromNpi); + } + + public String getUdh() { + return udh; + } + + @Override + public String toString() { + return "SendSmsBatchBinaryRequest{" + + "flashMessage=" + + flashMessage + + ", truncateConcat=" + + truncateConcat + + ", maxNumberOfMessageParts=" + + maxNumberOfMessageParts + + ", fromTon=" + + fromTon + + ", fromNpi=" + + fromNpi + + ", udh='" + + udh + + '\'' + + ", base='" + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends BaseBatch.Builder { + private Boolean flashMessage; + private Boolean truncateConcat; + private Integer maxNumberOfMessageParts; + private Integer fromTon; + private Integer fromNpi; + private String udh; + + private Builder() {} + + public Builder setFlashMessage(boolean flashMessage) { + this.flashMessage = flashMessage; + return this; + } + + public Builder setTruncateConcat(boolean truncateConcat) { + this.truncateConcat = truncateConcat; + return this; + } + + public Builder setMaxNumberOfMessageParts(int maxNumberOfMessageParts) { + this.maxNumberOfMessageParts = maxNumberOfMessageParts; + return this; + } + + public Builder setFromTon(int fromTon) { + this.fromTon = fromTon; + return this; + } + + public Builder setFromNpi(int fromNpi) { + this.fromNpi = fromNpi; + return this; + } + + public Builder setUdh(String udh) { + this.udh = udh; + return this; + } + + public SendSmsBatchBinaryRequest build() { + return new SendSmsBatchBinaryRequest( + to, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + flashMessage, + feedbackEnabled, + truncateConcat, + maxNumberOfMessageParts, + fromTon, + fromNpi, + udh); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchMediaRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchMediaRequest.java new file mode 100644 index 00000000..2c050ca4 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchMediaRequest.java @@ -0,0 +1,123 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.BaseBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.MediaBody; +import com.sinch.sdk.domains.sms.models.Parameters; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class SendSmsBatchMediaRequest extends BaseBatch { + private final Parameters parameters; + private final Boolean strictValidation; + + /** + * @param to List of Phone numbers and group IDs that will receive the batch + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param clientReference The client identifier of a batch message. If set, the identifier will be + * added in the delivery report/callback of this batch + * @param feedbackEnabled If set to true, then feedback is expected after successful delivery. + * @param parameters Contains the parameters that will be used for customizing the message for + * each recipient. + * @param strictValidation Whether or not you want the media included in your message to be + * checked against Sinch MMS channel best practices. If set to true, your message will be + * rejected if it doesn't conform to the listed recommendations, otherwise no validation will + * be performed. + */ + public SendSmsBatchMediaRequest( + Collection to, + String from, + MediaBody body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + String clientReference, + Boolean feedbackEnabled, + Parameters parameters, + Boolean strictValidation) { + super( + to, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled); + this.parameters = parameters; + this.strictValidation = strictValidation; + } + + public Optional getParameters() { + return Optional.ofNullable(parameters); + } + + public Optional isStrictValidation() { + return Optional.ofNullable(strictValidation); + } + + @Override + public String toString() { + return "SendSmsBatchMediaRequest{" + + "parameters=" + + parameters + + ", strictValidation=" + + strictValidation + + ", base='" + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends BaseBatch.Builder { + private Parameters parameters; + private Boolean strictValidation; + + private Builder() {} + + public Builder setParameters(Parameters parameters) { + this.parameters = parameters; + return this; + } + + public Builder setStrictValidation(Boolean strictValidation) { + this.strictValidation = strictValidation; + return this; + } + + public SendSmsBatchMediaRequest build() { + return new SendSmsBatchMediaRequest( + to, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + parameters, + strictValidation); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchTextRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchTextRequest.java new file mode 100644 index 00000000..5e999643 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchTextRequest.java @@ -0,0 +1,185 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.BaseBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.Parameters; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class SendSmsBatchTextRequest extends BaseBatch { + private final Boolean flashMessage; + private final Parameters parameters; + private final Boolean truncateConcat; + private final Integer maxNumberOfMessageParts; + private final Integer fromTon; + private final Integer fromNpi; + /** + * @param to List of Phone numbers and group IDs that will receive the batch + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param clientReference The client identifier of a batch message. If set, the identifier will be + * added in the delivery report/callback of this batch + * @param feedbackEnabled If set to true, then feedback is expected after successful delivery. + * @param parameters Contains the parameters that will be used for customizing the message for + * each recipient. + * @param flashMessage If sent as a flash message, displays true. + * @param truncateConcat If set to true, the message was shortened when exceeding one part. + * @param maxNumberOfMessageParts Displays the number of message parts set in the request. + * @param fromTon The type of number for the sender number. + * @param fromNpi Number Plan Indicator for the sender number. + */ + public SendSmsBatchTextRequest( + Collection to, + String from, + String body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + String clientReference, + Boolean flashMessage, + Boolean feedbackEnabled, + Parameters parameters, + Boolean truncateConcat, + Integer maxNumberOfMessageParts, + Integer fromTon, + Integer fromNpi) { + super( + to, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled); + this.flashMessage = flashMessage; + this.parameters = parameters; + this.truncateConcat = truncateConcat; + this.maxNumberOfMessageParts = maxNumberOfMessageParts; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + } + + public Optional getParameters() { + return Optional.ofNullable(parameters); + } + + public Optional isFlashMessage() { + return Optional.ofNullable(flashMessage); + } + + public Optional isTruncateConcat() { + return Optional.ofNullable(truncateConcat); + } + + public Optional getMaxNumberOfMessageParts() { + return Optional.ofNullable(maxNumberOfMessageParts); + } + + public Optional getFromTon() { + return Optional.ofNullable(fromTon); + } + + public Optional getFromNpi() { + return Optional.ofNullable(fromNpi); + } + + @Override + public String toString() { + return "SendSmsBatchTextRequest{" + + "flashMessage=" + + flashMessage + + ", parameters=" + + parameters + + ", truncateConcat=" + + truncateConcat + + ", maxNumberOfMessageParts=" + + maxNumberOfMessageParts + + ", fromTon=" + + fromTon + + ", fromNpi=" + + fromNpi + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends BaseBatch.Builder { + private Boolean flashMessage; + private Parameters parameters; + private Boolean truncateConcat; + private Integer maxNumberOfMessageParts; + private Integer fromTon; + private Integer fromNpi; + + private Builder() {} + + public Builder setFlashMessage(boolean flashMessage) { + this.flashMessage = flashMessage; + return this; + } + + public Builder setParameters(Parameters parameters) { + this.parameters = parameters; + return this; + } + + public Builder setTruncateConcat(Boolean truncateConcat) { + this.truncateConcat = truncateConcat; + return this; + } + + public Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts) { + this.maxNumberOfMessageParts = maxNumberOfMessageParts; + return this; + } + + public Builder setFromTon(Integer fromTon) { + this.fromTon = fromTon; + return this; + } + + public Builder setFromNpi(Integer fromNpi) { + this.fromNpi = fromNpi; + return this; + } + + public SendSmsBatchTextRequest build() { + return new SendSmsBatchTextRequest( + to, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + flashMessage, + feedbackEnabled, + parameters, + truncateConcat, + maxNumberOfMessageParts, + fromTon, + fromNpi); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateBaseBatchRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateBaseBatchRequest.java new file mode 100644 index 00000000..d958b9a6 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateBaseBatchRequest.java @@ -0,0 +1,200 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +/** + * Base class for Batch types + * + * @param Type of batch + * @since 1.0 + */ +public class UpdateBaseBatchRequest { + + private final String from; + + private final T body; + + private final Collection toAdd; + + private final Collection toRemove; + + private final DeliveryReportType deliveryReport; + + private final Instant sendAt; + + private final Instant expireAt; + + private final String callbackUrl; + + /** + * @param toAdd List of phone numbers and group IDs to add to the batch. + * @param toRemove List of phone numbers and group IDs to remove from the batch. + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + */ + public UpdateBaseBatchRequest( + Collection toAdd, + Collection toRemove, + String from, + T body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl) { + this.toAdd = toAdd; + this.toRemove = toRemove; + this.from = from; + this.body = body; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + } + + public static BatchBuilder batchBuilder() { + return new BatchBuilder<>(); + } + + public Optional> getToAdd() { + return Optional.ofNullable(toAdd); + } + + public Optional> getToRemove() { + return Optional.ofNullable(toRemove); + } + + public Optional getBody() { + return Optional.ofNullable(body); + } + + public Optional getFrom() { + return Optional.ofNullable(from); + } + + public Optional getDeliveryReport() { + return Optional.ofNullable(deliveryReport); + } + + public Optional getSendAt() { + return Optional.ofNullable(sendAt); + } + + public Optional getExpireAt() { + return Optional.ofNullable(expireAt); + } + + public Optional getCallbackUrl() { + return Optional.ofNullable(callbackUrl); + } + + @Override + public String toString() { + return "UpdateBaseBatchRequest{" + + "from='" + + from + + '\'' + + ", body=" + + body + + ", toAdd=" + + toAdd + + ", toRemove=" + + toRemove + + ", deliveryReportType=" + + deliveryReport + + ", sendAt=" + + sendAt + + ", expireAt=" + + expireAt + + ", callbackUrl='" + + callbackUrl + + '\'' + + '}'; + } + + protected static class Builder> { + + public Collection toAdd; + + public Collection toRemove; + + public String from; + + public T body; + + public DeliveryReportType deliveryReportType; + + public Instant sendAt; + + public Instant expireAt; + + public String callbackUrl; + + public B setToAdd(Collection toAdd) { + this.toAdd = toAdd; + return self(); + } + + public B setToRemove(Collection toRemove) { + this.toRemove = toRemove; + return self(); + } + + public B setFrom(String from) { + this.from = from; + return self(); + } + + public B setBody(T body) { + this.body = body; + return self(); + } + + public B setDeliveryReport(DeliveryReportType deliveryReportType) { + this.deliveryReportType = deliveryReportType; + return self(); + } + + public B setSendAt(Instant sendAt) { + this.sendAt = sendAt; + return self(); + } + + public B setExpireAt(Instant expireAt) { + this.expireAt = expireAt; + return self(); + } + + public B setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + return self(); + } + + public UpdateBaseBatchRequest build() { + return new UpdateBaseBatchRequest<>( + toAdd, toRemove, from, body, deliveryReportType, sendAt, expireAt, callbackUrl); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + } + + public static class BatchBuilder extends UpdateBaseBatchRequest.Builder> { + @Override + protected BatchBuilder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchBinaryRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchBinaryRequest.java new file mode 100644 index 00000000..4369884c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchBinaryRequest.java @@ -0,0 +1,74 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class UpdateSmsBatchBinaryRequest extends UpdateBaseBatchRequest { + private final String udh; + /** + * @param toAdd List of phone numbers and group IDs to add to the batch.List of Phone numbers and + * group IDs that will receive the batch + * @param toRemove List of phone numbers and group IDs to remove from the batch + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param udh The UDH header of a binary message HEX encoded. Max 140 bytes including the body. + */ + public UpdateSmsBatchBinaryRequest( + Collection toAdd, + Collection toRemove, + String from, + String body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + String udh) { + super(toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl); + this.udh = udh; + } + + public Optional getUdh() { + return Optional.ofNullable(udh); + } + + @Override + public String toString() { + return "UpdateSmsBatchBinaryRequest{" + "udh='" + udh + '\'' + "} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends UpdateBaseBatchRequest.Builder { + + private String udh; + + private Builder() {} + + public Builder setUdh(String udh) { + this.udh = udh; + return this; + } + + public UpdateSmsBatchBinaryRequest build() { + return new UpdateSmsBatchBinaryRequest( + toAdd, toRemove, from, body, deliveryReportType, sendAt, expireAt, callbackUrl, udh); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java new file mode 100644 index 00000000..bfef62f4 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java @@ -0,0 +1,107 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.MediaBody; +import com.sinch.sdk.domains.sms.models.Parameters; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class UpdateSmsBatchMediaRequest extends UpdateBaseBatchRequest { + private final Parameters parameters; + private final Boolean strictValidation; + /** + * @param toAdd List of phone numbers and group IDs to add to the batch. + * @param body The message content + * @param toRemove List of phone numbers and group IDs to remove from the batch. + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param parameters Contains the parameters that will be used for customizing the message for + * each recipient. + * @param strictValidation Whether or not you want the media included in your message to be + * checked against Sinch MMS channel best practices. If set to true, your message will be + * rejected if it doesn't conform to the listed recommendations, otherwise no validation will + * be performed + */ + public UpdateSmsBatchMediaRequest( + Collection toAdd, + Collection toRemove, + String from, + MediaBody body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + Parameters parameters, + Boolean strictValidation) { + super(toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl); + this.parameters = parameters; + this.strictValidation = strictValidation; + } + + public Optional getParameters() { + return Optional.ofNullable(parameters); + } + + public Optional isStrictValidation() { + return Optional.ofNullable(strictValidation); + } + + @Override + public String toString() { + return "UpdateSmsBatchMediaRequest{" + + "parameters=" + + parameters + + ", strictValidation=" + + strictValidation + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends UpdateBaseBatchRequest.Builder { + private Parameters parameters; + private Boolean strictValidation; + + private Builder() {} + + public Builder setParameters(Parameters parameters) { + this.parameters = parameters; + return this; + } + + public Builder setStrictValidation(Boolean strictValidation) { + this.strictValidation = strictValidation; + return this; + } + + public UpdateSmsBatchMediaRequest build() { + return new UpdateSmsBatchMediaRequest( + toAdd, + toRemove, + from, + body, + deliveryReportType, + sendAt, + expireAt, + callbackUrl, + parameters, + strictValidation); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchTextRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchTextRequest.java new file mode 100644 index 00000000..4e58c227 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchTextRequest.java @@ -0,0 +1,82 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.Parameters; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class UpdateSmsBatchTextRequest extends UpdateBaseBatchRequest { + private final Parameters parameters; + /** + * @param toAdd List of phone numbers and group IDs to add to the batch. + * @param toRemove List of phone numbers and group IDs to remove from the batch. + * @param body The message content + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param parameters Contains the parameters that will be used for customizing the message for + * each recipient. + */ + public UpdateSmsBatchTextRequest( + Collection toAdd, + Collection toRemove, + String from, + String body, + DeliveryReportType deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + Parameters parameters) { + super(toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl); + this.parameters = parameters; + } + + public Optional getParameters() { + return Optional.ofNullable(parameters); + } + + @Override + public String toString() { + return "UpdateSmsBatchTextRequest{" + "parameters=" + parameters + "} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends UpdateBaseBatchRequest.Builder { + private Parameters parameters; + + private Builder() {} + + public Builder setParameters(Parameters parameters) { + this.parameters = parameters; + return this; + } + + public UpdateSmsBatchTextRequest build() { + return new UpdateSmsBatchTextRequest( + toAdd, + toRemove, + from, + body, + deliveryReportType, + sendAt, + expireAt, + callbackUrl, + parameters); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/package-info.java new file mode 100644 index 00000000..853a2031 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS API requests related models + * + * @since 1.0 + */ +package com.sinch.sdk.domains.sms.models.requests; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/responses/BatchesListResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/responses/BatchesListResponse.java new file mode 100644 index 00000000..072e3c92 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/responses/BatchesListResponse.java @@ -0,0 +1,50 @@ +package com.sinch.sdk.domains.sms.models.responses; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.BatchesService; +import com.sinch.sdk.domains.sms.models.Batch; +import com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters; +import java.util.Collection; +import java.util.NoSuchElementException; + +/** + * Lists batches response + * + * @since 1.0 + */ +public class BatchesListResponse extends ListResponse> { + + private final Page, Integer> page; + private final BatchesService service; + + public BatchesListResponse( + BatchesService service, Page, Integer> page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + return (null != page.getNextPageToken() && null != page.getNextPageToken().getToken()); + } + + public BatchesListResponse nextPage() { + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + BatchesListRequestParameters.Builder newParameters = + BatchesListRequestParameters.builder(page.getParameters()); + Integer nextToken = page.getNextPageToken().getToken(); + newParameters.setPage(nextToken); + return service.list(newParameters.build()); + } + + public Collection> getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "ActiveNumberListResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/responses/DeliveryReportsListResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/responses/DeliveryReportsListResponse.java new file mode 100644 index 00000000..37f28176 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/responses/DeliveryReportsListResponse.java @@ -0,0 +1,51 @@ +package com.sinch.sdk.domains.sms.models.responses; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.DeliveryReportsService; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; +import java.util.Collection; +import java.util.NoSuchElementException; + +/** + * Lists batches response + * + * @since 1.0 + */ +public class DeliveryReportsListResponse extends ListResponse { + + private final Page page; + private final DeliveryReportsService service; + + public DeliveryReportsListResponse( + DeliveryReportsService service, + Page page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + return (null != page.getNextPageToken() && null != page.getNextPageToken().getToken()); + } + + public DeliveryReportsListResponse nextPage() { + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + DeliveryReportListRequestParameters.Builder newParameters = + DeliveryReportListRequestParameters.builder(page.getParameters()); + Integer nextToken = page.getNextPageToken().getToken(); + newParameters.setPage(nextToken); + return service.list(newParameters.build()); + } + + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "DeliveryReportsListResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/responses/GroupsListResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/responses/GroupsListResponse.java new file mode 100644 index 00000000..bc8f5a11 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/responses/GroupsListResponse.java @@ -0,0 +1,50 @@ +package com.sinch.sdk.domains.sms.models.responses; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.GroupsService; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.requests.GroupsListRequestParameters; +import java.util.Collection; +import java.util.NoSuchElementException; + +/** + * Groups List response + * + * @since 1.0 + */ +public class GroupsListResponse extends ListResponse { + + private final Page page; + private final GroupsService service; + + public GroupsListResponse( + GroupsService service, Page page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + return (null != page.getNextPageToken() && null != page.getNextPageToken().getToken()); + } + + public GroupsListResponse nextPage() { + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + GroupsListRequestParameters.Builder newParameters = + GroupsListRequestParameters.builder(page.getParameters()); + Integer nextToken = page.getNextPageToken().getToken(); + newParameters.setPage(nextToken); + return service.list(newParameters.build()); + } + + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "GroupsListResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/responses/InboundsListResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/responses/InboundsListResponse.java new file mode 100644 index 00000000..e716ec4f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/responses/InboundsListResponse.java @@ -0,0 +1,50 @@ +package com.sinch.sdk.domains.sms.models.responses; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.InboundsService; +import com.sinch.sdk.domains.sms.models.Inbound; +import com.sinch.sdk.domains.sms.models.requests.InboundsListRequestParameters; +import java.util.Collection; +import java.util.NoSuchElementException; + +/** + * List Incoming Messages response + * + * @since 1.0 + */ +public class InboundsListResponse extends ListResponse> { + + private final Page, Integer> page; + private final InboundsService service; + + public InboundsListResponse( + InboundsService service, Page, Integer> page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + return (null != page.getNextPageToken() && null != page.getNextPageToken().getToken()); + } + + public InboundsListResponse nextPage() { + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + InboundsListRequestParameters.Builder newParameters = + InboundsListRequestParameters.builder(page.getParameters()); + Integer nextToken = page.getNextPageToken().getToken(); + newParameters.setPage(nextToken); + return service.list(newParameters.build()); + } + + public Collection> getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "InboundsListResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/responses/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/responses/package-info.java new file mode 100644 index 00000000..d1d64f4d --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/responses/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS API responses related models + * + * @since 1.0 + */ +package com.sinch.sdk.domains.sms.models.responses; diff --git a/client/src/main/com/sinch/sdk/models/SMSRegion.java b/client/src/main/com/sinch/sdk/models/SMSRegion.java index c198f604..a8de1ba6 100644 --- a/client/src/main/com/sinch/sdk/models/SMSRegion.java +++ b/client/src/main/com/sinch/sdk/models/SMSRegion.java @@ -14,7 +14,7 @@ * href="https://developers.sinch.com/docs/sms/api-reference/#base-url/">https://developers.sinch.com/docs/sms/api-reference/#base-url/ * @since 1.0 */ -public class SMSRegion extends EnumDynamic { +public class SMSRegion extends EnumDynamic { /** United States */ public static final SMSRegion US = new SMSRegion("us"); @@ -28,7 +28,7 @@ public class SMSRegion extends EnumDynamic { /** Canada */ public static final SMSRegion CA = new SMSRegion("ca"); - private static final EnumSupportDynamic ENUM_SUPPORT = + private static final EnumSupportDynamic ENUM_SUPPORT = new EnumSupportDynamic<>(SMSRegion.class, SMSRegion::new, Arrays.asList(US, EU, AU, BR, CA)); private SMSRegion(String value) { diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java index 4a9ed4e0..63a0d928 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.sms.adapters; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; @@ -9,42 +10,66 @@ import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.utils.Pair; import com.sinch.sdk.domains.sms.adapters.api.v1.BatchesApi; -import com.sinch.sdk.domains.sms.models.*; +import com.sinch.sdk.domains.sms.adapters.converters.BatchDtoConverter; +import com.sinch.sdk.domains.sms.adapters.converters.DryRunDtoConverterTest; +import com.sinch.sdk.domains.sms.models.Batch; +import com.sinch.sdk.domains.sms.models.BatchBinary; +import com.sinch.sdk.domains.sms.models.BatchMedia; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.DryRun; +import com.sinch.sdk.domains.sms.models.MediaBody; +import com.sinch.sdk.domains.sms.models.Parameters; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiDeliveryFeedbackDto; +import com.sinch.sdk.domains.sms.models.dto.v1.DryRun200ResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjDto; import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjParameterKeyDto; import com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchBinaryRequest; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchMediaRequest; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchBinaryRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchMediaRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchTextRequest; +import com.sinch.sdk.domains.sms.models.responses.BatchesListResponse; import com.sinch.sdk.models.Configuration; import java.time.Instant; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; @TestWithResources public class BatchesServiceTest extends BaseTest { - final String id = "01FC66621XXXXX119Z8PMV1QPQ"; - final Collection to = Arrays.asList("+15551231234", "+15551256344"); - final String from = "+15551231234"; - final boolean canceled = false; - final Instant createdAt = Instant.parse("2019-08-24T14:15:22Z"); - final Instant modifiedAt = Instant.parse("2019-08-24T14:17:22Z"); - final DeliveryReport deliveryReport = DeliveryReport.NONE; - final Instant sendAt = Instant.parse("2019-08-24T14:19:22Z"); - final Instant expireAt = Instant.parse("2019-08-24T14:21:22Z"); - final String callbackUrl = "callback url"; - final String clientReference = "myReference"; - final boolean flashMessage = true; - final boolean feedbackEnabled = false; - final boolean truncateConcat = true; - final int maxNumberOfMessageParts = 1; - final int fromTon = 6; - final int fromNpi = 18; - final String udh = "foo udh"; - final String body = "Hi ${name}! How are you?"; - public final BatchBinary batchBinary = + static final String id = "01FC66621XXXXX119Z8PMV1QPQ"; + static final Collection to = Arrays.asList("+15551231234", "+15551256344"); + static final String from = "+15551231234"; + static final boolean canceled = false; + static final Instant createdAt = Instant.parse("2019-08-24T14:15:22Z"); + static final Instant modifiedAt = Instant.parse("2019-08-24T14:17:22Z"); + static final DeliveryReportType deliveryReport = DeliveryReportType.NONE; + static final Instant sendAt = Instant.parse("2019-08-24T14:19:22Z"); + static final Instant expireAt = Instant.parse("2019-08-24T14:21:22Z"); + static final String callbackUrl = "callback url"; + static final String clientReference = "myReference"; + static final boolean flashMessage = true; + static final boolean feedbackEnabled = false; + static final boolean truncateConcat = true; + static final int maxNumberOfMessageParts = 1; + static final int fromTon = 6; + static final int fromNpi = 18; + static final String udh = "foo udh"; + static final String body = "Hi ${name}! How are you?"; + public static final BatchBinary batchBinary = BatchBinary.builder() .setId(id) .setTo(to) @@ -66,7 +91,7 @@ public class BatchesServiceTest extends BaseTest { .setFromNpi(fromNpi) .setUdh(udh) .build(); - final Parameters parameters = + static final Parameters parameters = new Parameters( Arrays.asList( new Parameters.Entry("an identifier", new Pair<>("a key", "a value")), @@ -90,7 +115,7 @@ public class BatchesServiceTest extends BaseTest { "Media message from Sinch!")) .setCreatedAt(Instant.parse("2019-08-24T14:14:22Z")) .setModifiedAt(Instant.parse("2019-08-24T14:15:22Z")) - .setDeliveryReport(DeliveryReport.SUMMARY) + .setDeliveryReport(DeliveryReportType.SUMMARY) .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) .setCallbackUrl(callbackUrl) @@ -121,6 +146,102 @@ public class BatchesServiceTest extends BaseTest { .setParameters(parameters) .build(); + public static final SendSmsBatchBinaryRequest sendSmsBatchBinaryRequest = + SendSmsBatchBinaryRequest.builder() + .setTo(to) + .setFrom(from) + .setBody(body) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setClientReference(clientReference) + .setFlashMessage(flashMessage) + .setFeedbackEnabled(feedbackEnabled) + .setTruncateConcat(truncateConcat) + .setMaxNumberOfMessageParts(maxNumberOfMessageParts) + .setFromTon(fromTon) + .setFromNpi(fromNpi) + .setUdh(udh) + .build(); + + public static final SendSmsBatchMediaRequest sendSmsBatchMediaRequest = + SendSmsBatchMediaRequest.builder() + .setTo(to) + .setFrom(from) + .setBody( + new MediaBody( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", + "Media message from Sinch!")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl(callbackUrl) + .setClientReference("client reference") + .setFeedbackEnabled(feedbackEnabled) + .setStrictValidation(true) + .setParameters(parameters) + .build(); + public static final SendSmsBatchTextRequest sendSmsBatchTextRequest = + SendSmsBatchTextRequest.builder() + .setTo(to) + .setFrom(from) + .setBody(body) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setClientReference(clientReference) + .setFlashMessage(flashMessage) + .setFeedbackEnabled(feedbackEnabled) + .setTruncateConcat(truncateConcat) + .setMaxNumberOfMessageParts(maxNumberOfMessageParts) + .setFromTon(fromTon) + .setFromNpi(fromNpi) + .setParameters(parameters) + .build(); + + public static final UpdateSmsBatchTextRequest updateSmsBatchTextRequest = + UpdateSmsBatchTextRequest.builder() + .setToAdd(to) + .setFrom(from) + .setBody(body) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setParameters(parameters) + .build(); + + public static final UpdateSmsBatchMediaRequest updateSmsBatchMediaRequest = + UpdateSmsBatchMediaRequest.builder() + .setToRemove(to) + .setFrom(from) + .setBody( + new MediaBody( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", + "Media message from Sinch!")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl(callbackUrl) + .setStrictValidation(true) + .setParameters(parameters) + .build(); + + public static final UpdateSmsBatchBinaryRequest updateSmsBatchBinaryRequest = + UpdateSmsBatchBinaryRequest.builder() + .setToAdd(Arrays.asList("+15551231234", "+15987365412")) + .setToRemove(Arrays.asList("+0123456789", "+9876543210")) + .setFrom(from) + .setBody(body) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setUdh(udh) + .build(); + @GivenJsonResource("/domains/sms/v1/BinaryResponseDto.json") public SendSMS201ResponseDto binaryResponseDto; @@ -130,10 +251,21 @@ public class BatchesServiceTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/TextResponseDto.json") SendSMS201ResponseDto textResponseDto; + @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") + DryRun200ResponseDto dryRunResponseDto; + + @GivenJsonResource("/domains/sms/v1/ListBatchesResponseDtoPage0.json") + ApiBatchListDto listBatchesResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/ListBatchesResponseDtoPage1.json") + ApiBatchListDto listBatchesResponseDtoPage1; + @Mock Configuration configuration; @Mock BatchesApi api; @InjectMocks BatchesService service; + @Captor ArgumentCaptor recipientsCaptor; + @Test void getBinary() throws ApiException { @@ -166,4 +298,250 @@ void getText() throws ApiException { Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText); } + + @Test + void sendBinary() throws ApiException { + + when(api.sendSMS( + eq(configuration.getProjectId()), + eq(BatchDtoConverter.convert(sendSmsBatchBinaryRequest)))) + .thenReturn(binaryResponseDto); + + Batch response = service.send(sendSmsBatchBinaryRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchBinary); + } + + @Test + void sendMedia() throws ApiException { + + when(api.sendSMS( + eq(configuration.getProjectId()), + eq(BatchDtoConverter.convert(sendSmsBatchMediaRequest)))) + .thenReturn(mediaResponseDto); + + Batch response = service.send(sendSmsBatchMediaRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchMedia); + } + + @Test + void sendText() throws ApiException { + + when(api.sendSMS( + eq(configuration.getProjectId()), + eq(BatchDtoConverter.convert(sendSmsBatchTextRequest)))) + .thenReturn(textResponseDto); + + Batch response = service.send(sendSmsBatchTextRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText); + } + + @Test + void dryRun() throws ApiException { + + when(api.dryRun( + eq(configuration.getProjectId()), + eq(true), + eq(456), + eq(BatchDtoConverter.convert(sendSmsBatchTextRequest)))) + .thenReturn(dryRunResponseDto); + + DryRun response = service.dryRun(true, 456, sendSmsBatchTextRequest); + + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(DryRunDtoConverterTest.dryRunClient); + } + + @Test + void list() throws ApiException { + + when(api.listBatches( + eq(configuration.getProjectId()), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null))) + .thenReturn(listBatchesResponseDtoPage0); + when(api.listBatches( + eq(configuration.getProjectId()), + eq(1), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null))) + .thenReturn(listBatchesResponseDtoPage1); + + BatchesListResponse response = service.list(null); + + Iterator> iterator = response.autoPageIter(); + Batch batch = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + Assertions.assertThat(batch) + .usingRecursiveComparison() + .isEqualTo( + BatchBinary.builder() + .setId("01HEAWCHESCXG8SDG5R10VF8E1") + .setTo(Collections.singletonList("339876543213")) + .setFrom("33123456789") + .setCanceled(false) + .setBody("the body") + .setCreatedAt(Instant.parse("2023-11-03T15:21:21.113Z")) + .setModifiedAt(Instant.parse("2023-11-03T15:21:21.568Z")) + .setDeliveryReport(DeliveryReportType.NONE) + .setExpireAt(Instant.parse("2023-11-06T15:21:21.973Z")) + .setClientReference("a client reference") + .setFeedbackEnabled(false) + .setFlashMessage(false) + .build()); + + batch = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + Assertions.assertThat(batch) + .usingRecursiveComparison() + .isEqualTo( + BatchText.builder() + .setId("01HEAC0AG69SVYYQ675VPYT28Q") + .setTo(Collections.singletonList("3300000000")) + .setCanceled(false) + .setBody("the body") + .setCreatedAt(Instant.parse("2023-11-03T10:35:03.558Z")) + .setModifiedAt(Instant.parse("2023-11-03T10:35:03.666Z")) + .setDeliveryReport(DeliveryReportType.NONE) + .setExpireAt(Instant.parse("2023-11-03T10:35:03.558Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build()); + + batch = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + Assertions.assertThat(batch) + .usingRecursiveComparison() + .isEqualTo( + BatchMedia.builder() + .setId("01HEABZ9S80D4ENE3X6CPMATZR") + .setTo(Collections.singletonList("331111111")) + .setCanceled(false) + .setBody(MediaBody.builder().setUrl("an URL").build()) + .setCreatedAt(Instant.parse("2023-11-03T10:34:30.056Z")) + .setModifiedAt(Instant.parse("2023-11-03T10:34:30.156Z")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setExpireAt(Instant.parse("2023-11-06T10:34:30.256Z")) + .setFeedbackEnabled(false) + .build()); + } + + @Test + void updateText() throws ApiException { + + when(api.updateBatchMessage( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(updateSmsBatchTextRequest)))) + .thenReturn(textResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchTextRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText); + } + + @Test + void updateMedia() throws ApiException { + + when(api.updateBatchMessage( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(updateSmsBatchMediaRequest)))) + .thenReturn(mediaResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchMediaRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchMedia); + } + + @Test + void updateBinary() throws ApiException { + + when(api.updateBatchMessage( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(updateSmsBatchBinaryRequest)))) + .thenReturn(binaryResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchBinaryRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchBinary); + } + + @Test + void replaceBinary() throws ApiException { + + when(api.replaceBatch( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(sendSmsBatchBinaryRequest)))) + .thenReturn(binaryResponseDto); + + Batch response = service.replace("foo text batch id", sendSmsBatchBinaryRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchBinary); + } + + @Test + void replaceMedia() throws ApiException { + + when(api.replaceBatch( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(sendSmsBatchMediaRequest)))) + .thenReturn(mediaResponseDto); + + Batch response = service.replace("foo text batch id", sendSmsBatchMediaRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchMedia); + } + + @Test + void replaceText() throws ApiException { + + when(api.replaceBatch( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(sendSmsBatchTextRequest)))) + .thenReturn(textResponseDto); + + Batch response = service.replace("foo text batch id", sendSmsBatchTextRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText); + } + + @Test + void cancelBatch() throws ApiException { + + when(api.cancelBatchMessage(eq(configuration.getProjectId()), eq("foo text batch id"))) + .thenReturn(textResponseDto); + + Batch response = service.cancel("foo text batch id"); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText); + } + + @Test + void sendDeliveryFeedback() throws ApiException { + List recipients = Arrays.asList("foo", "foo2"); + + service.sendDeliveryFeedback("foo text batch id", recipients); + + verify(api) + .deliveryFeedback( + eq(configuration.getProjectId()), eq("foo text batch id"), recipientsCaptor.capture()); + + ApiDeliveryFeedbackDto dto = recipientsCaptor.getValue(); + Assertions.assertThat(dto.getRecipients()).usingRecursiveComparison().isEqualTo(recipients); + } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/DeliveryReportsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/DeliveryReportsServiceTest.java new file mode 100644 index 00000000..6242b457 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/DeliveryReportsServiceTest.java @@ -0,0 +1,236 @@ +package com.sinch.sdk.domains.sms.adapters; + +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.adapters.api.v1.DeliveryReportsApi; +import com.sinch.sdk.domains.sms.adapters.converters.DeliveryReportDtoConverter; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchMMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportErrorCode; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientEncoding; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientMMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportDto; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.RecipientDeliveryReportDto; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportBatchGetRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.DeliveryReportsListResponse; +import com.sinch.sdk.models.Configuration; +import java.time.Instant; +import java.util.Arrays; +import java.util.Iterator; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +@TestWithResources +class DeliveryReportsServiceTest extends BaseTest { + + @Mock Configuration configuration; + @Mock DeliveryReportsApi api; + @InjectMocks DeliveryReportsService service; + + @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + DeliveryReportDto deliveryReportBatchSMSDto; + + @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + DeliveryReportDto deliveryReportBatchMMSDto; + + @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") + RecipientDeliveryReportDto deliveryReportRecipientSMSDto; + + @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientMMSDto.json") + RecipientDeliveryReportDto deliveryReportRecipientMMSDto; + + @GivenJsonResource("/domains/sms/v1/ListDeliveryReportResponseDtoPage0.json") + DeliveryReportListDto listDeliveryReportResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/ListDeliveryReportResponseDtoPage1.json") + DeliveryReportListDto listDeliveryReportResponseDtoPage1; + + @Test + void getDeliveryReportBatchSMS() throws ApiException { + + when(api.getDeliveryReportByBatchId( + eq(configuration.getProjectId()), + eq("foo binary batch id"), + eq("foo type"), + eq("foo status1,Cancelled"), + eq("456,789"))) + .thenReturn(deliveryReportBatchSMSDto); + + DeliveryReportBatch response = + service.get( + "foo binary batch id", + DeliveryReportBatchGetRequestParameters.builder() + .setType(DeliveryReportType.from("foo type")) + .setStatuses( + Arrays.asList( + DeliveryReportStatus.from("foo status1"), DeliveryReportStatus.CANCELLED)) + .setCodes(Arrays.asList(456, 789)) + .build()); + + assertInstanceOf(DeliveryReportBatchSMS.class, response); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(DeliveryReportDtoConverter.convert(deliveryReportBatchSMSDto)); + } + + @Test + void getDeliveryReportBatchMMS() throws ApiException { + + when(api.getDeliveryReportByBatchId( + eq(configuration.getProjectId()), + eq("foo binary batch id"), + eq("foo type"), + eq("foo status1,Cancelled"), + eq("456,789"))) + .thenReturn(deliveryReportBatchMMSDto); + + DeliveryReportBatch response = + service.get( + "foo binary batch id", + DeliveryReportBatchGetRequestParameters.builder() + .setType(DeliveryReportType.from("foo type")) + .setStatuses( + Arrays.asList( + DeliveryReportStatus.from("foo status1"), DeliveryReportStatus.CANCELLED)) + .setCodes(Arrays.asList(456, 789)) + .build()); + + assertInstanceOf(DeliveryReportBatchMMS.class, response); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(DeliveryReportDtoConverter.convert(deliveryReportBatchMMSDto)); + } + + @Test + void getDeliveryReportRecipientSMS() throws ApiException { + + when(api.getDeliveryReportByPhoneNumber( + eq(configuration.getProjectId()), eq("foo binary batch id"), eq("foo number"))) + .thenReturn(deliveryReportRecipientSMSDto); + + DeliveryReportRecipient response = service.getForNumber("foo binary batch id", "foo number"); + + assertInstanceOf(DeliveryReportRecipientSMS.class, response); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(DeliveryReportDtoConverter.convert(deliveryReportRecipientSMSDto)); + } + + @Test + void getDeliveryReportRecipientMMS() throws ApiException { + + when(api.getDeliveryReportByPhoneNumber( + eq(configuration.getProjectId()), eq("foo binary batch id"), eq("foo number"))) + .thenReturn(deliveryReportRecipientMMSDto); + + DeliveryReportRecipient response = service.getForNumber("foo binary batch id", "foo number"); + + assertInstanceOf(DeliveryReportRecipientMMS.class, response); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(DeliveryReportDtoConverter.convert(deliveryReportRecipientMMSDto)); + } + + @Test + void list() throws ApiException { + + when(api.getDeliveryReports( + eq(configuration.getProjectId()), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null))) + .thenReturn(listDeliveryReportResponseDtoPage0); + when(api.getDeliveryReports( + eq(configuration.getProjectId()), + eq(1), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null))) + .thenReturn(listDeliveryReportResponseDtoPage1); + + DeliveryReportsListResponse response = service.list(null); + + Iterator iterator = response.autoPageIter(); + DeliveryReportRecipient item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + + assertInstanceOf(DeliveryReportRecipientSMS.class, item); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + DeliveryReportRecipientSMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setRecipient("+44231235674") + .setCode(DeliveryReportErrorCode.from(401)) + .setStatus(DeliveryReportStatus.DISPATCHED) + .setAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setOperator("operator") + .setAppliedOriginator("applied originator") + .setClientReference("client reference") + .setEncoding(DeliveryReportRecipientEncoding.from("encoding")) + .setNumberOfMessageParts(123) + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + assertInstanceOf(DeliveryReportRecipientMMS.class, item); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + DeliveryReportRecipientMMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setRecipient("+44231235674") + .setCode(DeliveryReportErrorCode.DISPATCHED) + .setStatus(DeliveryReportStatus.DISPATCHED) + .setAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setOperator("operator") + .setAppliedOriginator("applied originator") + .setClientReference("client reference") + .setEncoding(DeliveryReportRecipientEncoding.from("encoding")) + .setNumberOfMessageParts(123) + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + assertInstanceOf(DeliveryReportRecipientSMS.class, item); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + DeliveryReportRecipientSMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setRecipient("+44231235674") + .setCode(DeliveryReportErrorCode.from(401)) + .setStatus(DeliveryReportStatus.DISPATCHED) + .setAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setOperator("operator") + .setAppliedOriginator("applied originator") + .setClientReference("client reference") + .setEncoding(DeliveryReportRecipientEncoding.from("encoding")) + .setNumberOfMessageParts(123) + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build()); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java new file mode 100644 index 00000000..d08edb55 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java @@ -0,0 +1,222 @@ +package com.sinch.sdk.domains.sms.adapters; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.adapters.api.v1.GroupsApi; +import com.sinch.sdk.domains.sms.adapters.converters.GroupsDtoConverter; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.GroupAutoUpdate; +import com.sinch.sdk.domains.sms.models.GroupAutoUpdateKeyword; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.CreateGroupResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ReplaceGroupRequestDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestDto; +import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.GroupsListResponse; +import com.sinch.sdk.models.Configuration; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +@TestWithResources +class GroupsServiceTest extends BaseTest { + + @Mock Configuration configuration; + @Mock GroupsApi api; + @InjectMocks GroupsService service; + + @Captor ArgumentCaptor groupIdCaptor; + + @GivenJsonResource("/domains/sms/v1/GroupResponseDto.json") + CreateGroupResponseDto createGroupResponseDto; + + @GivenJsonResource("/domains/sms/v1/GroupsListResponseDtoPage0.json") + ApiGroupListDto groupsListResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/GroupsListResponseDtoPage1.json") + ApiGroupListDto groupsListResponseDtoPage1; + + @Test + void get() throws ApiException { + + when(api.retrieveGroup(eq(configuration.getProjectId()), eq("foo group ID"))) + .thenReturn(createGroupResponseDto); + + Group response = service.get("foo group ID"); + + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(GroupsDtoConverter.convert(createGroupResponseDto)); + } + + @Test + void create() throws ApiException { + + when(api.createGroup(eq(configuration.getProjectId()), eq(new GroupObjectDto()))) + .thenReturn(createGroupResponseDto); + + Group response = service.create(null); + + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(GroupsDtoConverter.convert(createGroupResponseDto)); + } + + @Test + void list() throws ApiException { + + when(api.listGroups(eq(configuration.getProjectId()), eq(null), eq(null))) + .thenReturn(groupsListResponseDtoPage0); + when(api.listGroups(eq(configuration.getProjectId()), eq(1), eq(null))) + .thenReturn(groupsListResponseDtoPage1); + + GroupsListResponse response = service.list(null); + + Iterator iterator = response.autoPageIter(); + Group item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + Group.builder() + .setId("01FC66621XXXXX119Z8PMV1QPU") + .setName("My new customers") + .setSize(2) + .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:15:44Z")) + .setChildGroupIds( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00")) + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd( + GroupAutoUpdateKeyword.builder() + .setFirstWord("Add 1st keyword") + .build()) + .setRemove( + GroupAutoUpdateKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo(Group.builder().setId("foo id").build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + Group.builder() + .setId("01FC66621XXXXX119Z8PMV1QPU") + .setName("My new customers") + .setSize(2) + .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:15:44Z")) + .setChildGroupIds( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00")) + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd( + GroupAutoUpdateKeyword.builder() + .setFirstWord("Add 1st keyword") + .build()) + .setRemove( + GroupAutoUpdateKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .build()); + } + + @Test + void replace() throws ApiException { + + when(api.replaceGroup( + eq(configuration.getProjectId()), + eq("group id"), + eq( + new ReplaceGroupRequestDto() + .name("foo name") + .members(Collections.singletonList("foo member"))))) + .thenReturn(createGroupResponseDto); + + Group response = + service.replace( + "group id", + GroupReplaceRequestParameters.builder() + .setName("foo name") + .setMembers(Collections.singletonList("foo member")) + .build()); + + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(GroupsDtoConverter.convert(createGroupResponseDto)); + } + + @Test + void update() throws ApiException { + + when(api.updateGroup( + eq(configuration.getProjectId()), + eq("group id"), + eq(new UpdateGroupRequestDto().name("foo name")))) + .thenReturn(createGroupResponseDto); + + Group response = + service.update( + "group id", GroupUpdateRequestParameters.builder().setName("foo name").build()); + + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(GroupsDtoConverter.convert(createGroupResponseDto)); + } + + @Test + void delete() throws ApiException { + + service.delete("foo group id"); + + verify(api).deleteGroup(eq(configuration.getProjectId()), groupIdCaptor.capture()); + + String parameter = groupIdCaptor.getValue(); + Assertions.assertThat(parameter).isEqualTo("foo group id"); + } + + @Test + void listMembers() throws ApiException { + + when(api.getMembers(eq(configuration.getProjectId()), eq("group id"))) + .thenReturn(Arrays.asList("entry 1", "entry 2")); + + Collection response = service.listMembers("group id"); + + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(Arrays.asList("entry 1", "entry 2")); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java new file mode 100644 index 00000000..5e645afe --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java @@ -0,0 +1,153 @@ +package com.sinch.sdk.domains.sms.adapters; + +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.adapters.api.v1.InboundsApi; +import com.sinch.sdk.domains.sms.adapters.converters.InboundsDtoConverter; +import com.sinch.sdk.domains.sms.models.Inbound; +import com.sinch.sdk.domains.sms.models.InboundBinary; +import com.sinch.sdk.domains.sms.models.InboundText; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiInboundListDto; +import com.sinch.sdk.domains.sms.models.dto.v1.InboundDto; +import com.sinch.sdk.domains.sms.models.responses.InboundsListResponse; +import com.sinch.sdk.models.Configuration; +import java.time.Instant; +import java.util.Iterator; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +@TestWithResources +class InboundsServiceTest extends BaseTest { + + @Mock Configuration configuration; + @Mock InboundsApi api; + @InjectMocks InboundsService service; + + @GivenJsonResource("/domains/sms/v1/MOBinaryDto.json") + InboundDto binary; + + @GivenJsonResource("/domains/sms/v1/MOTextDto.json") + InboundDto text; + + @GivenJsonResource("/domains/sms/v1/InboundsListResponseDtoPage0.json") + ApiInboundListDto inboundsLisResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/InboundsListResponseDtoPage1.json") + ApiInboundListDto inboundsLisResponseDtoPage1; + + @Test + void getBinary() throws ApiException { + + when(api.retrieveInboundMessage(eq(configuration.getProjectId()), eq("foo inbound ID"))) + .thenReturn(binary); + + Inbound response = service.get("foo inbound ID"); + + assertInstanceOf(InboundBinary.class, response); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(InboundsDtoConverter.convert(binary)); + } + + @Test + void getText() throws ApiException { + + when(api.retrieveInboundMessage(eq(configuration.getProjectId()), eq("foo inbound ID"))) + .thenReturn(text); + + Inbound response = service.get("foo inbound ID"); + + assertInstanceOf(InboundText.class, response); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(InboundsDtoConverter.convert(text)); + } + + @Test + void list() throws ApiException { + + when(api.listInboundMessages( + eq(configuration.getProjectId()), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null))) + .thenReturn(inboundsLisResponseDtoPage0); + when(api.listInboundMessages( + eq(configuration.getProjectId()), + eq(1), + eq(null), + eq(null), + eq(null), + eq(null), + eq(null))) + .thenReturn(inboundsLisResponseDtoPage1); + + InboundsListResponse response = service.list(null); + + Iterator> iterator = response.autoPageIter(); + Inbound item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + + assertInstanceOf(InboundBinary.class, item); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + InboundBinary.builder() + .setBody("a body") + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .setUdh("foo udh") + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + assertInstanceOf(InboundText.class, item); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + InboundText.builder() + .setBody("a body") + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + assertInstanceOf(InboundBinary.class, item); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + InboundBinary.builder() + .setBody("a body") + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .setUdh("foo udh") + .build()); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java new file mode 100644 index 00000000..286a1269 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java @@ -0,0 +1,142 @@ +package com.sinch.sdk.domains.sms.adapters; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.exceptions.ApiMappingException; +import com.sinch.sdk.domains.sms.adapters.converters.DeliveryReportDtoConverter; +import com.sinch.sdk.domains.sms.adapters.converters.InboundsDtoConverter; +import com.sinch.sdk.domains.sms.models.BaseDeliveryReport; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchMMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientMMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientSMS; +import com.sinch.sdk.domains.sms.models.Inbound; +import com.sinch.sdk.domains.sms.models.InboundBinary; +import com.sinch.sdk.domains.sms.models.InboundText; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportBatchDtoTest; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportRecipientDtoTest; +import com.sinch.sdk.domains.sms.models.dto.v1.MOBinaryDtoTest; +import com.sinch.sdk.domains.sms.models.dto.v1.MOTextDtoTest; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; + +@TestWithResources +public class WebHooksServiceTest extends BaseTest { + + @GivenTextResource("/domains/sms/v1/MOBinaryDto.json") + String incomingSMSBinaryJsonString; + + @GivenTextResource("/domains/sms/v1/MOTextDto.json") + String incomingSMSTextJsonString; + + @GivenTextResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") + String deliveryReportRecipientSMSJsonString; + + @GivenTextResource("/domains/sms/v1/DeliveryReportRecipientMMSDto.json") + String deliveryReportRecipientMMSJsonString; + + @GivenTextResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + String deliveryReportBatchSMSJsonString; + + @GivenTextResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + String deliveryReportBatchMMSJsonString; + + @InjectMocks WebHooksService service; + + @Test + void incomingSMSBinary() throws ApiException { + + Inbound response = service.incomingSMS(incomingSMSBinaryJsonString); + + Assertions.assertThat(response).isInstanceOf(InboundBinary.class); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(InboundsDtoConverter.convert(MOBinaryDtoTest.dto)); + } + + @Test + void incomingSMSText() throws ApiException { + + Inbound response = service.incomingSMS(incomingSMSTextJsonString); + + Assertions.assertThat(response).isInstanceOf(InboundText.class); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(InboundsDtoConverter.convert(MOTextDtoTest.dto)); + } + + @Test + void handleExceptionIncomingSMS() throws ApiException { + + String jsonPayload = incomingSMSBinaryJsonString.replace("mo_binary", "foo type"); + ApiMappingException thrown = + assertThrows(ApiMappingException.class, () -> service.incomingSMS(jsonPayload)); + assertTrue(thrown.getMessage().contains(jsonPayload)); + } + + @Test + void deliveryReportRecipientDeliveryReportSms() throws ApiException { + + BaseDeliveryReport response = service.deliveryReport(deliveryReportRecipientSMSJsonString); + + Assertions.assertThat(response).isInstanceOf(DeliveryReportRecipientSMS.class); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo( + DeliveryReportDtoConverter.convert( + DeliveryReportRecipientDtoTest.deliveryReportRecipientSMS)); + } + + @Test + void deliveryReportRecipientDeliveryReportMms() throws ApiException { + + BaseDeliveryReport response = service.deliveryReport(deliveryReportRecipientMMSJsonString); + + Assertions.assertThat(response).isInstanceOf(DeliveryReportRecipientMMS.class); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo( + DeliveryReportDtoConverter.convert( + DeliveryReportRecipientDtoTest.deliveryReportRecipientMMS)); + } + + @Test + void deliveryReportBatchDeliveryReportSms() throws ApiException { + + BaseDeliveryReport response = service.deliveryReport(deliveryReportBatchSMSJsonString); + + Assertions.assertThat(response).isInstanceOf(DeliveryReportBatchSMS.class); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo( + DeliveryReportDtoConverter.convert(DeliveryReportBatchDtoTest.deliveryReportBatchSMS)); + } + + @Test + void deliveryReportBatchDeliveryReportMms() throws ApiException { + + BaseDeliveryReport response = service.deliveryReport(deliveryReportBatchMMSJsonString); + + Assertions.assertThat(response).isInstanceOf(DeliveryReportBatchMMS.class); + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo( + DeliveryReportDtoConverter.convert(DeliveryReportBatchDtoTest.deliveryReportBatchMMS)); + } + + @Test + void handleExceptionDeliveryReport() throws ApiException { + + String jsonPayload = + deliveryReportRecipientMMSJsonString.replace("recipient_delivery_report_mms", "foo type"); + ApiMappingException thrown = + assertThrows(ApiMappingException.class, () -> service.deliveryReport(jsonPayload)); + assertTrue(thrown.getMessage().contains(jsonPayload)); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java index ded49e62..c25e5605 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java @@ -1,13 +1,30 @@ package com.sinch.sdk.domains.sms.adapters.converters; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.utils.Pair; -import com.sinch.sdk.domains.sms.models.*; -import com.sinch.sdk.domains.sms.models.dto.v1.*; +import com.sinch.sdk.domains.sms.adapters.BatchesServiceTest; +import com.sinch.sdk.domains.sms.models.Batch; +import com.sinch.sdk.domains.sms.models.BatchBinary; +import com.sinch.sdk.domains.sms.models.BatchMedia; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.Parameters; +import com.sinch.sdk.domains.sms.models.dto.v1.BinaryResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.MediaResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjParameterKeyDto; +import com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.SendSMSRequestDto; +import com.sinch.sdk.domains.sms.models.dto.v1.TextResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateBatchMessageRequestDto; +import java.util.Arrays; import java.util.Collection; import java.util.Map; import java.util.Optional; @@ -26,6 +43,24 @@ class BatchDtoConverterTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/MediaResponseDto.json") public SendSMS201ResponseDto mediaResponseDto; + @GivenJsonResource("/domains/sms/v1/SendSMSBinaryRequestDto.json") + public SendSMSRequestDto sendBinaryRequestDto; + + @GivenJsonResource("/domains/sms/v1/SendSMSTextRequestDto.json") + public SendSMSRequestDto sendTextRequestDto; + + @GivenJsonResource("/domains/sms/v1/SendSMSMediaRequestDto.json") + public SendSMSRequestDto sendMediaRequestDto; + + @GivenJsonResource("/domains/sms/v1/UpdateSMSTextRequestDto.json") + public UpdateBatchMessageRequestDto updateTextRequestDto; + + @GivenJsonResource("/domains/sms/v1/UpdateSMSMediaRequestDto.json") + public UpdateBatchMessageRequestDto updateMediaRequestDto; + + @GivenJsonResource("/domains/sms/v1/UpdateSMSBinaryRequestDto.json") + public UpdateBatchMessageRequestDto updateBinaryRequestDto; + public static void compareWithDto(Batch client, SendSMS201ResponseDto dto) { Object obj = dto.getActualInstance(); if (obj instanceof BinaryResponseDto) { @@ -70,8 +105,8 @@ private static void compareMedia(BatchMedia client, MediaResponseDto dto) { assertEquals(dto.getTo(), client.getTo()); assertEquals(dto.getFrom(), client.getFrom()); assertEquals(dto.getCanceled(), client.isCanceled()); - assertEquals(dto.getBody().getMessage(), client.getBody().getMessage()); assertEquals(dto.getBody().getUrl(), client.getBody().getUrl()); + assertEquals(dto.getBody().getMessage(), client.getBody().getMessage().get()); assertEquals(dto.getType(), MediaResponseDto.TypeEnum.MT_MEDIA.getValue()); assertEquals(dto.getCreatedAt().toInstant(), client.getCreatedAt()); assertEquals(dto.getModifiedAt().toInstant(), client.getModifiedAt()); @@ -129,17 +164,74 @@ private static void compareParameters(Parameters client, ParameterObjDto dto) { } @Test - void convertBinary() { + void convertBinaryResponse() { compareWithDto(BatchDtoConverter.convert(binaryResponseDto), binaryResponseDto); } @Test - void convertMedia() { + void convertMediaResponse() { compareWithDto(BatchDtoConverter.convert(mediaResponseDto), mediaResponseDto); } @Test - void convertText() { + void convertTextResponse() { compareWithDto(BatchDtoConverter.convert(textResponseDto), textResponseDto); } + + @Test + void convertSendBinaryRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.sendSmsBatchBinaryRequest)) + .usingRecursiveComparison() + .isEqualTo(sendBinaryRequestDto); + } + + @Test + void convertSendtediaRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.sendSmsBatchMediaRequest)) + .usingRecursiveComparison() + .isEqualTo(sendMediaRequestDto); + } + + @Test + void convertSendTextRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.sendSmsBatchTextRequest)) + .usingRecursiveComparison() + .isEqualTo(sendTextRequestDto); + } + + @Test + void convertUpdateTextRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchTextRequest)) + .usingRecursiveComparison() + .isEqualTo(updateTextRequestDto); + } + + @Test + void convertUpdateMediaRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchMediaRequest)) + .usingRecursiveComparison() + .isEqualTo(updateMediaRequestDto); + } + + @Test + void convertUpdateBinaryRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchBinaryRequest)) + .usingRecursiveComparison() + .isEqualTo(updateBinaryRequestDto); + } + + @Test + void convertDeliveryFeedbackRecipients() { + Collection recipients = Arrays.asList("foo1", "foo2"); + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(recipients).getRecipients()) + .usingRecursiveComparison() + .isEqualTo(recipients); + } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportBatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportBatchDtoConverterTest.java new file mode 100644 index 00000000..789d6416 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportBatchDtoConverterTest.java @@ -0,0 +1,76 @@ +package com.sinch.sdk.domains.sms.adapters.converters; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchMMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatusDetails; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportDto; +import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportDto.TypeEnum; +import com.sinch.sdk.domains.sms.models.dto.v1.MessageDeliveryStatusDto; +import java.rmi.UnexpectedException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Objects; +import org.junit.jupiter.api.Test; + +@TestWithResources +class DeliveryReportBatchDtoConverterTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + DeliveryReportDto deliveryReportSMSClientDto; + + @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + DeliveryReportDto deliveryReportMMSClientDto; + + public static void compareWithDto( + DeliveryReportStatusDetails client, MessageDeliveryStatusDto dto) { + assertEquals(dto.getCode(), client.getCode()); + assertEquals(dto.getCount(), client.getCount()); + assertEquals(dto.getRecipients(), client.getRecipients()); + assertEquals(dto.getStatus(), client.getStatus().value()); + } + + public static void compareWithDto( + Collection client, Collection dto) { + assertEquals(dto.size(), client.size()); + Iterator dtoIterator = dto.iterator(); + Iterator clientIterator = client.iterator(); + + dtoIterator.forEachRemaining(dtoItem -> compareWithDto(clientIterator.next(), dtoItem)); + } + + public static void compareWithDto(DeliveryReportBatch client, DeliveryReportDto dto) + throws UnexpectedException { + String type = dto.getType(); + if (Objects.equals(type, TypeEnum.MMS.getValue())) { + assertInstanceOf(DeliveryReportBatchMMS.class, client); + } else if (Objects.equals(type, TypeEnum.SMS.getValue())) { + assertInstanceOf(DeliveryReportBatchSMS.class, client); + } else { + throw new UnexpectedException("Unexpected type " + type); + } + + assertEquals(dto.getBatchId(), client.getBatchId()); + compareWithDto(client.getStatuses(), dto.getStatuses()); + assertEquals(dto.getTotalMessageCount(), client.getTotalMessageCount()); + assertEquals(dto.getClientReference(), client.getClientReference().orElse(null)); + } + + @Test + void convertSMS() throws UnexpectedException { + compareWithDto( + DeliveryReportDtoConverter.convert(deliveryReportSMSClientDto), deliveryReportSMSClientDto); + } + + @Test + void convertMMS() throws UnexpectedException { + compareWithDto( + DeliveryReportDtoConverter.convert(deliveryReportMMSClientDto), deliveryReportMMSClientDto); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java new file mode 100644 index 00000000..51e02eca --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java @@ -0,0 +1,40 @@ +package com.sinch.sdk.domains.sms.adapters.converters; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.sms.models.DryRun; +import com.sinch.sdk.domains.sms.models.DryRunPerRecipientDetails; +import com.sinch.sdk.domains.sms.models.dto.v1.DryRun200ResponseDto; +import java.util.Collections; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class DryRunDtoConverterTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") + DryRun200ResponseDto loadedDto; + + public static DryRun dryRunClient = + DryRun.builder() + .setNumberOfRecipients(123) + .setNumberOfMessages(456) + .setPerRecipient( + Collections.singletonList( + DryRunPerRecipientDetails.builder() + .setRecipient("recipient string") + .setMessagePart("message part string") + .setBody("body string") + .setEncoding("encoding string") + .build())) + .build(); + + @Test + void testConvertDryRun() { + assertThat(DryRunDtoConverter.convert(loadedDto)) + .usingRecursiveComparison() + .isEqualTo(dryRunClient); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java new file mode 100644 index 00000000..c5d049fd --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java @@ -0,0 +1,131 @@ +package com.sinch.sdk.domains.sms.adapters.converters; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.GroupAutoUpdate; +import com.sinch.sdk.domains.sms.models.GroupAutoUpdateKeyword; +import com.sinch.sdk.domains.sms.models.dto.v1.CreateGroupResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.GroupAutoUpdateDto; +import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectDto; +import com.sinch.sdk.domains.sms.models.dto.v1.ReplaceGroupRequestDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestDto; +import com.sinch.sdk.domains.sms.models.requests.GroupCreateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters; +import java.rmi.UnexpectedException; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +@TestWithResources +class GroupsDtoConverterTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/GroupResponseDto.json") + CreateGroupResponseDto createGroupResponseDto; + + @GivenJsonResource("/domains/sms/v1/GroupCreateRequestParametersDto.json") + GroupObjectDto createGroupRequestParametersDto; + + @GivenJsonResource("/domains/sms/v1/GroupUpdateRequestParametersDto.json") + UpdateGroupRequestDto groupUpdateRequestParametersDto; + + @GivenJsonResource("/domains/sms/v1/GroupReplaceRequestParametersDto.json") + ReplaceGroupRequestDto groupReplaceRequestParametersDto; + + static void compareWithDto(Group client, CreateGroupResponseDto dto) { + assertEquals(dto.getSize(), client.getSize()); + assertEquals(dto.getCreatedAt().toInstant(), client.getCreatedAt()); + assertEquals(dto.getModifiedAt().toInstant(), client.getModifiedAt()); + assertEquals(dto.getId(), client.getId()); + assertEquals(dto.getName(), client.getName()); + Iterator dtoIterator = dto.getChildGroups().iterator(); + Iterator clientIterator = client.getChildGroupIds().iterator(); + dtoIterator.forEachRemaining(dtoItem -> assertEquals(clientIterator.next(), dtoItem)); + compareWithDto(client.getAutoUpdate(), dto.getAutoUpdate()); + } + + static void compareWithDto(GroupAutoUpdate client, GroupAutoUpdateDto dto) { + assertEquals(dto.getTo(), client.getTo()); + assertEquals(dto.getAdd().getFirstWord(), client.getAdd().getFirstWord()); + assertEquals(dto.getAdd().getSecondWord(), client.getAdd().getSecondWord()); + assertEquals(dto.getRemove().getFirstWord(), client.getRemove().getFirstWord()); + assertEquals(dto.getRemove().getSecondWord(), client.getRemove().getSecondWord()); + } + + @Test + void convertCreateGroupResponse() throws UnexpectedException { + compareWithDto(GroupsDtoConverter.convert(createGroupResponseDto), createGroupResponseDto); + } + + @Test + void convertCreateRequestParameters() throws UnexpectedException { + GroupCreateRequestParameters client = + GroupCreateRequestParameters.builder() + .setName("My new customers") + .setMembers(Collections.singletonList("foo")) + .setChildGroupIds( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00")) + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd( + GroupAutoUpdateKeyword.builder().setFirstWord("Add 1st keyword").build()) + .setRemove( + GroupAutoUpdateKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .build(); + + Assertions.assertThat(createGroupRequestParametersDto) + .usingRecursiveComparison() + .isEqualTo(GroupsDtoConverter.convert(client)); + } + + @Test + void convertUpdateRequestParameters() throws UnexpectedException { + GroupUpdateRequestParameters client = + GroupUpdateRequestParameters.builder() + .setName("My new customers") + .setAdd(Collections.singletonList("foo")) + .setRemove(Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00")) + .setAddFromGroup("add from group string") + .setRemoveFromGroup("remove from group string") + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd( + GroupAutoUpdateKeyword.builder().setFirstWord("Add 1st keyword").build()) + .setRemove( + GroupAutoUpdateKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .build(); + + Assertions.assertThat(groupUpdateRequestParametersDto) + .usingRecursiveComparison() + .isEqualTo(GroupsDtoConverter.convert(client)); + } + + @Test + void convertReplaceRequestParameters() throws UnexpectedException { + GroupReplaceRequestParameters client = + GroupReplaceRequestParameters.builder() + .setName("My new customers") + .setMembers(Collections.singletonList("foo")) + .build(); + + Assertions.assertThat(groupReplaceRequestParametersDto) + .usingRecursiveComparison() + .isEqualTo(GroupsDtoConverter.convert(client)); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryBuilderTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryBuilderTest.java index 4ad146da..af820216 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryBuilderTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryBuilderTest.java @@ -17,7 +17,7 @@ class BatchBinaryBuilderTest { final boolean canceled = true; final Instant createdAt = Instant.now(); final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); final Instant expireAt = Instant.now(); final String callbackUrl = "callback value"; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryTest.java index 2f782047..721ce174 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBinaryTest.java @@ -17,7 +17,7 @@ class BatchBinaryTest { final boolean canceled = true; final Instant createdAt = Instant.now(); final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); final Instant expireAt = Instant.now(); final String callbackUrl = "callback value"; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBuilderTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBuilderTest.java index 5a8927c9..8855fb58 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBuilderTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchBuilderTest.java @@ -22,7 +22,7 @@ class BatchBuilderTest { final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaBuilderTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaBuilderTest.java index a7692241..b7da2e2a 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaBuilderTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaBuilderTest.java @@ -18,7 +18,7 @@ class BatchMediaBuilderTest { final Parameters parameters = null; final Instant createdAt = Instant.now(); final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); final Instant expireAt = Instant.now(); final String callbackUrl = "callback value"; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaTest.java index 2d11b321..95ac1cbb 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchMediaTest.java @@ -23,7 +23,7 @@ class BatchMediaTest { "key 2", new Pair<>("value identifier2", "value 2"), "default value for "))); final Instant createdAt = Instant.now(); final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); final Instant expireAt = Instant.now(); final String callbackUrl = "callback value"; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTest.java index 5cd68c60..7da9d943 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTest.java @@ -22,7 +22,7 @@ class BatchTest { final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextBuilderTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextBuilderTest.java index 2d5ff3fa..1054c47f 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextBuilderTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextBuilderTest.java @@ -18,7 +18,7 @@ class BatchTextBuilderTest { final Parameters parameters = null; final Instant createdAt = Instant.now(); final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); final Instant expireAt = Instant.now(); final String callbackUrl = "callback value"; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextTest.java index 89847d15..604882a6 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/BatchTextTest.java @@ -18,7 +18,7 @@ class BatchTextTest { final Parameters parameters = null; final Instant createdAt = Instant.now(); final Instant modifiedAt = Instant.now(); - final DeliveryReport deliveryReport = DeliveryReport.FULL; + final DeliveryReportType deliveryReport = DeliveryReportType.FULL; final Instant sendAt = Instant.now(); final Instant expireAt = Instant.now(); final String callbackUrl = "callback value"; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/MediaBodyTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/MediaBodyTest.java index bf1a3cd3..1579b7ea 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/MediaBodyTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/MediaBodyTest.java @@ -9,7 +9,7 @@ class MediaBodyTest { @Test void getMessage() { - Assertions.assertThat(value.getMessage()).isEqualTo("the message"); + Assertions.assertThat(value.getMessage().get()).isEqualTo("the message"); } @Test diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/requests/BatchesListRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/requests/BatchesListRequestParametersTest.java new file mode 100644 index 00000000..3ffa9828 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/requests/BatchesListRequestParametersTest.java @@ -0,0 +1,51 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import static org.junit.jupiter.api.Assertions.*; + +import java.time.Instant; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class BatchesListRequestParametersTest { + + static final String from = "foo from"; + + static Instant startDate = Instant.now(); + static Instant endDate = Instant.now(); + static String clientReference = "a client reference"; + static Integer page = 1; + static Integer pageSize = 3; + + public static final BatchesListRequestParameters value = + new BatchesListRequestParameters(from, startDate, endDate, clientReference, page, pageSize); + + @Test + void getFrom() { + Assertions.assertThat(value.getFrom().get()).isEqualTo(from); + } + + @Test + void getStartDate() { + Assertions.assertThat(value.getStartDate().get()).isEqualTo(startDate); + } + + @Test + void getEndDate() { + Assertions.assertThat(value.getEndDate().get()).isEqualTo(endDate); + } + + @Test + void getClientReference() { + Assertions.assertThat(value.getClientReference().get()).isEqualTo(clientReference); + } + + @Test + void getPage() { + Assertions.assertThat(value.getPage().get()).isEqualTo(page); + } + + @Test + void getPageSize() { + Assertions.assertThat(value.getPageSize().get()).isEqualTo(pageSize); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParametersBuilderTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParametersBuilderTest.java new file mode 100644 index 00000000..74ea6ccd --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParametersBuilderTest.java @@ -0,0 +1,68 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReportErrorCode; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collection; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class DeliveryReportListRequestParametersBuilderTest { + + final Instant startDate = Instant.now().plusSeconds(10); + final Instant endDate = Instant.now().plusSeconds(15); + final String clientReference = " client reference"; + final Integer page = 12; + final Integer pageSize = 3; + final Collection statuses = + Arrays.asList(DeliveryReportStatus.CANCELLED, DeliveryReportStatus.DELETED); + final Collection codes = + Arrays.asList( + DeliveryReportErrorCode.from(123), DeliveryReportErrorCode.DELIVERY_REPORT_UNREACHABLE); + final DeliveryReportListRequestParameters value = + DeliveryReportListRequestParameters.builder() + .setStartDate(startDate) + .setEndDate(endDate) + .setClientReference(clientReference) + .setPage(page) + .setPageSize(pageSize) + .setStatuses(statuses) + .setCodes(codes) + .build(); + + @Test + void getStartDate() { + Assertions.assertThat(value.getStartDate().get()).isEqualTo(startDate); + } + + @Test + void getEndDate() { + Assertions.assertThat(value.getEndDate().get()).isEqualTo(endDate); + } + + @Test + void getClientReference() { + Assertions.assertThat(value.getClientReference().get()).isEqualTo(clientReference); + } + + @Test + void getPage() { + Assertions.assertThat(value.getPage().get()).isEqualTo(page); + } + + @Test + void getPageSize() { + Assertions.assertThat(value.getPageSize().get()).isEqualTo(pageSize); + } + + @Test + void getStatuses() { + Assertions.assertThat(value.getStatuses().get()).usingRecursiveComparison().isEqualTo(statuses); + } + + @Test + void getCodes() { + Assertions.assertThat(value.getCodes().get()).usingRecursiveComparison().isEqualTo(codes); + } +} diff --git a/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java b/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java index d7b31989..883fb3fa 100644 --- a/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java +++ b/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java @@ -15,6 +15,10 @@ public ApiException(String message) { super(message); } + public ApiException(String message, Throwable throwable) { + super(message, throwable); + } + public ApiException(String message, Throwable throwable, int code) { super(message, throwable); this.code = code; diff --git a/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java b/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java index 8f5ecccf..645f89bb 100644 --- a/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java +++ b/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java @@ -12,17 +12,17 @@ public static ApiException build(String message, int code) { public static ApiException build(String message, int code, Map mappedResponse) { // Hardcoded Numbers API errors like format parsing - Optional numbersException = getExceptionFromNumbersOrSmsError(mappedResponse); + Optional numbersException = getExceptionFromNumbersError(mappedResponse); + if (numbersException.isPresent()) { + return numbersException.get(); + } - return numbersException.orElseGet(() -> new ApiException(message, code)); + Optional smsException = getExceptionFromSmsError(mappedResponse); + return smsException.orElseGet(() -> new ApiException(message, code)); } - private static Optional getExceptionFromNumbersOrSmsError( - Map mappedResponse) { + private static Optional getExceptionFromNumbersError(Map mappedResponse) { - if (null == mappedResponse) { - return Optional.empty(); - } // excepted numbers API errors have following form // "error": { // "code": int, @@ -54,4 +54,25 @@ private static Optional getExceptionFromNumbersOrSmsError( return Optional.of( new ApiException(String.format("%s: %s", statusValue, messageValue), codeValue)); } + + private static Optional getExceptionFromSmsError(Map mappedResponse) { + + // excepted SMS API errors have following form + // "code": int, + // "text": string, + // } + + if (null == mappedResponse) { + return Optional.empty(); + } + + Object code = mappedResponse.get("code"); + Object text = mappedResponse.get("text"); + + if (null == code || null == text) { + return Optional.empty(); + } + + return Optional.of(new ApiException(String.format("%s: %s", code, text))); + } } diff --git a/core/src/main/com/sinch/sdk/core/exceptions/ApiMappingException.java b/core/src/main/com/sinch/sdk/core/exceptions/ApiMappingException.java new file mode 100644 index 00000000..426aedcd --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/exceptions/ApiMappingException.java @@ -0,0 +1,8 @@ +package com.sinch.sdk.core.exceptions; + +public class ApiMappingException extends ApiException { + + public ApiMappingException(String payload, Throwable throwable) { + super(String.format("Unable to map string '%s'", payload), throwable); + } +} diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java index 3a9a1ce8..e68a36a5 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java @@ -33,7 +33,7 @@ public static Optional encode(URLParameter parameter) { } Object value = parameter.getValue(); - if (value instanceof String || value instanceof Number) { + if (value instanceof String || value instanceof Number || value instanceof Boolean) { return encodeString(parameter.getStyle(), parameter.getName(), value.toString()); } diff --git a/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java b/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java index 1e24aa49..a1c32632 100644 --- a/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java +++ b/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java @@ -13,6 +13,7 @@ * @since 1.0 */ public abstract class ListResponse { + /** * Indicate if another page response is available * diff --git a/core/src/main/com/sinch/sdk/core/utils/DateUtil.java b/core/src/main/com/sinch/sdk/core/utils/DateUtil.java new file mode 100644 index 00000000..8d6c2a23 --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/utils/DateUtil.java @@ -0,0 +1,19 @@ +package com.sinch.sdk.core.utils; + +import java.time.Instant; +import java.time.OffsetDateTime; + +/** Utility class for Date */ +public class DateUtil { + + /** + * Convert an OffsetDateTime to Instant with null value protection + * + * @param value Value to be converted + * @return Converted value to Instant or null if source value was null + * @since 1.0 + */ + public static Instant toInstant(OffsetDateTime value) { + return (null == value ? null : value.toInstant()); + } +} diff --git a/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java b/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java index e3446a27..65fd3431 100644 --- a/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java +++ b/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java @@ -5,11 +5,11 @@ * * @param Enum type */ -public abstract class EnumDynamic> { +public abstract class EnumDynamic> { - private final String value; + private final T value; - protected EnumDynamic(String value) { + protected EnumDynamic(T value) { this.value = value; } @@ -18,12 +18,12 @@ protected EnumDynamic(String value) { * * @return Enum value */ - public String value() { + public T value() { return value; } public String toString() { - return value(); + return value().toString(); } public boolean equals(E o) { diff --git a/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java b/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java index 0ceb4fe2..4816734c 100644 --- a/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java +++ b/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java @@ -13,15 +13,15 @@ * to extend it dynamically Typical use case: being able to send and/or receive values not yet * defined at SDK version release */ -public final class EnumSupportDynamic> { +public final class EnumSupportDynamic> { private final Class aClass; - private final Map valueMap; - private final Function surplusFactory; + private final Map valueMap; + private final Function surplusFactory; private volatile List values; - public EnumSupportDynamic(Class aClass, Function surplusFactory, List values) { + public EnumSupportDynamic(Class aClass, Function surplusFactory, List values) { this.aClass = aClass; this.values = Collections.unmodifiableList(values); @@ -39,25 +39,25 @@ public Stream values() { return values.stream(); } - public String valueOf(E e) { + public T valueOf(E e) { return e == null ? null : e.value(); } - public List valuesOf(Collection values) { + public List valuesOf(Collection values) { if (values == null) { return null; } return values.stream().map(this::valueOf).collect(toList()); } - public List fromValues(Collection values) { + public List fromValues(Collection values) { if (values == null) { return null; } return values.stream().map(this::from).collect(toList()); } - public E from(String value) { + public E from(T value) { if (value == null) { return null; } @@ -102,7 +102,7 @@ public String toComparableValue(Object o) { if (aClass.isInstance(o)) { E obj = aClass.cast(o); - return obj.value(); + return obj.value().toString(); } throw new IllegalArgumentException( diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java index 4dce763f..a381369e 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java @@ -65,6 +65,15 @@ public ActiveNumberApi( */ public ActiveNumberDto numberServiceGetActiveNumber(String projectId, String phoneNumber) throws ApiException { + + LOGGER.finest( + "[numberServiceGetActiveNumber] " + + "projectId: " + + projectId + + ", " + + "phoneNumber: " + + phoneNumber); + HttpRequest httpRequest = numberServiceGetActiveNumberRequestBuilder(projectId, phoneNumber); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -116,12 +125,6 @@ private HttpRequest numberServiceGetActiveNumberRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -168,6 +171,36 @@ public ActiveNumbersResponseDto numberServiceListActiveNumbers( String pageToken, String orderBy) throws ApiException { + + LOGGER.finest( + "[numberServiceListActiveNumbers] " + + "projectId: " + + projectId + + ", " + + "regionCode: " + + regionCode + + ", " + + "type: " + + type + + ", " + + "numberPatternPattern: " + + numberPatternPattern + + ", " + + "numberPatternSearchPattern: " + + numberPatternSearchPattern + + ", " + + "capability: " + + capability + + ", " + + "pageSize: " + + pageSize + + ", " + + "pageToken: " + + pageToken + + ", " + + "orderBy: " + + orderBy); + HttpRequest httpRequest = numberServiceListActiveNumbersRequestBuilder( projectId, @@ -287,12 +320,6 @@ private HttpRequest numberServiceListActiveNumbersRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -319,6 +346,15 @@ private HttpRequest numberServiceListActiveNumbersRequestBuilder( */ public ActiveNumberDto numberServiceReleaseNumber(String projectId, String phoneNumber) throws ApiException { + + LOGGER.finest( + "[numberServiceReleaseNumber] " + + "projectId: " + + projectId + + ", " + + "phoneNumber: " + + phoneNumber); + HttpRequest httpRequest = numberServiceReleaseNumberRequestBuilder(projectId, phoneNumber); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -370,12 +406,6 @@ private HttpRequest numberServiceReleaseNumberRequestBuilder(String projectId, S final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, @@ -406,6 +436,18 @@ private HttpRequest numberServiceReleaseNumberRequestBuilder(String projectId, S public ActiveNumberDto numberServiceUpdateActiveNumber( String projectId, String phoneNumber, ActiveNumberRequestDto activeNumberRequestDto) throws ApiException { + + LOGGER.finest( + "[numberServiceUpdateActiveNumber] " + + "projectId: " + + projectId + + ", " + + "phoneNumber: " + + phoneNumber + + ", " + + "activeNumberRequestDto: " + + activeNumberRequestDto); + HttpRequest httpRequest = numberServiceUpdateActiveNumberRequestBuilder( projectId, phoneNumber, activeNumberRequestDto); @@ -462,12 +504,6 @@ private HttpRequest numberServiceUpdateActiveNumberRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, activeNumberRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.PATCH, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java index 427e48b8..5e726f75 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java @@ -69,6 +69,15 @@ public AvailableNumberApi( */ public AvailableNumberDto numberServiceGetAvailableNumber(String projectId, String phoneNumber) throws ApiException { + + LOGGER.finest( + "[numberServiceGetAvailableNumber] " + + "projectId: " + + projectId + + ", " + + "phoneNumber: " + + phoneNumber); + HttpRequest httpRequest = numberServiceGetAvailableNumberRequestBuilder(projectId, phoneNumber); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -123,12 +132,6 @@ private HttpRequest numberServiceGetAvailableNumberRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -172,6 +175,30 @@ public AvailableNumbersResponseDto numberServiceListAvailableNumbers( List capabilities, Integer size) throws ApiException { + + LOGGER.finest( + "[numberServiceListAvailableNumbers] " + + "projectId: " + + projectId + + ", " + + "regionCode: " + + regionCode + + ", " + + "type: " + + type + + ", " + + "numberPatternPattern: " + + numberPatternPattern + + ", " + + "numberPatternSearchPattern: " + + numberPatternSearchPattern + + ", " + + "capabilities: " + + capabilities + + ", " + + "size: " + + size); + HttpRequest httpRequest = numberServiceListAvailableNumbersRequestBuilder( projectId, @@ -281,12 +308,6 @@ private HttpRequest numberServiceListAvailableNumbersRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -311,6 +332,15 @@ private HttpRequest numberServiceListAvailableNumbersRequestBuilder( */ public ActiveNumberDto numberServiceRentAnyNumber( String projectId, RentAnyNumberRequestDto rentAnyNumberRequestDto) throws ApiException { + + LOGGER.finest( + "[numberServiceRentAnyNumber] " + + "projectId: " + + projectId + + ", " + + "rentAnyNumberRequestDto: " + + rentAnyNumberRequestDto); + HttpRequest httpRequest = numberServiceRentAnyNumberRequestBuilder(projectId, rentAnyNumberRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -361,12 +391,6 @@ private HttpRequest numberServiceRentAnyNumberRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, rentAnyNumberRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, @@ -396,6 +420,18 @@ private HttpRequest numberServiceRentAnyNumberRequestBuilder( public ActiveNumberDto numberServiceRentNumber( String projectId, String phoneNumber, RentNumberRequestDto rentNumberRequestDto) throws ApiException { + + LOGGER.finest( + "[numberServiceRentNumber] " + + "projectId: " + + projectId + + ", " + + "phoneNumber: " + + phoneNumber + + ", " + + "rentNumberRequestDto: " + + rentNumberRequestDto); + HttpRequest httpRequest = numberServiceRentNumberRequestBuilder(projectId, phoneNumber, rentNumberRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -454,12 +490,6 @@ private HttpRequest numberServiceRentNumberRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, rentNumberRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java index 30301d15..8fe90f51 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java @@ -65,6 +65,15 @@ public AvailableRegionsApi( */ public ListAvailableRegionsResponseDto numberServiceListAvailableRegions( String projectId, List types) throws ApiException { + + LOGGER.finest( + "[numberServiceListAvailableRegions] " + + "projectId: " + + projectId + + ", " + + "types: " + + types); + HttpRequest httpRequest = numberServiceListAvailableRegionsRequestBuilder(projectId, types); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -113,12 +122,6 @@ private HttpRequest numberServiceListAvailableRegionsRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java index 53e447e2..c5e6af56 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java @@ -59,6 +59,9 @@ public CallbackConfigurationApi( * @throws ApiException if fails to make API call */ public CallbackConfigurationDto getCallbackConfiguration(String projectId) throws ApiException { + + LOGGER.finest("[getCallbackConfiguration] " + "projectId: " + projectId); + HttpRequest httpRequest = getCallbackConfigurationRequestBuilder(projectId); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -100,12 +103,6 @@ private HttpRequest getCallbackConfigurationRequestBuilder(String projectId) thr final Collection localVarAuthNames = Arrays.asList("BasicAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -130,6 +127,15 @@ private HttpRequest getCallbackConfigurationRequestBuilder(String projectId) thr public CallbackConfigurationDto updateCallbackConfiguration( String projectId, CallbackConfigurationUpdateDto callbackConfigurationUpdateDto) throws ApiException { + + LOGGER.finest( + "[updateCallbackConfiguration] " + + "projectId: " + + projectId + + ", " + + "callbackConfigurationUpdateDto: " + + callbackConfigurationUpdateDto); + HttpRequest httpRequest = updateCallbackConfigurationRequestBuilder(projectId, callbackConfigurationUpdateDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -176,12 +182,6 @@ private HttpRequest updateCallbackConfigurationRequestBuilder( final String serializedBody = mapper.serialize(localVarContentTypes, callbackConfigurationUpdateDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.PATCH, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java index 993ad73e..d8fed58f 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java @@ -27,7 +27,6 @@ import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListDto; import com.sinch.sdk.domains.sms.models.dto.v1.ApiDeliveryFeedbackDto; import com.sinch.sdk.domains.sms.models.dto.v1.DryRun200ResponseDto; -import com.sinch.sdk.domains.sms.models.dto.v1.DryRunRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.SendSMSRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.UpdateBatchMessageRequestDto; @@ -70,6 +69,10 @@ public BatchesApi( */ public SendSMS201ResponseDto cancelBatchMessage(String servicePlanId, String batchId) throws ApiException { + + LOGGER.finest( + "[cancelBatchMessage] " + "servicePlanId: " + servicePlanId + ", " + "batchId: " + batchId); + HttpRequest httpRequest = cancelBatchMessageRequestBuilder(servicePlanId, batchId); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -120,12 +123,6 @@ private HttpRequest cancelBatchMessageRequestBuilder(String servicePlanId, Strin final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.DELETE, @@ -156,6 +153,18 @@ private HttpRequest cancelBatchMessageRequestBuilder(String servicePlanId, Strin public void deliveryFeedback( String servicePlanId, String batchId, ApiDeliveryFeedbackDto apiDeliveryFeedbackDto) throws ApiException { + + LOGGER.finest( + "[deliveryFeedback] " + + "servicePlanId: " + + servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "apiDeliveryFeedbackDto: " + + apiDeliveryFeedbackDto); + HttpRequest httpRequest = deliveryFeedbackRequestBuilder(servicePlanId, batchId, apiDeliveryFeedbackDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -212,12 +221,6 @@ private HttpRequest deliveryFeedbackRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, apiDeliveryFeedbackDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, @@ -237,7 +240,7 @@ private HttpRequest deliveryFeedbackRequestBuilder( * @param perRecipient Whether to include per recipient details in the response (optional) * @param numberOfRecipients Max number of recipients to include per recipient details for in the * response (optional, default to 100) - * @param dryRunRequestDto (optional) + * @param sendSMSRequestDto (optional) * @return DryRun200ResponseDto * @throws ApiException if fails to make API call */ @@ -245,10 +248,25 @@ public DryRun200ResponseDto dryRun( String servicePlanId, Boolean perRecipient, Integer numberOfRecipients, - DryRunRequestDto dryRunRequestDto) + SendSMSRequestDto sendSMSRequestDto) throws ApiException { + + LOGGER.finest( + "[dryRun] " + + "servicePlanId: " + + servicePlanId + + ", " + + "perRecipient: " + + perRecipient + + ", " + + "numberOfRecipients: " + + numberOfRecipients + + ", " + + "sendSMSRequestDto: " + + sendSMSRequestDto); + HttpRequest httpRequest = - dryRunRequestBuilder(servicePlanId, perRecipient, numberOfRecipients, dryRunRequestDto); + dryRunRequestBuilder(servicePlanId, perRecipient, numberOfRecipients, sendSMSRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { @@ -269,7 +287,7 @@ private HttpRequest dryRunRequestBuilder( String servicePlanId, Boolean perRecipient, Integer numberOfRecipients, - DryRunRequestDto dryRunRequestDto) + SendSMSRequestDto sendSMSRequestDto) throws ApiException { // verify the required parameter 'servicePlanId' is set if (servicePlanId == null) { @@ -308,14 +326,8 @@ private HttpRequest dryRunRequestBuilder( final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("BearerAuth"); - final String serializedBody = mapper.serialize(localVarContentTypes, dryRunRequestDto); + final String serializedBody = mapper.serialize(localVarContentTypes, sendSMSRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, @@ -337,6 +349,10 @@ private HttpRequest dryRunRequestBuilder( */ public SendSMS201ResponseDto getBatchMessage(String servicePlanId, String batchId) throws ApiException { + + LOGGER.finest( + "[getBatchMessage] " + "servicePlanId: " + servicePlanId + ", " + "batchId: " + batchId); + HttpRequest httpRequest = getBatchMessageRequestBuilder(servicePlanId, batchId); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -387,12 +403,6 @@ private HttpRequest getBatchMessageRequestBuilder(String servicePlanId, String b final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -432,6 +442,30 @@ public ApiBatchListDto listBatches( String endDate, String clientReference) throws ApiException { + + LOGGER.finest( + "[listBatches] " + + "servicePlanId: " + + servicePlanId + + ", " + + "page: " + + page + + ", " + + "pageSize: " + + pageSize + + ", " + + "from: " + + from + + ", " + + "startDate: " + + startDate + + ", " + + "endDate: " + + endDate + + ", " + + "clientReference: " + + clientReference); + HttpRequest httpRequest = listBatchesRequestBuilder( servicePlanId, page, pageSize, from, startDate, endDate, clientReference); @@ -513,12 +547,6 @@ private HttpRequest listBatchesRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -536,13 +564,26 @@ private HttpRequest listBatchesRequestBuilder( * @param servicePlanId Your service plan ID. You can find this on your * [Dashboard](https://dashboard.sinch.com/sms/api/rest). (required) * @param batchId The batch ID you received from sending a message. (required) - * @param dryRunRequestDto (optional) + * @param sendSMSRequestDto (optional) * @return SendSMS201ResponseDto * @throws ApiException if fails to make API call */ public SendSMS201ResponseDto replaceBatch( - String servicePlanId, String batchId, DryRunRequestDto dryRunRequestDto) throws ApiException { - HttpRequest httpRequest = replaceBatchRequestBuilder(servicePlanId, batchId, dryRunRequestDto); + String servicePlanId, String batchId, SendSMSRequestDto sendSMSRequestDto) + throws ApiException { + + LOGGER.finest( + "[replaceBatch] " + + "servicePlanId: " + + servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "sendSMSRequestDto: " + + sendSMSRequestDto); + + HttpRequest httpRequest = replaceBatchRequestBuilder(servicePlanId, batchId, sendSMSRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { @@ -560,7 +601,8 @@ public SendSMS201ResponseDto replaceBatch( } private HttpRequest replaceBatchRequestBuilder( - String servicePlanId, String batchId, DryRunRequestDto dryRunRequestDto) throws ApiException { + String servicePlanId, String batchId, SendSMSRequestDto sendSMSRequestDto) + throws ApiException { // verify the required parameter 'servicePlanId' is set if (servicePlanId == null) { throw new ApiException( @@ -590,14 +632,8 @@ private HttpRequest replaceBatchRequestBuilder( final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("BearerAuth"); - final String serializedBody = mapper.serialize(localVarContentTypes, dryRunRequestDto); + final String serializedBody = mapper.serialize(localVarContentTypes, sendSMSRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.PUT, @@ -624,6 +660,15 @@ private HttpRequest replaceBatchRequestBuilder( */ public SendSMS201ResponseDto sendSMS(String servicePlanId, SendSMSRequestDto sendSMSRequestDto) throws ApiException { + + LOGGER.finest( + "[sendSMS] " + + "servicePlanId: " + + servicePlanId + + ", " + + "sendSMSRequestDto: " + + sendSMSRequestDto); + HttpRequest httpRequest = sendSMSRequestBuilder(servicePlanId, sendSMSRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -666,12 +711,6 @@ private HttpRequest sendSMSRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, sendSMSRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, @@ -698,6 +737,18 @@ public SendSMS201ResponseDto updateBatchMessage( String batchId, UpdateBatchMessageRequestDto updateBatchMessageRequestDto) throws ApiException { + + LOGGER.finest( + "[updateBatchMessage] " + + "servicePlanId: " + + servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "updateBatchMessageRequestDto: " + + updateBatchMessageRequestDto); + HttpRequest httpRequest = updateBatchMessageRequestBuilder(servicePlanId, batchId, updateBatchMessageRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -753,12 +804,6 @@ private HttpRequest updateBatchMessageRequestBuilder( final String serializedBody = mapper.serialize(localVarContentTypes, updateBatchMessageRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java index 005fa7eb..050f5334 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java @@ -71,6 +71,24 @@ public DeliveryReportsApi( public DeliveryReportDto getDeliveryReportByBatchId( String servicePlanId, String batchId, String type, String status, String code) throws ApiException { + + LOGGER.finest( + "[getDeliveryReportByBatchId] " + + "servicePlanId: " + + servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "type: " + + type + + ", " + + "status: " + + status + + ", " + + "code: " + + code); + HttpRequest httpRequest = getDeliveryReportByBatchIdRequestBuilder(servicePlanId, batchId, type, status, code); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -137,12 +155,6 @@ private HttpRequest getDeliveryReportByBatchIdRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -166,6 +178,18 @@ private HttpRequest getDeliveryReportByBatchIdRequestBuilder( */ public RecipientDeliveryReportDto getDeliveryReportByPhoneNumber( String servicePlanId, String batchId, String recipientMsisdn) throws ApiException { + + LOGGER.finest( + "[getDeliveryReportByPhoneNumber] " + + "servicePlanId: " + + servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "recipientMsisdn: " + + recipientMsisdn); + HttpRequest httpRequest = getDeliveryReportByPhoneNumberRequestBuilder(servicePlanId, batchId, recipientMsisdn); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -230,12 +254,6 @@ private HttpRequest getDeliveryReportByPhoneNumberRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -273,6 +291,33 @@ public DeliveryReportListDto getDeliveryReports( String code, String clientReference) throws ApiException { + + LOGGER.finest( + "[getDeliveryReports] " + + "servicePlanId: " + + servicePlanId + + ", " + + "page: " + + page + + ", " + + "pageSize: " + + pageSize + + ", " + + "startDate: " + + startDate + + ", " + + "endDate: " + + endDate + + ", " + + "status: " + + status + + ", " + + "code: " + + code + + ", " + + "clientReference: " + + clientReference); + HttpRequest httpRequest = getDeliveryReportsRequestBuilder( servicePlanId, page, pageSize, startDate, endDate, status, code, clientReference); @@ -361,12 +406,6 @@ private HttpRequest getDeliveryReportsRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java index 2d725650..bd3546e6 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java @@ -24,9 +24,9 @@ import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupListDto; import com.sinch.sdk.domains.sms.models.dto.v1.CreateGroupResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectDto; -import com.sinch.sdk.domains.sms.models.dto.v1.ListGroups200ResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.ReplaceGroupRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestDto; import java.util.ArrayList; @@ -65,6 +65,15 @@ public GroupsApi( */ public CreateGroupResponseDto createGroup(String servicePlanId, GroupObjectDto groupObjectDto) throws ApiException { + + LOGGER.finest( + "[createGroup] " + + "servicePlanId: " + + servicePlanId + + ", " + + "groupObjectDto: " + + groupObjectDto); + HttpRequest httpRequest = createGroupRequestBuilder(servicePlanId, groupObjectDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -107,12 +116,6 @@ private HttpRequest createGroupRequestBuilder(String servicePlanId, GroupObjectD final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, groupObjectDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, @@ -132,6 +135,10 @@ private HttpRequest createGroupRequestBuilder(String servicePlanId, GroupObjectD * @throws ApiException if fails to make API call */ public void deleteGroup(String servicePlanId, String groupId) throws ApiException { + + LOGGER.finest( + "[deleteGroup] " + "servicePlanId: " + servicePlanId + ", " + "groupId: " + groupId); + HttpRequest httpRequest = deleteGroupRequestBuilder(servicePlanId, groupId); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -180,12 +187,6 @@ private HttpRequest deleteGroupRequestBuilder(String servicePlanId, String group final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.DELETE, @@ -207,6 +208,10 @@ private HttpRequest deleteGroupRequestBuilder(String servicePlanId, String group * @throws ApiException if fails to make API call */ public List getMembers(String servicePlanId, String groupId) throws ApiException { + + LOGGER.finest( + "[getMembers] " + "servicePlanId: " + servicePlanId + ", " + "groupId: " + groupId); + HttpRequest httpRequest = getMembersRequestBuilder(servicePlanId, groupId); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -256,12 +261,6 @@ private HttpRequest getMembersRequestBuilder(String servicePlanId, String groupI final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -280,17 +279,28 @@ private HttpRequest getMembersRequestBuilder(String servicePlanId, String groupI * [Dashboard](https://dashboard.sinch.com/sms/api/rest). (required) * @param page The page number starting from 0. (optional, default to 0) * @param pageSize Determines the size of a page. (optional, default to 30) - * @return ListGroups200ResponseDto + * @return ApiGroupListDto * @throws ApiException if fails to make API call */ - public ListGroups200ResponseDto listGroups(String servicePlanId, Integer page, Integer pageSize) + public ApiGroupListDto listGroups(String servicePlanId, Integer page, Integer pageSize) throws ApiException { + + LOGGER.finest( + "[listGroups] " + + "servicePlanId: " + + servicePlanId + + ", " + + "page: " + + page + + ", " + + "pageSize: " + + pageSize); + HttpRequest httpRequest = listGroupsRequestBuilder(servicePlanId, page, pageSize); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; + TypeReference localVarReturnType = new TypeReference() {}; return mapper.deserialize(response, localVarReturnType); } // fallback to default errors handling: @@ -336,12 +346,6 @@ private HttpRequest listGroupsRequestBuilder(String servicePlanId, Integer page, final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -367,6 +371,18 @@ private HttpRequest listGroupsRequestBuilder(String servicePlanId, Integer page, public CreateGroupResponseDto replaceGroup( String servicePlanId, String groupId, ReplaceGroupRequestDto replaceGroupRequestDto) throws ApiException { + + LOGGER.finest( + "[replaceGroup] " + + "servicePlanId: " + + servicePlanId + + ", " + + "groupId: " + + groupId + + ", " + + "replaceGroupRequestDto: " + + replaceGroupRequestDto); + HttpRequest httpRequest = replaceGroupRequestBuilder(servicePlanId, groupId, replaceGroupRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -419,12 +435,6 @@ private HttpRequest replaceGroupRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, replaceGroupRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.PUT, @@ -446,6 +456,10 @@ private HttpRequest replaceGroupRequestBuilder( */ public CreateGroupResponseDto retrieveGroup(String servicePlanId, String groupId) throws ApiException { + + LOGGER.finest( + "[retrieveGroup] " + "servicePlanId: " + servicePlanId + ", " + "groupId: " + groupId); + HttpRequest httpRequest = retrieveGroupRequestBuilder(servicePlanId, groupId); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -496,12 +510,6 @@ private HttpRequest retrieveGroupRequestBuilder(String servicePlanId, String gro final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -535,6 +543,18 @@ private HttpRequest retrieveGroupRequestBuilder(String servicePlanId, String gro public CreateGroupResponseDto updateGroup( String servicePlanId, String groupId, UpdateGroupRequestDto updateGroupRequestDto) throws ApiException { + + LOGGER.finest( + "[updateGroup] " + + "servicePlanId: " + + servicePlanId + + ", " + + "groupId: " + + groupId + + ", " + + "updateGroupRequestDto: " + + updateGroupRequestDto); + HttpRequest httpRequest = updateGroupRequestBuilder(servicePlanId, groupId, updateGroupRequestDto); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); @@ -587,12 +607,6 @@ private HttpRequest updateGroupRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = mapper.serialize(localVarContentTypes, updateGroupRequestDto); - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.POST, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java index 6d73d032..a79ded82 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java @@ -25,7 +25,7 @@ import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.sms.models.dto.v1.ApiInboundListDto; -import com.sinch.sdk.domains.sms.models.dto.v1.RetrieveInboundMessage200ResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.InboundDto; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -87,6 +87,30 @@ public ApiInboundListDto listInboundMessages( String endDate, String clientReference) throws ApiException { + + LOGGER.finest( + "[listInboundMessages] " + + "servicePlanId: " + + servicePlanId + + ", " + + "page: " + + page + + ", " + + "pageSize: " + + pageSize + + ", " + + "to: " + + to + + ", " + + "startDate: " + + startDate + + ", " + + "endDate: " + + endDate + + ", " + + "clientReference: " + + clientReference); + HttpRequest httpRequest = listInboundMessagesRequestBuilder( servicePlanId, page, pageSize, to, startDate, endDate, clientReference); @@ -169,12 +193,6 @@ private HttpRequest listInboundMessagesRequestBuilder( final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, @@ -192,17 +210,25 @@ private HttpRequest listInboundMessagesRequestBuilder( * @param servicePlanId Your service plan ID. You can find this on your * [Dashboard](https://dashboard.sinch.com/sms/api/rest). (required) * @param inboundId The inbound ID found when listing inbound messages. (required) - * @return RetrieveInboundMessage200ResponseDto + * @return InboundDto * @throws ApiException if fails to make API call */ - public RetrieveInboundMessage200ResponseDto retrieveInboundMessage( - String servicePlanId, String inboundId) throws ApiException { + public InboundDto retrieveInboundMessage(String servicePlanId, String inboundId) + throws ApiException { + + LOGGER.finest( + "[retrieveInboundMessage] " + + "servicePlanId: " + + servicePlanId + + ", " + + "inboundId: " + + inboundId); + HttpRequest httpRequest = retrieveInboundMessageRequestBuilder(servicePlanId, inboundId); HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; + TypeReference localVarReturnType = new TypeReference() {}; return mapper.deserialize(response, localVarReturnType); } // fallback to default errors handling: @@ -248,12 +274,6 @@ private HttpRequest retrieveInboundMessageRequestBuilder(String servicePlanId, S final Collection localVarAuthNames = Arrays.asList("BearerAuth"); final String serializedBody = null; - /*if (memberVarReadTimeout != null) { - localVarRequestBuilder.timeout(memberVarReadTimeout); - } - if (memberVarInterceptor != null) { - memberVarInterceptor.accept(localVarRequestBuilder); - }*/ return new HttpRequest( localVarPath, HttpMethod.GET, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/AddKeywordDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/AddKeywordDto.java new file mode 100644 index 00000000..ed9c4d04 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/AddKeywordDto.java @@ -0,0 +1,118 @@ +/* + * API Overview | Sinch + * Sinch SMS API is one of the easiest APIs we offer and enables you to add fast and reliable global SMS to your applications. Send single messages, scheduled batch messages, use available message templates and more. + * + * The version of the OpenAPI document: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.Objects; + +/** Keyword to be sent in MO to add MSISDN to a group */ +@JsonPropertyOrder({ + AddKeywordDto.JSON_PROPERTY_FIRST_WORD, + AddKeywordDto.JSON_PROPERTY_SECOND_WORD +}) +// @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class AddKeywordDto { + public static final String JSON_PROPERTY_FIRST_WORD = "first_word"; + private String firstWord; + + public static final String JSON_PROPERTY_SECOND_WORD = "second_word"; + private String secondWord; + + public AddKeywordDto() {} + + public AddKeywordDto firstWord(String firstWord) { + this.firstWord = firstWord; + return this; + } + + /** + * Opt-in keyword like \"JOIN\" if _auto_update.to_ is dedicated long/short number or + * unique brand keyword like \"Sinch\" if it is a shared short code. + * + * @return firstWord + */ + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getFirstWord() { + return firstWord; + } + + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setFirstWord(String firstWord) { + this.firstWord = firstWord; + } + + public AddKeywordDto secondWord(String secondWord) { + this.secondWord = secondWord; + return this; + } + + /** + * Opt-in keyword like \"JOIN\" if _auto_update.to_ is shared short code. + * + * @return secondWord + */ + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public String getSecondWord() { + return secondWord; + } + + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setSecondWord(String secondWord) { + this.secondWord = secondWord; + } + + /** Return true if this addKeyword object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AddKeywordDto addKeyword = (AddKeywordDto) o; + return Objects.equals(this.firstWord, addKeyword.firstWord) + && Objects.equals(this.secondWord, addKeyword.secondWord); + } + + @Override + public int hashCode() { + return Objects.hash(firstWord, secondWord); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AddKeywordDto {\n"); + sb.append(" firstWord: ").append(toIndentedString(firstWord)).append("\n"); + sb.append(" secondWord: ").append(toIndentedString(secondWord)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupAutoUpdateDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupAutoUpdateDto.java new file mode 100644 index 00000000..6da5a543 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupAutoUpdateDto.java @@ -0,0 +1,145 @@ +/* + * API Overview | Sinch + * Sinch SMS API is one of the easiest APIs we offer and enables you to add fast and reliable global SMS to your applications. Send single messages, scheduled batch messages, use available message templates and more. + * + * The version of the OpenAPI document: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.Objects; + +/** ApiGroupAutoUpdateDto */ +@JsonPropertyOrder({ + ApiGroupAutoUpdateDto.JSON_PROPERTY_TO, + ApiGroupAutoUpdateDto.JSON_PROPERTY_ADD, + ApiGroupAutoUpdateDto.JSON_PROPERTY_REMOVE +}) +// @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class ApiGroupAutoUpdateDto { + public static final String JSON_PROPERTY_TO = "to"; + private String to; + + public static final String JSON_PROPERTY_ADD = "add"; + private AddKeywordDto add; + + public static final String JSON_PROPERTY_REMOVE = "remove"; + private RemoveKeywordDto remove; + + public ApiGroupAutoUpdateDto() {} + + public ApiGroupAutoUpdateDto to(String to) { + this.to = to; + return this; + } + + /** + * Short code or long number addressed in MO. Constraints: Must be valid MSISDN or short code. + * + * @return to + */ + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getTo() { + return to; + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setTo(String to) { + this.to = to; + } + + public ApiGroupAutoUpdateDto add(AddKeywordDto add) { + this.add = add; + return this; + } + + /** + * Get add + * + * @return add + */ + @JsonProperty(JSON_PROPERTY_ADD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public AddKeywordDto getAdd() { + return add; + } + + @JsonProperty(JSON_PROPERTY_ADD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setAdd(AddKeywordDto add) { + this.add = add; + } + + public ApiGroupAutoUpdateDto remove(RemoveKeywordDto remove) { + this.remove = remove; + return this; + } + + /** + * Get remove + * + * @return remove + */ + @JsonProperty(JSON_PROPERTY_REMOVE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public RemoveKeywordDto getRemove() { + return remove; + } + + @JsonProperty(JSON_PROPERTY_REMOVE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setRemove(RemoveKeywordDto remove) { + this.remove = remove; + } + + /** Return true if this ApiGroupAutoUpdate object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ApiGroupAutoUpdateDto apiGroupAutoUpdate = (ApiGroupAutoUpdateDto) o; + return Objects.equals(this.to, apiGroupAutoUpdate.to) + && Objects.equals(this.add, apiGroupAutoUpdate.add) + && Objects.equals(this.remove, apiGroupAutoUpdate.remove); + } + + @Override + public int hashCode() { + return Objects.hash(to, add, remove); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiGroupAutoUpdateDto {\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" add: ").append(toIndentedString(add)).append("\n"); + sb.append(" remove: ").append(toIndentedString(remove)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupDto.java index b40f58f4..f3660ead 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupDto.java @@ -16,21 +16,58 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.time.OffsetDateTime; +import java.util.LinkedHashSet; import java.util.Objects; +import java.util.Set; /** ApiGroupDto */ -@JsonPropertyOrder({ApiGroupDto.JSON_PROPERTY_ID}) +@JsonPropertyOrder({ + ApiGroupDto.JSON_PROPERTY_ID, + ApiGroupDto.JSON_PROPERTY_NAME, + ApiGroupDto.JSON_PROPERTY_SIZE, + ApiGroupDto.JSON_PROPERTY_CREATED_AT, + ApiGroupDto.JSON_PROPERTY_MODIFIED_AT, + ApiGroupDto.JSON_PROPERTY_CHILD_GROUPS, + ApiGroupDto.JSON_PROPERTY_AUTO_UPDATE +}) // @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class ApiGroupDto { public static final String JSON_PROPERTY_ID = "id"; private String id; + public static final String JSON_PROPERTY_NAME = "name"; + private String name; + + public static final String JSON_PROPERTY_SIZE = "size"; + private Integer size; + + public static final String JSON_PROPERTY_CREATED_AT = "created_at"; + private OffsetDateTime createdAt; + + public static final String JSON_PROPERTY_MODIFIED_AT = "modified_at"; + private OffsetDateTime modifiedAt; + + public static final String JSON_PROPERTY_CHILD_GROUPS = "child_groups"; + private Set childGroups; + + public static final String JSON_PROPERTY_AUTO_UPDATE = "auto_update"; + private ApiGroupAutoUpdateDto autoUpdate; + public ApiGroupDto() {} @JsonCreator - public ApiGroupDto(@JsonProperty(JSON_PROPERTY_ID) String id) { + public ApiGroupDto( + @JsonProperty(JSON_PROPERTY_ID) String id, + @JsonProperty(JSON_PROPERTY_SIZE) Integer size, + @JsonProperty(JSON_PROPERTY_CREATED_AT) OffsetDateTime createdAt, + @JsonProperty(JSON_PROPERTY_MODIFIED_AT) OffsetDateTime modifiedAt) { this(); this.id = id; + this.size = size; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; } /** @@ -44,6 +81,115 @@ public String getId() { return id; } + public ApiGroupDto name(String name) { + this.name = name; + return this; + } + + /** + * Name of group if set. + * + * @return name + */ + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public String getName() { + return name; + } + + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setName(String name) { + this.name = name; + } + + /** + * The number of members currently in the group. + * + * @return size + */ + @JsonProperty(JSON_PROPERTY_SIZE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public Integer getSize() { + return size; + } + + /** + * Timestamp for when the group was created. YYYY-MM-DDThh:mm:ss.SSSZ format + * + * @return createdAt + */ + @JsonProperty(JSON_PROPERTY_CREATED_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + /** + * Timestamp for when the group was last updated. YYYY-MM-DDThh:mm:ss.SSSZ format + * + * @return modifiedAt + */ + @JsonProperty(JSON_PROPERTY_MODIFIED_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OffsetDateTime getModifiedAt() { + return modifiedAt; + } + + public ApiGroupDto childGroups(Set childGroups) { + this.childGroups = childGroups; + return this; + } + + public ApiGroupDto addChildGroupsItem(Object childGroupsItem) { + if (this.childGroups == null) { + this.childGroups = new LinkedHashSet<>(); + } + this.childGroups.add(childGroupsItem); + return this; + } + + /** + * MSISDNs of child group will be included in this group. If present then this group will be auto + * populated. Constraints: Elements must be group IDs. + * + * @return childGroups + */ + @JsonProperty(JSON_PROPERTY_CHILD_GROUPS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public Set getChildGroups() { + return childGroups; + } + + @JsonDeserialize(as = LinkedHashSet.class) + @JsonProperty(JSON_PROPERTY_CHILD_GROUPS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setChildGroups(Set childGroups) { + this.childGroups = childGroups; + } + + public ApiGroupDto autoUpdate(ApiGroupAutoUpdateDto autoUpdate) { + this.autoUpdate = autoUpdate; + return this; + } + + /** + * Get autoUpdate + * + * @return autoUpdate + */ + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public ApiGroupAutoUpdateDto getAutoUpdate() { + return autoUpdate; + } + + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setAutoUpdate(ApiGroupAutoUpdateDto autoUpdate) { + this.autoUpdate = autoUpdate; + } + /** Return true if this ApiGroup object is equal to o. */ @Override public boolean equals(Object o) { @@ -54,12 +200,18 @@ public boolean equals(Object o) { return false; } ApiGroupDto apiGroup = (ApiGroupDto) o; - return Objects.equals(this.id, apiGroup.id); + return Objects.equals(this.id, apiGroup.id) + && Objects.equals(this.name, apiGroup.name) + && Objects.equals(this.size, apiGroup.size) + && Objects.equals(this.createdAt, apiGroup.createdAt) + && Objects.equals(this.modifiedAt, apiGroup.modifiedAt) + && Objects.equals(this.childGroups, apiGroup.childGroups) + && Objects.equals(this.autoUpdate, apiGroup.autoUpdate); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(id, name, size, createdAt, modifiedAt, childGroups, autoUpdate); } @Override @@ -67,6 +219,12 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ApiGroupDto {\n"); sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" size: ").append(toIndentedString(size)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" modifiedAt: ").append(toIndentedString(modifiedAt)).append("\n"); + sb.append(" childGroups: ").append(toIndentedString(childGroups)).append("\n"); + sb.append(" autoUpdate: ").append(toIndentedString(autoUpdate)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ListGroups200ResponseDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupListDto.java similarity index 71% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ListGroups200ResponseDto.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupListDto.java index 3aa4b4cf..3dbf21e3 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ListGroups200ResponseDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupListDto.java @@ -19,30 +19,52 @@ import java.util.List; import java.util.Objects; -/** ListGroups200ResponseDto */ +/** ApiGroupListDto */ @JsonPropertyOrder({ - ListGroups200ResponseDto.JSON_PROPERTY_PAGE, - ListGroups200ResponseDto.JSON_PROPERTY_PAGE_SIZE, - ListGroups200ResponseDto.JSON_PROPERTY_COUNT, - ListGroups200ResponseDto.JSON_PROPERTY_GROUPS + ApiGroupListDto.JSON_PROPERTY_COUNT, + ApiGroupListDto.JSON_PROPERTY_PAGE, + ApiGroupListDto.JSON_PROPERTY_GROUPS, + ApiGroupListDto.JSON_PROPERTY_PAGE_SIZE }) // @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ListGroups200ResponseDto { +public class ApiGroupListDto { + public static final String JSON_PROPERTY_COUNT = "count"; + private Long count; + public static final String JSON_PROPERTY_PAGE = "page"; private Integer page; + public static final String JSON_PROPERTY_GROUPS = "groups"; + private List groups; + public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; private Integer pageSize; - public static final String JSON_PROPERTY_COUNT = "count"; - private Integer count; + public ApiGroupListDto() {} - public static final String JSON_PROPERTY_GROUPS = "groups"; - private List groups; + public ApiGroupListDto count(Long count) { + this.count = count; + return this; + } + + /** + * The total number of entries matching the given filters. + * + * @return count + */ + @JsonProperty(JSON_PROPERTY_COUNT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public Long getCount() { + return count; + } - public ListGroups200ResponseDto() {} + @JsonProperty(JSON_PROPERTY_COUNT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setCount(Long count) { + this.count = count; + } - public ListGroups200ResponseDto page(Integer page) { + public ApiGroupListDto page(Integer page) { this.page = page; return this; } @@ -64,81 +86,59 @@ public void setPage(Integer page) { this.page = page; } - public ListGroups200ResponseDto pageSize(Integer pageSize) { - this.pageSize = pageSize; + public ApiGroupListDto groups(List groups) { + this.groups = groups; return this; } - /** - * The number of groups returned in this request - * - * @return pageSize - */ - @JsonProperty(JSON_PROPERTY_PAGE_SIZE) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public Integer getPageSize() { - return pageSize; - } - - @JsonProperty(JSON_PROPERTY_PAGE_SIZE) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setPageSize(Integer pageSize) { - this.pageSize = pageSize; - } - - public ListGroups200ResponseDto count(Integer count) { - this.count = count; + public ApiGroupListDto addGroupsItem(ApiGroupDto groupsItem) { + if (this.groups == null) { + this.groups = new ArrayList<>(); + } + this.groups.add(groupsItem); return this; } /** - * The total number of groups. + * Get groups * - * @return count + * @return groups */ - @JsonProperty(JSON_PROPERTY_COUNT) + @JsonProperty(JSON_PROPERTY_GROUPS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public Integer getCount() { - return count; + public List getGroups() { + return groups; } - @JsonProperty(JSON_PROPERTY_COUNT) + @JsonProperty(JSON_PROPERTY_GROUPS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setCount(Integer count) { - this.count = count; - } - - public ListGroups200ResponseDto groups(List groups) { + public void setGroups(List groups) { this.groups = groups; - return this; } - public ListGroups200ResponseDto addGroupsItem(GroupObjectDto groupsItem) { - if (this.groups == null) { - this.groups = new ArrayList<>(); - } - this.groups.add(groupsItem); + public ApiGroupListDto pageSize(Integer pageSize) { + this.pageSize = pageSize; return this; } /** - * Get groups + * The number of entries returned in this request. * - * @return groups + * @return pageSize */ - @JsonProperty(JSON_PROPERTY_GROUPS) + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public List getGroups() { - return groups; + public Integer getPageSize() { + return pageSize; } - @JsonProperty(JSON_PROPERTY_GROUPS) + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setGroups(List groups) { - this.groups = groups; + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; } - /** Return true if this ListGroups_200_response object is equal to o. */ + /** Return true if this ApiGroupList object is equal to o. */ @Override public boolean equals(Object o) { if (this == o) { @@ -147,26 +147,26 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - ListGroups200ResponseDto listGroups200Response = (ListGroups200ResponseDto) o; - return Objects.equals(this.page, listGroups200Response.page) - && Objects.equals(this.pageSize, listGroups200Response.pageSize) - && Objects.equals(this.count, listGroups200Response.count) - && Objects.equals(this.groups, listGroups200Response.groups); + ApiGroupListDto apiGroupList = (ApiGroupListDto) o; + return Objects.equals(this.count, apiGroupList.count) + && Objects.equals(this.page, apiGroupList.page) + && Objects.equals(this.groups, apiGroupList.groups) + && Objects.equals(this.pageSize, apiGroupList.pageSize); } @Override public int hashCode() { - return Objects.hash(page, pageSize, count, groups); + return Objects.hash(count, page, groups, pageSize); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class ListGroups200ResponseDto {\n"); - sb.append(" page: ").append(toIndentedString(page)).append("\n"); - sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); + sb.append("class ApiGroupListDto {\n"); sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); sb.append(" groups: ").append(toIndentedString(groups)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiInboundListDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiInboundListDto.java index bc53514a..79cdbe36 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiInboundListDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiInboundListDto.java @@ -35,7 +35,7 @@ public class ApiInboundListDto { private Integer page; public static final String JSON_PROPERTY_INBOUNDS = "inbounds"; - private List inbounds; + private List inbounds; public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; private Integer pageSize; @@ -86,12 +86,12 @@ public void setPage(Integer page) { this.page = page; } - public ApiInboundListDto inbounds(List inbounds) { + public ApiInboundListDto inbounds(List inbounds) { this.inbounds = inbounds; return this; } - public ApiInboundListDto addInboundsItem(ApiInboundListInboundsInnerDto inboundsItem) { + public ApiInboundListDto addInboundsItem(InboundDto inboundsItem) { if (this.inbounds == null) { this.inbounds = new ArrayList<>(); } @@ -106,13 +106,13 @@ public ApiInboundListDto addInboundsItem(ApiInboundListInboundsInnerDto inbounds */ @JsonProperty(JSON_PROPERTY_INBOUNDS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public List getInbounds() { + public List getInbounds() { return inbounds; } @JsonProperty(JSON_PROPERTY_INBOUNDS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setInbounds(List inbounds) { + public void setInbounds(List inbounds) { this.inbounds = inbounds; } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/DryRunRequestDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/DryRunRequestDto.java deleted file mode 100644 index 2addfefa..00000000 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/DryRunRequestDto.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * API Overview | Sinch - * Sinch SMS API is one of the easiest APIs we offer and enables you to add fast and reliable global SMS to your applications. Send single messages, scheduled batch messages, use available message templates and more. - * - * The version of the OpenAPI document: v1 - * Contact: Support@sinch.com - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sinch.sdk.domains.sms.models.dto.v1; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.sinch.sdk.core.models.AbstractOpenApiSchema; -import com.sinch.sdk.core.utils.databind.JSONNavigator; -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -// @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -@JsonDeserialize(using = DryRunRequestDto.DryRunRequestDtoDeserializer.class) -@JsonSerialize(using = DryRunRequestDto.DryRunRequestDtoSerializer.class) -public class DryRunRequestDto extends AbstractOpenApiSchema { - private static final Logger log = Logger.getLogger(DryRunRequestDto.class.getName()); - - public static class DryRunRequestDtoSerializer extends StdSerializer { - public DryRunRequestDtoSerializer(Class t) { - super(t); - } - - public DryRunRequestDtoSerializer() { - this(null); - } - - @Override - public void serialize(DryRunRequestDto value, JsonGenerator jgen, SerializerProvider provider) - throws IOException, JsonProcessingException { - jgen.writeObject(value.getActualInstance()); - } - } - - public static class DryRunRequestDtoDeserializer extends StdDeserializer { - public DryRunRequestDtoDeserializer() { - this(DryRunRequestDto.class); - } - - public DryRunRequestDtoDeserializer(Class vc) { - super(vc); - } - - @Override - public DryRunRequestDto deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { - JsonNode tree = jp.readValueAsTree(); - Object deserialized = null; - boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); - int match = 0; - JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize BinaryRequestDto - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (BinaryRequestDto.class.equals(Integer.class) - || BinaryRequestDto.class.equals(Long.class) - || BinaryRequestDto.class.equals(Float.class) - || BinaryRequestDto.class.equals(Double.class) - || BinaryRequestDto.class.equals(Boolean.class) - || BinaryRequestDto.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= - ((BinaryRequestDto.class.equals(Integer.class) - || BinaryRequestDto.class.equals(Long.class)) - && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= - ((BinaryRequestDto.class.equals(Float.class) - || BinaryRequestDto.class.equals(Double.class)) - && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= - (BinaryRequestDto.class.equals(Boolean.class) - && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= - (BinaryRequestDto.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryRequestDto.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'BinaryRequestDto'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'BinaryRequestDto'", e); - } - - // deserialize MediaRequestDto - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (MediaRequestDto.class.equals(Integer.class) - || MediaRequestDto.class.equals(Long.class) - || MediaRequestDto.class.equals(Float.class) - || MediaRequestDto.class.equals(Double.class) - || MediaRequestDto.class.equals(Boolean.class) - || MediaRequestDto.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= - ((MediaRequestDto.class.equals(Integer.class) - || MediaRequestDto.class.equals(Long.class)) - && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= - ((MediaRequestDto.class.equals(Float.class) - || MediaRequestDto.class.equals(Double.class)) - && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= - (MediaRequestDto.class.equals(Boolean.class) - && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= - (MediaRequestDto.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaRequestDto.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'MediaRequestDto'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'MediaRequestDto'", e); - } - - // deserialize TextRequestDto - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (TextRequestDto.class.equals(Integer.class) - || TextRequestDto.class.equals(Long.class) - || TextRequestDto.class.equals(Float.class) - || TextRequestDto.class.equals(Double.class) - || TextRequestDto.class.equals(Boolean.class) - || TextRequestDto.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= - ((TextRequestDto.class.equals(Integer.class) - || TextRequestDto.class.equals(Long.class)) - && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= - ((TextRequestDto.class.equals(Float.class) - || TextRequestDto.class.equals(Double.class)) - && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= - (TextRequestDto.class.equals(Boolean.class) - && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= - (TextRequestDto.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(TextRequestDto.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'TextRequestDto'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'TextRequestDto'", e); - } - - if (match == 1) { - DryRunRequestDto ret = new DryRunRequestDto(); - ret.setActualInstance(deserialized); - return ret; - } - throw new IOException( - String.format( - "Failed deserialization for DryRunRequestDto: %d classes match result, expected 1", - match)); - } - - /** Handle deserialization of the 'null' value. */ - @Override - public DryRunRequestDto getNullValue(DeserializationContext ctxt) throws JsonMappingException { - throw new JsonMappingException(ctxt.getParser(), "DryRunRequestDto cannot be null"); - } - } - - // store a list of schema names defined in oneOf - public static final Map> schemas = new HashMap<>(); - - public DryRunRequestDto() { - super("oneOf", Boolean.FALSE); - } - - public DryRunRequestDto(BinaryRequestDto o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public DryRunRequestDto(MediaRequestDto o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public DryRunRequestDto(TextRequestDto o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - static { - schemas.put("BinaryRequestDto", BinaryRequestDto.class); - schemas.put("MediaRequestDto", MediaRequestDto.class); - schemas.put("TextRequestDto", TextRequestDto.class); - JSONNavigator.registerDescendants(DryRunRequestDto.class, Collections.unmodifiableMap(schemas)); - } - - @Override - public Map> getSchemas() { - return DryRunRequestDto.schemas; - } - - /** - * Set the instance that matches the oneOf child schema, check the instance parameter is valid - * against the oneOf child schemas: BinaryRequestDto, MediaRequestDto, TextRequestDto - * - *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a - * composed schema (allOf, anyOf, oneOf). - */ - @Override - public void setActualInstance(Object instance) { - if (JSONNavigator.isInstanceOf(BinaryRequestDto.class, instance, new HashSet>())) { - super.setActualInstance(instance); - return; - } - - if (JSONNavigator.isInstanceOf(MediaRequestDto.class, instance, new HashSet>())) { - super.setActualInstance(instance); - return; - } - - if (JSONNavigator.isInstanceOf(TextRequestDto.class, instance, new HashSet>())) { - super.setActualInstance(instance); - return; - } - - throw new RuntimeException( - "Invalid instance type. Must be BinaryRequestDto, MediaRequestDto, TextRequestDto"); - } - - /** - * Get the actual instance, which can be the following: BinaryRequestDto, MediaRequestDto, - * TextRequestDto - * - * @return The actual instance (BinaryRequestDto, MediaRequestDto, TextRequestDto) - */ - @Override - public Object getActualInstance() { - return super.getActualInstance(); - } - - /** - * Get the actual instance of `BinaryRequestDto`. If the actual instance is not - * `BinaryRequestDto`, the ClassCastException will be thrown. - * - * @return The actual instance of `BinaryRequestDto` - * @throws ClassCastException if the instance is not `BinaryRequestDto` - */ - public BinaryRequestDto getBinaryRequestDto() throws ClassCastException { - return (BinaryRequestDto) super.getActualInstance(); - } - - /** - * Get the actual instance of `MediaRequestDto`. If the actual instance is not `MediaRequestDto`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `MediaRequestDto` - * @throws ClassCastException if the instance is not `MediaRequestDto` - */ - public MediaRequestDto getMediaRequestDto() throws ClassCastException { - return (MediaRequestDto) super.getActualInstance(); - } - - /** - * Get the actual instance of `TextRequestDto`. If the actual instance is not `TextRequestDto`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `TextRequestDto` - * @throws ClassCastException if the instance is not `TextRequestDto` - */ - public TextRequestDto getTextRequestDto() throws ClassCastException { - return (TextRequestDto) super.getActualInstance(); - } -} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/GroupAutoUpdateDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/GroupAutoUpdateDto.java index b674a895..564d4a9c 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/GroupAutoUpdateDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/GroupAutoUpdateDto.java @@ -29,10 +29,10 @@ public class GroupAutoUpdateDto { private String to; public static final String JSON_PROPERTY_ADD = "add"; - private String add; + private AddKeywordDto add; public static final String JSON_PROPERTY_REMOVE = "remove"; - private String remove; + private RemoveKeywordDto remove; public GroupAutoUpdateDto() {} @@ -61,7 +61,7 @@ public void setTo(String to) { this.to = to; } - public GroupAutoUpdateDto add(String add) { + public GroupAutoUpdateDto add(AddKeywordDto add) { this.add = add; return this; } @@ -73,17 +73,17 @@ public GroupAutoUpdateDto add(String add) { */ @JsonProperty(JSON_PROPERTY_ADD) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public String getAdd() { + public AddKeywordDto getAdd() { return add; } @JsonProperty(JSON_PROPERTY_ADD) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setAdd(String add) { + public void setAdd(AddKeywordDto add) { this.add = add; } - public GroupAutoUpdateDto remove(String remove) { + public GroupAutoUpdateDto remove(RemoveKeywordDto remove) { this.remove = remove; return this; } @@ -95,13 +95,13 @@ public GroupAutoUpdateDto remove(String remove) { */ @JsonProperty(JSON_PROPERTY_REMOVE) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public String getRemove() { + public RemoveKeywordDto getRemove() { return remove; } @JsonProperty(JSON_PROPERTY_REMOVE) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setRemove(String remove) { + public void setRemove(RemoveKeywordDto remove) { this.remove = remove; } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiInboundListInboundsInnerDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/InboundDto.java similarity index 77% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiInboundListInboundsInnerDto.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/InboundDto.java index a34412ea..d6ca4359 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiInboundListInboundsInnerDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/InboundDto.java @@ -37,67 +37,68 @@ import java.util.logging.Logger; // @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -@JsonDeserialize( - using = ApiInboundListInboundsInnerDto.ApiInboundListInboundsInnerDtoDeserializer.class) -@JsonSerialize( - using = ApiInboundListInboundsInnerDto.ApiInboundListInboundsInnerDtoSerializer.class) -public class ApiInboundListInboundsInnerDto extends AbstractOpenApiSchema { - private static final Logger log = - Logger.getLogger(ApiInboundListInboundsInnerDto.class.getName()); +@JsonDeserialize(using = InboundDto.InboundDtoDeserializer.class) +@JsonSerialize(using = InboundDto.InboundDtoSerializer.class) +public class InboundDto extends AbstractOpenApiSchema { + private static final Logger log = Logger.getLogger(InboundDto.class.getName()); - public static class ApiInboundListInboundsInnerDtoSerializer - extends StdSerializer { - public ApiInboundListInboundsInnerDtoSerializer(Class t) { + public static class InboundDtoSerializer extends StdSerializer { + public InboundDtoSerializer(Class t) { super(t); } - public ApiInboundListInboundsInnerDtoSerializer() { + public InboundDtoSerializer() { this(null); } @Override - public void serialize( - ApiInboundListInboundsInnerDto value, JsonGenerator jgen, SerializerProvider provider) + public void serialize(InboundDto value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeObject(value.getActualInstance()); } } - public static class ApiInboundListInboundsInnerDtoDeserializer - extends StdDeserializer { - public ApiInboundListInboundsInnerDtoDeserializer() { - this(ApiInboundListInboundsInnerDto.class); + public static class InboundDtoDeserializer extends StdDeserializer { + public InboundDtoDeserializer() { + this(InboundDto.class); } - public ApiInboundListInboundsInnerDtoDeserializer(Class vc) { + public InboundDtoDeserializer(Class vc) { super(vc); } @Override - public ApiInboundListInboundsInnerDto deserialize(JsonParser jp, DeserializationContext ctxt) + public InboundDto deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; - ApiInboundListInboundsInnerDto newApiInboundListInboundsInnerDto = - new ApiInboundListInboundsInnerDto(); + InboundDto newInboundDto = new InboundDto(); Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String) result2.get("type"); switch (discriminatorValue) { case "MOBinary": deserialized = tree.traverse(jp.getCodec()).readValueAs(MOBinaryDto.class); - newApiInboundListInboundsInnerDto.setActualInstance(deserialized); - return newApiInboundListInboundsInnerDto; + newInboundDto.setActualInstance(deserialized); + return newInboundDto; case "MOText": deserialized = tree.traverse(jp.getCodec()).readValueAs(MOTextDto.class); - newApiInboundListInboundsInnerDto.setActualInstance(deserialized); - return newApiInboundListInboundsInnerDto; + newInboundDto.setActualInstance(deserialized); + return newInboundDto; + case "mo_binary": + deserialized = tree.traverse(jp.getCodec()).readValueAs(MOBinaryDto.class); + newInboundDto.setActualInstance(deserialized); + return newInboundDto; + case "mo_text": + deserialized = tree.traverse(jp.getCodec()).readValueAs(MOTextDto.class); + newInboundDto.setActualInstance(deserialized); + return newInboundDto; default: log.log( Level.WARNING, String.format( - "Failed to lookup discriminator value `%s` for ApiInboundListInboundsInnerDto." - + " Possible values: MOBinary MOText", + "Failed to lookup discriminator value `%s` for InboundDto. Possible values:" + + " MOBinary MOText mo_binary mo_text", discriminatorValue)); } @@ -181,39 +182,35 @@ public ApiInboundListInboundsInnerDto deserialize(JsonParser jp, Deserialization } if (match == 1) { - ApiInboundListInboundsInnerDto ret = new ApiInboundListInboundsInnerDto(); + InboundDto ret = new InboundDto(); ret.setActualInstance(deserialized); return ret; } throw new IOException( String.format( - "Failed deserialization for ApiInboundListInboundsInnerDto: %d classes match result," - + " expected 1", - match)); + "Failed deserialization for InboundDto: %d classes match result, expected 1", match)); } /** Handle deserialization of the 'null' value. */ @Override - public ApiInboundListInboundsInnerDto getNullValue(DeserializationContext ctxt) - throws JsonMappingException { - throw new JsonMappingException( - ctxt.getParser(), "ApiInboundListInboundsInnerDto cannot be null"); + public InboundDto getNullValue(DeserializationContext ctxt) throws JsonMappingException { + throw new JsonMappingException(ctxt.getParser(), "InboundDto cannot be null"); } } // store a list of schema names defined in oneOf public static final Map> schemas = new HashMap<>(); - public ApiInboundListInboundsInnerDto() { + public InboundDto() { super("oneOf", Boolean.FALSE); } - public ApiInboundListInboundsInnerDto(MOBinaryDto o) { + public InboundDto(MOBinaryDto o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } - public ApiInboundListInboundsInnerDto(MOTextDto o) { + public InboundDto(MOTextDto o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } @@ -221,19 +218,20 @@ public ApiInboundListInboundsInnerDto(MOTextDto o) { static { schemas.put("MOBinaryDto", MOBinaryDto.class); schemas.put("MOTextDto", MOTextDto.class); - JSONNavigator.registerDescendants( - ApiInboundListInboundsInnerDto.class, Collections.unmodifiableMap(schemas)); + JSONNavigator.registerDescendants(InboundDto.class, Collections.unmodifiableMap(schemas)); // Initialize and register the discriminator mappings. Map> mappings = new HashMap>(); mappings.put("MOBinary", MOBinaryDto.class); mappings.put("MOText", MOTextDto.class); - mappings.put("ApiInboundList_inbounds_inner", ApiInboundListInboundsInnerDto.class); - JSONNavigator.registerDiscriminator(ApiInboundListInboundsInnerDto.class, "type", mappings); + mappings.put("mo_binary", MOBinaryDto.class); + mappings.put("mo_text", MOTextDto.class); + mappings.put("Inbound", InboundDto.class); + JSONNavigator.registerDiscriminator(InboundDto.class, "type", mappings); } @Override public Map> getSchemas() { - return ApiInboundListInboundsInnerDto.schemas; + return InboundDto.schemas; } /** diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDto.java index f3fa0785..c7eca84a 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDto.java @@ -27,8 +27,8 @@ /** MOBinaryDto */ @JsonPropertyOrder({ MOBinaryDto.JSON_PROPERTY_BODY, - MOBinaryDto.JSON_PROPERTY_UDH, - MOBinaryDto.JSON_PROPERTY_TYPE + MOBinaryDto.JSON_PROPERTY_TYPE, + MOBinaryDto.JSON_PROPERTY_UDH }) // @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") /*@JsonIgnoreProperties( @@ -44,9 +44,6 @@ public class MOBinaryDto extends ApiMoMessageDto { public static final String JSON_PROPERTY_BODY = "body"; private String body; - public static final String JSON_PROPERTY_UDH = "udh"; - private String udh; - /** SMS in binary format */ public enum TypeEnum { MO_BINARY("mo_binary"), @@ -83,6 +80,9 @@ public static TypeEnum fromValue(String value) { public static final String JSON_PROPERTY_TYPE = "type"; private String type; + public static final String JSON_PROPERTY_UDH = "udh"; + private String udh; + public MOBinaryDto() {} @JsonCreator @@ -113,6 +113,17 @@ public void setBody(String body) { this.body = body; } + /** + * SMS in binary format + * + * @return type + */ + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getType() { + return type; + } + public MOBinaryDto udh(String udh) { this.udh = udh; return this; @@ -135,17 +146,6 @@ public void setUdh(String udh) { this.udh = udh; } - /** - * SMS in binary format - * - * @return type - */ - @JsonProperty(JSON_PROPERTY_TYPE) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public String getType() { - return type; - } - @Override public MOBinaryDto from(String from) { this.setFrom(from); @@ -199,14 +199,14 @@ public boolean equals(Object o) { } MOBinaryDto moBinary = (MOBinaryDto) o; return Objects.equals(this.body, moBinary.body) - && Objects.equals(this.udh, moBinary.udh) && Objects.equals(this.type, moBinary.type) + && Objects.equals(this.udh, moBinary.udh) && super.equals(o); } @Override public int hashCode() { - return Objects.hash(body, udh, type, super.hashCode()); + return Objects.hash(body, type, udh, super.hashCode()); } @Override @@ -215,8 +215,8 @@ public String toString() { sb.append("class MOBinaryDto {\n"); sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" body: ").append(toIndentedString(body)).append("\n"); - sb.append(" udh: ").append(toIndentedString(udh)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" udh: ").append(toIndentedString(udh)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDto.java index a0609af5..0bd4e708 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDto.java @@ -112,7 +112,7 @@ public void setBody(String body) { * @return type */ @JsonProperty(JSON_PROPERTY_TYPE) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) public String getType() { return type; } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RemoveKeywordDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RemoveKeywordDto.java new file mode 100644 index 00000000..83056d2e --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RemoveKeywordDto.java @@ -0,0 +1,118 @@ +/* + * API Overview | Sinch + * Sinch SMS API is one of the easiest APIs we offer and enables you to add fast and reliable global SMS to your applications. Send single messages, scheduled batch messages, use available message templates and more. + * + * The version of the OpenAPI document: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.Objects; + +/** Keyword to be sent in MO to remove MSISDN to a group */ +@JsonPropertyOrder({ + RemoveKeywordDto.JSON_PROPERTY_FIRST_WORD, + RemoveKeywordDto.JSON_PROPERTY_SECOND_WORD +}) +// @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class RemoveKeywordDto { + public static final String JSON_PROPERTY_FIRST_WORD = "first_word"; + private String firstWord; + + public static final String JSON_PROPERTY_SECOND_WORD = "second_word"; + private String secondWord; + + public RemoveKeywordDto() {} + + public RemoveKeywordDto firstWord(String firstWord) { + this.firstWord = firstWord; + return this; + } + + /** + * Opt-out keyword like \"LEAVE\" if _auto_update.to_ is dedicated long/short number or + * unique brand keyword like \"Sinch\" if it is a shared short code. + * + * @return firstWord + */ + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getFirstWord() { + return firstWord; + } + + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public void setFirstWord(String firstWord) { + this.firstWord = firstWord; + } + + public RemoveKeywordDto secondWord(String secondWord) { + this.secondWord = secondWord; + return this; + } + + /** + * Opt-out keyword like \"LEAVE\" if _auto_update.to_ is shared short code. + * + * @return secondWord + */ + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public String getSecondWord() { + return secondWord; + } + + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public void setSecondWord(String secondWord) { + this.secondWord = secondWord; + } + + /** Return true if this removeKeyword object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RemoveKeywordDto removeKeyword = (RemoveKeywordDto) o; + return Objects.equals(this.firstWord, removeKeyword.firstWord) + && Objects.equals(this.secondWord, removeKeyword.secondWord); + } + + @Override + public int hashCode() { + return Objects.hash(firstWord, secondWord); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class RemoveKeywordDto {\n"); + sb.append(" firstWord: ").append(toIndentedString(firstWord)).append("\n"); + sb.append(" secondWord: ").append(toIndentedString(secondWord)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessage200ResponseDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessage200ResponseDto.java deleted file mode 100644 index 0fa520b5..00000000 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessage200ResponseDto.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * API Overview | Sinch - * Sinch SMS API is one of the easiest APIs we offer and enables you to add fast and reliable global SMS to your applications. Send single messages, scheduled batch messages, use available message templates and more. - * - * The version of the OpenAPI document: v1 - * Contact: Support@sinch.com - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sinch.sdk.domains.sms.models.dto.v1; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.sinch.sdk.core.models.AbstractOpenApiSchema; -import com.sinch.sdk.core.utils.databind.JSONNavigator; -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -// @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -@JsonDeserialize( - using = - RetrieveInboundMessage200ResponseDto.RetrieveInboundMessage200ResponseDtoDeserializer.class) -@JsonSerialize( - using = - RetrieveInboundMessage200ResponseDto.RetrieveInboundMessage200ResponseDtoSerializer.class) -public class RetrieveInboundMessage200ResponseDto extends AbstractOpenApiSchema { - private static final Logger log = - Logger.getLogger(RetrieveInboundMessage200ResponseDto.class.getName()); - - public static class RetrieveInboundMessage200ResponseDtoSerializer - extends StdSerializer { - public RetrieveInboundMessage200ResponseDtoSerializer( - Class t) { - super(t); - } - - public RetrieveInboundMessage200ResponseDtoSerializer() { - this(null); - } - - @Override - public void serialize( - RetrieveInboundMessage200ResponseDto value, JsonGenerator jgen, SerializerProvider provider) - throws IOException, JsonProcessingException { - jgen.writeObject(value.getActualInstance()); - } - } - - public static class RetrieveInboundMessage200ResponseDtoDeserializer - extends StdDeserializer { - public RetrieveInboundMessage200ResponseDtoDeserializer() { - this(RetrieveInboundMessage200ResponseDto.class); - } - - public RetrieveInboundMessage200ResponseDtoDeserializer(Class vc) { - super(vc); - } - - @Override - public RetrieveInboundMessage200ResponseDto deserialize( - JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { - JsonNode tree = jp.readValueAsTree(); - Object deserialized = null; - RetrieveInboundMessage200ResponseDto newRetrieveInboundMessage200ResponseDto = - new RetrieveInboundMessage200ResponseDto(); - Map result2 = - tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); - String discriminatorValue = (String) result2.get("type"); - switch (discriminatorValue) { - case "MOBinary": - deserialized = tree.traverse(jp.getCodec()).readValueAs(MOBinaryDto.class); - newRetrieveInboundMessage200ResponseDto.setActualInstance(deserialized); - return newRetrieveInboundMessage200ResponseDto; - case "MOText": - deserialized = tree.traverse(jp.getCodec()).readValueAs(MOTextDto.class); - newRetrieveInboundMessage200ResponseDto.setActualInstance(deserialized); - return newRetrieveInboundMessage200ResponseDto; - case "mo_binary": - deserialized = tree.traverse(jp.getCodec()).readValueAs(MOBinaryDto.class); - newRetrieveInboundMessage200ResponseDto.setActualInstance(deserialized); - return newRetrieveInboundMessage200ResponseDto; - case "mo_text": - deserialized = tree.traverse(jp.getCodec()).readValueAs(MOTextDto.class); - newRetrieveInboundMessage200ResponseDto.setActualInstance(deserialized); - return newRetrieveInboundMessage200ResponseDto; - default: - log.log( - Level.WARNING, - String.format( - "Failed to lookup discriminator value `%s` for" - + " RetrieveInboundMessage200ResponseDto. Possible values: MOBinary MOText" - + " mo_binary mo_text", - discriminatorValue)); - } - - boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); - int match = 0; - JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize MOBinaryDto - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (MOBinaryDto.class.equals(Integer.class) - || MOBinaryDto.class.equals(Long.class) - || MOBinaryDto.class.equals(Float.class) - || MOBinaryDto.class.equals(Double.class) - || MOBinaryDto.class.equals(Boolean.class) - || MOBinaryDto.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= - ((MOBinaryDto.class.equals(Integer.class) || MOBinaryDto.class.equals(Long.class)) - && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= - ((MOBinaryDto.class.equals(Float.class) || MOBinaryDto.class.equals(Double.class)) - && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= - (MOBinaryDto.class.equals(Boolean.class) - && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= - (MOBinaryDto.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(MOBinaryDto.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'MOBinaryDto'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'MOBinaryDto'", e); - } - - // deserialize MOTextDto - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (MOTextDto.class.equals(Integer.class) - || MOTextDto.class.equals(Long.class) - || MOTextDto.class.equals(Float.class) - || MOTextDto.class.equals(Double.class) - || MOTextDto.class.equals(Boolean.class) - || MOTextDto.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= - ((MOTextDto.class.equals(Integer.class) || MOTextDto.class.equals(Long.class)) - && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= - ((MOTextDto.class.equals(Float.class) || MOTextDto.class.equals(Double.class)) - && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= - (MOTextDto.class.equals(Boolean.class) - && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= - (MOTextDto.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(MOTextDto.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'MOTextDto'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'MOTextDto'", e); - } - - if (match == 1) { - RetrieveInboundMessage200ResponseDto ret = new RetrieveInboundMessage200ResponseDto(); - ret.setActualInstance(deserialized); - return ret; - } - throw new IOException( - String.format( - "Failed deserialization for RetrieveInboundMessage200ResponseDto: %d classes match" - + " result, expected 1", - match)); - } - - /** Handle deserialization of the 'null' value. */ - @Override - public RetrieveInboundMessage200ResponseDto getNullValue(DeserializationContext ctxt) - throws JsonMappingException { - throw new JsonMappingException( - ctxt.getParser(), "RetrieveInboundMessage200ResponseDto cannot be null"); - } - } - - // store a list of schema names defined in oneOf - public static final Map> schemas = new HashMap<>(); - - public RetrieveInboundMessage200ResponseDto() { - super("oneOf", Boolean.FALSE); - } - - public RetrieveInboundMessage200ResponseDto(MOBinaryDto o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - public RetrieveInboundMessage200ResponseDto(MOTextDto o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - - static { - schemas.put("MOBinaryDto", MOBinaryDto.class); - schemas.put("MOTextDto", MOTextDto.class); - JSONNavigator.registerDescendants( - RetrieveInboundMessage200ResponseDto.class, Collections.unmodifiableMap(schemas)); - // Initialize and register the discriminator mappings. - Map> mappings = new HashMap>(); - mappings.put("MOBinary", MOBinaryDto.class); - mappings.put("MOText", MOTextDto.class); - mappings.put("mo_binary", MOBinaryDto.class); - mappings.put("mo_text", MOTextDto.class); - mappings.put("RetrieveInboundMessage_200_response", RetrieveInboundMessage200ResponseDto.class); - JSONNavigator.registerDiscriminator( - RetrieveInboundMessage200ResponseDto.class, "type", mappings); - } - - @Override - public Map> getSchemas() { - return RetrieveInboundMessage200ResponseDto.schemas; - } - - /** - * Set the instance that matches the oneOf child schema, check the instance parameter is valid - * against the oneOf child schemas: MOBinaryDto, MOTextDto - * - *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a - * composed schema (allOf, anyOf, oneOf). - */ - @Override - public void setActualInstance(Object instance) { - if (JSONNavigator.isInstanceOf(MOBinaryDto.class, instance, new HashSet>())) { - super.setActualInstance(instance); - return; - } - - if (JSONNavigator.isInstanceOf(MOTextDto.class, instance, new HashSet>())) { - super.setActualInstance(instance); - return; - } - - throw new RuntimeException("Invalid instance type. Must be MOBinaryDto, MOTextDto"); - } - - /** - * Get the actual instance, which can be the following: MOBinaryDto, MOTextDto - * - * @return The actual instance (MOBinaryDto, MOTextDto) - */ - @Override - public Object getActualInstance() { - return super.getActualInstance(); - } - - /** - * Get the actual instance of `MOBinaryDto`. If the actual instance is not `MOBinaryDto`, the - * ClassCastException will be thrown. - * - * @return The actual instance of `MOBinaryDto` - * @throws ClassCastException if the instance is not `MOBinaryDto` - */ - public MOBinaryDto getMOBinaryDto() throws ClassCastException { - return (MOBinaryDto) super.getActualInstance(); - } - - /** - * Get the actual instance of `MOTextDto`. If the actual instance is not `MOTextDto`, the - * ClassCastException will be thrown. - * - * @return The actual instance of `MOTextDto` - * @throws ClassCastException if the instance is not `MOTextDto` - */ - public MOTextDto getMOTextDto() throws ClassCastException { - return (MOTextDto) super.getActualInstance(); - } -} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java index d41b118d..17d2c358 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; @@ -75,6 +76,48 @@ public UpdateBatchMessageRequestDto deserialize(JsonParser jp, DeserializationCo throws IOException, JsonProcessingException { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; + UpdateBatchMessageRequestDto newUpdateBatchMessageRequestDto = + new UpdateBatchMessageRequestDto(); + Map result2 = + tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + String discriminatorValue = (String) result2.get("type"); + switch (discriminatorValue) { + case "ApiUpdateBinaryMtMessage": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(ApiUpdateBinaryMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "ApiUpdateMmsMtMessage": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateMmsMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "ApiUpdateTextMtMessage": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateTextMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "mt_binary": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(ApiUpdateBinaryMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "mt_media": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateMmsMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "mt_text": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateTextMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + default: + log.log( + Level.WARNING, + String.format( + "Failed to lookup discriminator value `%s` for UpdateBatchMessageRequestDto." + + " Possible values: ApiUpdateBinaryMtMessage ApiUpdateMmsMtMessage" + + " ApiUpdateTextMtMessage mt_binary mt_media mt_text", + discriminatorValue)); + } + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); @@ -251,6 +294,16 @@ public UpdateBatchMessageRequestDto(ApiUpdateTextMtMessageDto o) { schemas.put("ApiUpdateTextMtMessageDto", ApiUpdateTextMtMessageDto.class); JSONNavigator.registerDescendants( UpdateBatchMessageRequestDto.class, Collections.unmodifiableMap(schemas)); + // Initialize and register the discriminator mappings. + Map> mappings = new HashMap>(); + mappings.put("ApiUpdateBinaryMtMessage", ApiUpdateBinaryMtMessageDto.class); + mappings.put("ApiUpdateMmsMtMessage", ApiUpdateMmsMtMessageDto.class); + mappings.put("ApiUpdateTextMtMessage", ApiUpdateTextMtMessageDto.class); + mappings.put("mt_binary", ApiUpdateBinaryMtMessageDto.class); + mappings.put("mt_media", ApiUpdateMmsMtMessageDto.class); + mappings.put("mt_text", ApiUpdateTextMtMessageDto.class); + mappings.put("UpdateBatchMessage_request", UpdateBatchMessageRequestDto.class); + JSONNavigator.registerDiscriminator(UpdateBatchMessageRequestDto.class, "type", mappings); } @Override diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportBatchDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportBatchDtoTest.java new file mode 100644 index 00000000..8966cfee --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportBatchDtoTest.java @@ -0,0 +1,56 @@ +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import java.util.Collections; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class DeliveryReportBatchDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + DeliveryReportDto deliveryReportBatchSMSDto; + + @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + DeliveryReportDto deliveryReportBatchMMSDto; + + public static DeliveryReportDto deliveryReportBatchSMS = + new DeliveryReportDto("01FC66621XXXXX119Z8PMV1QPQ") + .type("delivery_report_sms") + .statuses( + Collections.singletonList( + new MessageDeliveryStatusDto() + .code(0) + .count(1) + .addRecipientsItem("44231235674") + .status("Delivered"))) + .totalMessageCount(1); + + public static DeliveryReportDto deliveryReportBatchMMS = + new DeliveryReportDto("01FC66621XXXXX119Z8PMV1QPQ") + .type("delivery_report_mms") + .statuses( + Collections.singletonList( + new MessageDeliveryStatusDto() + .code(0) + .count(1) + .addRecipientsItem("44231235674") + .status("Delivered"))) + .totalMessageCount(1); + + @Test + void deserializeDeliveryReportBatchSMS() { + Assertions.assertThat(deliveryReportBatchSMS) + .usingRecursiveComparison() + .isEqualTo(deliveryReportBatchSMSDto); + } + + @Test + void deserializeDeliveryReportBatchMMS() { + Assertions.assertThat(deliveryReportBatchMMS) + .usingRecursiveComparison() + .isEqualTo(deliveryReportBatchMMSDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportRecipientDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportRecipientDtoTest.java new file mode 100644 index 00000000..690b26ce --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportRecipientDtoTest.java @@ -0,0 +1,60 @@ +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import java.time.OffsetDateTime; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class DeliveryReportRecipientDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") + RecipientDeliveryReportDto deliveryReportRecipientSMSDto; + + @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientMMSDto.json") + RecipientDeliveryReportDto deliveryReportRecipientMMSDto; + + public static RecipientDeliveryReportDto deliveryReportRecipientSMS = + new RecipientDeliveryReportDto("01FC66621XXXXX119Z8PMV1QPQ") + .type("recipient_delivery_report_sms") + .clientReference("client reference") + .at(OffsetDateTime.parse("2022-08-30T08:16:08.930Z")) + .code(401) + .recipient("+44231235674") + .status("Dispatched") + .appliedOriginator("applied originator") + .encoding("encoding") + .numberOfMessageParts(123) + .operator("operator") + .operatorStatusAt(OffsetDateTime.parse("2022-08-30T08:16:08.150Z")); + + public static RecipientDeliveryReportDto deliveryReportRecipientMMS = + new RecipientDeliveryReportDto("01FC66621XXXXX119Z8PMV1QPQ") + .type("recipient_delivery_report_mms") + .clientReference("client reference") + .at(OffsetDateTime.parse("2022-08-30T08:16:08.930Z")) + .code(401) + .recipient("+44231235674") + .status("Dispatched") + .appliedOriginator("applied originator") + .encoding("encoding") + .numberOfMessageParts(123) + .operator("operator") + .operatorStatusAt(OffsetDateTime.parse("2022-08-30T08:16:08.150Z")); + + @Test + void deserializeDeliveryReportRecipientSMS() { + Assertions.assertThat(deliveryReportRecipientSMS) + .usingRecursiveComparison() + .isEqualTo(deliveryReportRecipientSMSDto); + } + + @Test + void deserializeDeliveryReportRecipientMMS() { + Assertions.assertThat(deliveryReportRecipientMMS) + .usingRecursiveComparison() + .isEqualTo(deliveryReportRecipientMMSDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java new file mode 100644 index 00000000..4ca65dc4 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java @@ -0,0 +1,48 @@ +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import java.util.Collections; +import org.assertj.core.api.Assertions; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class DryRunResponseDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") + DryRun200ResponseDto loadedDto; + + @GivenTextResource("/domains/sms/v1/DryRunResponseDto.json") + String jsonStringDto; + + DryRun200ResponseDto dto = + new DryRun200ResponseDto() + .numberOfRecipients(123) + .numberOfMessages(456) + .perRecipient( + Collections.singletonList( + new DryRun200ResponsePerRecipientInnerDto() + .recipient("recipient string") + .messagePart("message part string") + .body("body string") + .encoding("encoding string"))); + + @Test + void deserialize() { + + Assertions.assertThat(loadedDto).usingRecursiveComparison().isEqualTo(dto); + } + + @Test + void serialize() throws JsonProcessingException, JSONException { + + String serializedString = objectMapper.writeValueAsString(dto); + + JSONAssert.assertEquals(jsonStringDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java new file mode 100644 index 00000000..a5dcb61d --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java @@ -0,0 +1,44 @@ +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import java.time.OffsetDateTime; +import java.util.Arrays; +import java.util.HashSet; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +@TestWithResources +class GroupResponseDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/GroupResponseDto.json") + CreateGroupResponseDto createGroupResponseDto; + + Integer size = 2; + OffsetDateTime createdAt = OffsetDateTime.parse("2019-08-24T14:15:22Z"); + OffsetDateTime modifiedAt = OffsetDateTime.parse("2019-08-24T14:15:44Z"); + CreateGroupResponseDto groupResponse = + new CreateGroupResponseDto(size, createdAt, modifiedAt) + .id("01FC66621XXXXX119Z8PMV1QPU") + .name("My new customers") + .childGroups( + new HashSet<>( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00"))) + .autoUpdate( + new GroupAutoUpdateDto() + .to("15551231234") + .add(new AddKeywordDto().firstWord("Add 1st keyword")) + .remove( + new RemoveKeywordDto() + .firstWord("remove 1st keyword") + .secondWord("remove 2nd keyword"))); + + @Test + void deserializeGroup() { + + Assertions.assertThat(createGroupResponseDto) + .usingRecursiveComparison() + .isEqualTo(groupResponse); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessage200ResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java similarity index 79% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessage200ResponseDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java index d47a6278..8e36a4b9 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessage200ResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java @@ -8,13 +8,13 @@ import org.junit.jupiter.api.Test; @TestWithResources -class RetrieveInboundMessage200ResponseDtoTest extends BaseTest { +class InboundDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/MOBinaryDto.json") - RetrieveInboundMessage200ResponseDto loadedBinaryMessage; + InboundDto loadedBinaryMessage; @GivenJsonResource("/domains/sms/v1/MOTextDto.json") - RetrieveInboundMessage200ResponseDto loadedTextMessage; + InboundDto loadedTextMessage; MOBinaryDto binaryDTO = new MOBinaryDto("mo_binary") @@ -39,11 +39,9 @@ class RetrieveInboundMessage200ResponseDtoTest extends BaseTest { .operatorId("35000") .sentAt(OffsetDateTime.parse("2019-08-24T14:15:22Z")); - RetrieveInboundMessage200ResponseDto expectedBinaryMessageDto = - new RetrieveInboundMessage200ResponseDto(binaryDTO); + InboundDto expectedBinaryMessageDto = new InboundDto(binaryDTO); - RetrieveInboundMessage200ResponseDto expectedTextMessageDto = - new RetrieveInboundMessage200ResponseDto(textDTO); + InboundDto expectedTextMessageDto = new InboundDto(textDTO); @Test void deserializeBinaryMessage() { diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java index 6366473f..97791df9 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java @@ -12,7 +12,7 @@ import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources -class MOBinaryDtoTest extends BaseTest { +public class MOBinaryDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/MOBinaryDto.json") MOBinaryDto loadedDto; @@ -20,7 +20,7 @@ class MOBinaryDtoTest extends BaseTest { @GivenTextResource("/domains/sms/v1/MOBinaryDto.json") String jsonStringDto; - MOBinaryDto dto = + public static MOBinaryDto dto = new MOBinaryDto(MOBinaryDto.TypeEnum.MO_BINARY.getValue()) .from("+11203494390") .id("01FC66621XXXXX119Z8PMV1QPA") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java index 490d3f52..066aa97a 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java @@ -12,7 +12,7 @@ import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources -class MOTextDtoTest extends BaseTest { +public class MOTextDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/MOTextDto.json") MOTextDto loadedDto; @@ -20,7 +20,7 @@ class MOTextDtoTest extends BaseTest { @GivenTextResource("/domains/sms/v1/MOTextDto.json") String jsonStringDto; - MOTextDto dto = + public static MOTextDto dto = new MOTextDto(MOTextDto.TypeEnum.MO_TEXT.getValue()) .from("+11203494390") .id("01FC66621XXXXX119Z8PMV1QPA") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java index e979efea..8c3484be 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java @@ -56,16 +56,21 @@ void serializeBinaryRequestDto() throws JsonProcessingException, JSONException { @Test void serializeTextRequestDto() throws JsonProcessingException, JSONException { - Map map = + ParameterObjDto parameterObjDto = new ParameterObjDto(); + parameterObjDto.put( + "an identifier", + Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( + ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, Stream.of( - new AbstractMap.SimpleEntry<>("12345678910", "Joe"), new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "there")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - ParameterObjDto parameterObjDto = new ParameterObjDto(); - - parameterObjDto.put("name", map); + ParameterObjParameterKeyDto + .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, + "msisdn value"), + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); TextRequestDto textRequestDTO = new TextRequestDto() .to(Arrays.asList("+15551231234", "+15551256344")) @@ -95,16 +100,22 @@ void serializeTextRequestDto() throws JsonProcessingException, JSONException { @Test void serializeMediaRequestDto() throws JsonProcessingException, JSONException { - Map map = + ParameterObjDto parameterObjDto = new ParameterObjDto(); + parameterObjDto.put( + "an identifier", + Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( + ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, Stream.of( - new AbstractMap.SimpleEntry<>("12345678910", "Joe"), new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "there")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - ParameterObjDto parameterObjDto = new ParameterObjDto(); + ParameterObjParameterKeyDto + .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, + "msisdn value"), + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); - parameterObjDto.put("name", map); MediaRequestDto mediaRequestDTO = new MediaRequestDto("mt_media") .to(Arrays.asList("+15551231234", "+15551256344")) @@ -114,7 +125,7 @@ void serializeMediaRequestDto() throws JsonProcessingException, JSONException { "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") .message("Media message from Sinch!")) .from("+15551231234") - .deliveryReport("none") + .deliveryReport("summary") .sendAt(OffsetDateTime.parse("2019-08-24T14:16:22Z")) .expireAt(OffsetDateTime.parse("2019-08-24T14:17:22Z")) .callbackUrl("callback url") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMS201ResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java similarity index 99% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMS201ResponseDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java index 3bfef85b..82c8b95e 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMS201ResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test; @TestWithResources -class SendSMS201ResponseDtoTest extends BaseTest { +class SendSMSResponseDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/BinaryResponseDto.json") SendSMS201ResponseDto loadedBinary; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java new file mode 100644 index 00000000..66bcddf6 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java @@ -0,0 +1,132 @@ +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import java.time.OffsetDateTime; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class UpdateSMSRequestDtoTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/UpdateSMSBinaryRequestDto.json") + String jsonRequestBinaryDto; + + @GivenTextResource("/domains/sms/v1/UpdateSMSTextRequestDto.json") + String jsonRequestTextDto; + + @GivenTextResource("/domains/sms/v1/UpdateSMSMediaRequestDto.json") + String jsonRequestMediaDto; + + @Test + void serializeBinaryRequestDto() throws JsonProcessingException, JSONException { + + ApiUpdateBinaryMtMessageDto binaryRequestDTO = + new ApiUpdateBinaryMtMessageDto() + .toAdd(Arrays.asList("+15551231234", "+15987365412")) + .toRemove(Arrays.asList("+0123456789", "+9876543210")) + .body("Hi ${name}! How are you?") + .udh("foo udh") + .from("+15551231234") + .type("mt_binary") + .deliveryReport("full") + .sendAt(OffsetDateTime.parse("2019-08-24T14:19:22Z")) + .expireAt(OffsetDateTime.parse("2019-08-24T14:21:22Z")) + .callbackUrl("callback url"); + UpdateBatchMessageRequestDto sendSMSRequestDto = + new UpdateBatchMessageRequestDto(binaryRequestDTO); + + String serializedString = objectMapper.writeValueAsString(sendSMSRequestDto); + + JSONAssert.assertEquals(jsonRequestBinaryDto, serializedString, true); + } + + @Test + void serializeTextRequestDto() throws JsonProcessingException, JSONException { + + ParameterObjDto parameterObjDto = new ParameterObjDto(); + parameterObjDto.put( + "an identifier", + Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( + ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + Stream.of( + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto + .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, + "msisdn value"), + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + ApiUpdateTextMtMessageDto textRequestDTO = + new ApiUpdateTextMtMessageDto() + .toAdd(Arrays.asList("+15551231234", "+15551256344")) + .body("Hi ${name}! How are you?") + .from("+15551231234") + .type("mt_text") + .deliveryReport("none") + .sendAt(OffsetDateTime.parse("2019-08-24T14:19:22Z")) + .expireAt(OffsetDateTime.parse("2019-08-24T14:21:22Z")) + .callbackUrl("callback url") + .parameters(parameterObjDto); + + UpdateBatchMessageRequestDto sendSMSRequestDto = + new UpdateBatchMessageRequestDto(textRequestDTO); + + String serializedString = objectMapper.writeValueAsString(sendSMSRequestDto); + + JSONAssert.assertEquals(jsonRequestTextDto, serializedString, true); + } + + @Test + void serializeMediaRequestDto() throws JsonProcessingException, JSONException { + + ParameterObjDto parameterObjDto = new ParameterObjDto(); + parameterObjDto.put( + "an identifier", + Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( + ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + Stream.of( + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto + .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, + "msisdn value"), + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + + ApiUpdateMmsMtMessageDto mediaRequestDTO = + new ApiUpdateMmsMtMessageDto() + .type("mt_media") + .toRemove(Arrays.asList("+15551231234", "+15551256344")) + .body( + new MediaBodyDto() + .url( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .message("Media message from Sinch!")) + .from("+15551231234") + .deliveryReport("summary") + .sendAt(OffsetDateTime.parse("2019-08-24T14:16:22Z")) + .expireAt(OffsetDateTime.parse("2019-08-24T14:17:22Z")) + .callbackUrl("callback url") + .strictValidation(true) + .parameters(parameterObjDto); + + UpdateBatchMessageRequestDto sendSMSRequestDto = + new UpdateBatchMessageRequestDto(mediaRequestDTO); + + String serializedString = objectMapper.writeValueAsString(sendSMSRequestDto); + + JSONAssert.assertEquals(jsonRequestMediaDto, serializedString, true); + } +} diff --git a/sample-app/README.md b/sample-app/README.md index 4576d2ac..c4d5bb0e 100644 --- a/sample-app/README.md +++ b/sample-app/README.md @@ -49,19 +49,38 @@ See https://developers.sinch.com for details about these parameters ## Available samples classes -| API | Service | Sample | Class | Notes | -|---------|-----------|-----------|---------------------------------------------------------------------------------------------------------------|----------------------------------| -| Numbers | Available | - Get | [com.sinch.sample.numbers.available.Get](src/main/java/com/sinch/sample/numbers/available/Get.java) | Require `PHONE_NUMBER` parameter | -| | | - ListAll | [com.sinch.sample.numbers.available.ListAll](src/main/java/com/sinch/sample/numbers/available/ListAll.java) | | -| | | - Rent | [com.sinch.sample.numbers.available.Rent](src/main/java/com/sinch/sample/numbers/available/Rent.java) | Require `PHONE_NUMBER` parameter | -| | | - RentAny | [com.sinch.sample.numbers.available.RentAny](src/main/java/com/sinch/sample/numbers/available/RentAny.java) | | -| | Active | - Get | [com.sinch.sample.numbers.active.Get](src/main/java/com/sinch/sample/numbers/active/Get.java) | Require `PHONE_NUMBER` parameter | -| | | - List | [com.sinch.sample.numbers.active.List](src/main/java/com/sinch/sample/numbers/active/List.java) | | -| | | - Release | [com.sinch.sample.numbers.active.Release](src/main/java/com/sinch/sample/numbers/active/Release.java) | Require `PHONE_NUMBER` parameter | -| | | - Update | [com.sinch.sample.numbers.active.Update](src/main/java/com/sinch/sample/numbers/active/Update.java) | Require `PHONE_NUMBER` parameter | -| | Callback | - Get | [com.sinch.sample.numbers.callback.Get](src/main/java/com/sinch/sample/numbers/callback/Get.java) | | -| | | - Update | [com.sinch.sample.numbers.callback.Update](src/main/java/com/sinch/sample/numbers/callback/Get.java) | | -| | Regions | - ListAll | [com.sinch.sample.numbers.regions.ListAll](src/main/java/com/sinch/sample/numbers/regions/ListAll.java) | | -| SMS | Batches | - Get | [com.sinch.sample.sms.batches.Get](src/main/java/com/sinch/sample/sms/batches/Get.java) | Require `BATCH_ID` parameter | - - +| API | Service | Sample | Class | Notes | +|---------|----------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------| +| Numbers | Available | - Get | [com.sinch.sample.numbers.available.Get](src/main/java/com/sinch/sample/numbers/available/Get.java) | Require `PHONE_NUMBER` parameter | +| | | - ListAll | [com.sinch.sample.numbers.available.ListAll](src/main/java/com/sinch/sample/numbers/available/ListAll.java) | | +| | | - Rent | [com.sinch.sample.numbers.available.Rent](src/main/java/com/sinch/sample/numbers/available/Rent.java) | Require `PHONE_NUMBER` parameter | +| | | - RentAny | [com.sinch.sample.numbers.available.RentAny](src/main/java/com/sinch/sample/numbers/available/RentAny.java) | | +| | Active | - Get | [com.sinch.sample.numbers.active.Get](src/main/java/com/sinch/sample/numbers/active/Get.java) | Require `PHONE_NUMBER` parameter | +| | | - List | [com.sinch.sample.numbers.active.List](src/main/java/com/sinch/sample/numbers/active/List.java) | | +| | | - Release | [com.sinch.sample.numbers.active.Release](src/main/java/com/sinch/sample/numbers/active/Release.java) | Require `PHONE_NUMBER` parameter | +| | | - Update | [com.sinch.sample.numbers.active.Update](src/main/java/com/sinch/sample/numbers/active/Update.java) | Require `PHONE_NUMBER` parameter | +| | Callback | - Get | [com.sinch.sample.numbers.callback.Get](src/main/java/com/sinch/sample/numbers/callback/Get.java) | | +| | | - Update | [com.sinch.sample.numbers.callback.Update](src/main/java/com/sinch/sample/numbers/callback/Get.java) | | +| | Regions | - ListAll | [com.sinch.sample.numbers.regions.ListAll](src/main/java/com/sinch/sample/numbers/regions/ListAll.java) | | +| SMS | Batches | - Get | [com.sinch.sample.sms.batches.Get](src/main/java/com/sinch/sample/sms/batches/Get.java) | Require `BATCH_ID` parameter | +| | | - List | [com.sinch.sample.sms.batches.List](src/main/java/com/sinch/sample/sms/batches/List.java) | | +| | | - Send | [com.sinch.sample.sms.batches.Send](src/main/java/com/sinch/sample/sms/batches/Send.java) | | +| | | - Replace | [com.sinch.sample.sms.batches.Replace](src/main/java/com/sinch/sample/sms/batches/Replace.java) | Require `BATCH_ID` parameter | +| | | - Update | [com.sinch.sample.sms.batches.Update](src/main/java/com/sinch/sample/sms/batches/Update.java) | Require `BATCH_ID` parameter | +| | | - DryRun | [com.sinch.sample.sms.batches.DryRun](src/main/java/com/sinch/sample/sms/batches/dryRun.java) | | +| | | - Cancel | [com.sinch.sample.sms.batches.Cancel](src/main/java/com/sinch/sample/sms/batches/Cancel.java) | Require `BATCH_ID` parameter | +| | | - SendDeliveryFeedback | [com.sinch.sample.sms.batches.SendDeliveryFeedback](src/main/java/com/sinch/sample/sms/batches/SendDeliveryFeedback.java) | Require `BATCH_ID` parameter | +| | DeliveryReport | - Get | [com.sinch.sample.sms.deliveryReports.Get](src/main/java/com/sinch/sample/sms/deliveryReports/Get.java) | Require `BATCH_ID` parameter | +| | | - GetForNumber | [com.sinch.sample.sms.deliveryReports.GetForNumber](src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java) | Require `BATCH_ID` and `PHONE_NUMBER` parameters | +| | | - List | [com.sinch.sample.sms.deliveryReports.List](src/main/java/com/sinch/sample/sms/deliveryReports/List.java) | | +| | Groups | - Create | [com.sinch.sample.sms.groups.Create](src/main/java/com/sinch/sample/sms/groups/Create.java) | | +| | | - Get | [com.sinch.sample.sms.groups.Get](src/main/java/com/sinch/sample/sms/groups/Get.java) | | +| | | - Delete | [com.sinch.sample.sms.groups.Delete](src/main/java/com/sinch/sample/sms/groups/Delete.java) | | +| | | - List | [com.sinch.sample.sms.groups.List](src/main/java/com/sinch/sample/sms/groups/List.java) | | +| | | - ListMembers | [com.sinch.sample.sms.groups.ListMembers](src/main/java/com/sinch/sample/sms/groups/ListMembers.java) | | +| | | - Replace | [com.sinch.sample.sms.groups.Replace](src/main/java/com/sinch/sample/sms/groups/Replace.java) | | +| | | - Update | [com.sinch.sample.sms.groups.Update](src/main/java/com/sinch/sample/sms/groups/Update.java) | | +| | Inbounds | - Get | [com.sinch.sample.sms.inbounds.Get](src/main/java/com/sinch/sample/sms/inbounds/Get.java) | | +| | | - List | [com.sinch.sample.sms.inbounds.List](src/main/java/com/sinch/sample/sms/inbounds/List.java) | | +| | WebHooks | - DeliveryReport | [com.sinch.sample.sms.webhooks.DeliveryReport](src/main/java/com/sinch/sample/sms/webhooks/DeliveryReport.java) | | +| | | - IncomingSMSReport | [com.sinch.sample.sms.webhooks.IncomingSMS](src/main/java/com/sinch/sample/sms/webhooks/IncomingSMS.java) | | diff --git a/sample-app/pom.xml b/sample-app/pom.xml index f7829518..c1aa0ce1 100644 --- a/sample-app/pom.xml +++ b/sample-app/pom.xml @@ -12,7 +12,14 @@ [0.0.0,) - + 1.8 + 1.8 + 1.8 + 1.8 + 8 + 3.8.0 + true + true diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Cancel.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Cancel.java new file mode 100644 index 00000000..52c11d72 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Cancel.java @@ -0,0 +1,29 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.BatchText; +import java.io.IOException; +import java.util.logging.Logger; + +public class Cancel extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Cancel.class.getName()); + + public Cancel() throws IOException {} + + public static void main(String[] args) { + try { + new Cancel().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Cancelling batch: " + batchId); + BatchText value = client.sms().batches().cancel(batchId); + + LOGGER.info("Response: " + value); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/List.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/List.java new file mode 100644 index 00000000..50a7452d --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/List.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters; +import java.io.IOException; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("List batches"); + + LOGGER.info("Response:"); + client + .sms() + .batches() + .list( + BatchesListRequestParameters.builder() + // .setFrom(phoneNumber) + // .setPage(15) + .setPageSize(2) + // .setClientReference("a client reference") + // .setStartDate(Instant.now()) + .build()) + .autoPageIter() + .forEachRemaining(f -> LOGGER.info(f.toString())); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Replace.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Replace.java new file mode 100644 index 00000000..cf3b295c --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Replace.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class Replace extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Replace.class.getName()); + + public Replace() throws IOException {} + + public static void main(String[] args) { + try { + new Replace().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Replace batch" + batchId); + BatchText value = + client + .sms() + .batches() + .replace( + batchId, + SendSmsBatchTextRequest.builder() + .setTo(Collections.singletonList("+33745149803")) + .setBody("the body") + .setClientReference("a client reference") + .setFrom("+33123456789") + .build()); + + LOGGER.info("Response: " + value); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java new file mode 100644 index 00000000..afa44d61 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java @@ -0,0 +1,41 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class Send extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Send.class.getName()); + + public Send() throws IOException {} + + public static void main(String[] args) { + try { + new Send().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Send Text"); + BatchText value = + client + .sms() + .batches() + .send( + SendSmsBatchTextRequest.builder() + .setTo(Collections.singletonList("+foo ")) + .setBody("the body") + .setClientReference("a client reference") + .setFrom("+33123456789") + .build()); + + LOGGER.info("Response: " + value); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/SendDeliveryFeedback.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/SendDeliveryFeedback.java new file mode 100644 index 00000000..21da1e46 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/SendDeliveryFeedback.java @@ -0,0 +1,32 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import java.io.IOException; +import java.util.Arrays; +import java.util.logging.Logger; + +public class SendDeliveryFeedback extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(SendDeliveryFeedback.class.getName()); + + public SendDeliveryFeedback() throws IOException {} + + public static void main(String[] args) { + try { + new SendDeliveryFeedback().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Send Delivery Feedback for batch ID:" + batchId); + client + .sms() + .batches() + .sendDeliveryFeedback(batchId, Arrays.asList("foo number 1", "foo number 2")); + LOGGER.info("Done"); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Update.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Update.java new file mode 100644 index 00000000..9f661161 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Update.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchTextRequest; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class Update extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Update.class.getName()); + + public Update() throws IOException {} + + public static void main(String[] args) { + try { + new Update().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Updating batch: " + batchId); + BatchText value = + client + .sms() + .batches() + .update( + batchId, + UpdateSmsBatchTextRequest.builder() + .setToRemove(Collections.singletonList("+33745149803")) + .setToAdd(Collections.singletonList("+33745149803")) + .setBody("the body updated") + .setFrom("+33123456789") + .build()); + + LOGGER.info("Response: " + value); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/dryRun.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/dryRun.java new file mode 100644 index 00000000..90a8065d --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/dryRun.java @@ -0,0 +1,43 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.DryRun; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class dryRun extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(dryRun.class.getName()); + + public dryRun() throws IOException {} + + public static void main(String[] args) { + try { + new dryRun().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("DryRun Request"); + + DryRun value = + client + .sms() + .batches() + .dryRun( + true, + 3, + SendSmsBatchTextRequest.builder() + .setTo(Collections.singletonList("+foo number")) + .setBody("the body") + .build()); + + LOGGER.info("Response :" + value); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/Get.java new file mode 100644 index 00000000..10cfb460 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/Get.java @@ -0,0 +1,30 @@ +package com.sinch.sample.sms.deliveryReports; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Get for :" + batchId); + + DeliveryReportBatch response = client.sms().deliveryReports().get(batchId, null); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java new file mode 100644 index 00000000..8a25f1c0 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java @@ -0,0 +1,31 @@ +package com.sinch.sample.sms.deliveryReports; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import java.io.IOException; +import java.util.logging.Logger; + +public class GetForNumber extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public GetForNumber() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Get for :" + phoneNumber); + + DeliveryReportRecipient response = + client.sms().deliveryReports().getForNumber(batchId, phoneNumber); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/List.java b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/List.java new file mode 100644 index 00000000..a72dd747 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/List.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.deliveryReports; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.DeliveryReportErrorCode; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; +import java.io.IOException; +import java.util.Arrays; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("List Delivery Reports"); + + LOGGER.info("Response:"); + client + .sms() + .deliveryReports() + .list( + DeliveryReportListRequestParameters.builder() + .setCodes( + Arrays.asList( + DeliveryReportErrorCode.from(0), DeliveryReportErrorCode.DISPATCHED)) + .build()) + .autoPageIter() + .forEachRemaining(f -> LOGGER.info(f.toString())); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/Create.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/Create.java new file mode 100644 index 00000000..16e252c0 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/Create.java @@ -0,0 +1,30 @@ +package com.sinch.sample.sms.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.Group; +import java.io.IOException; +import java.util.logging.Logger; + +public class Create extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Create.class.getName()); + + public Create() throws IOException {} + + public static void main(String[] args) { + try { + new Create().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Creating group"); + + Group response = client.sms().groups().create(); + + LOGGER.info("Response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/Delete.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/Delete.java new file mode 100644 index 00000000..e611f89d --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/Delete.java @@ -0,0 +1,32 @@ +package com.sinch.sample.sms.groups; + +import com.sinch.sample.BaseApplication; +import java.io.IOException; +import java.util.logging.Logger; + +public class Delete extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Delete.class.getName()); + + public Delete() throws IOException {} + + public static void main(String[] args) { + try { + new Delete().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String groupId = "01HF70ZG5VDZA9EP56HCHVB1R0"; + + LOGGER.info("Deleting group: " + groupId); + + client.sms().groups().delete(groupId); + + LOGGER.info("Done"); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/Get.java new file mode 100644 index 00000000..7379cd08 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/Get.java @@ -0,0 +1,31 @@ +package com.sinch.sample.sms.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.Group; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String groupId = "01HF714PHPH9SQ2BNWSCY2068R"; + LOGGER.info("Get for: " + groupId); + + Group response = client.sms().groups().get(groupId); + + LOGGER.info("Response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/List.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/List.java new file mode 100644 index 00000000..b6cf8a26 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/List.java @@ -0,0 +1,31 @@ +package com.sinch.sample.sms.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.responses.GroupsListResponse; +import java.io.IOException; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("List groups"); + + GroupsListResponse response = client.sms().groups().list(); + + response.autoPageIter().forEachRemaining(f -> LOGGER.info(f.toString())); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java new file mode 100644 index 00000000..33b00f2c --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java @@ -0,0 +1,33 @@ +package com.sinch.sample.sms.groups; + +import com.sinch.sample.BaseApplication; +import java.io.IOException; +import java.util.Collection; +import java.util.logging.Logger; + +public class ListMembers extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(ListMembers.class.getName()); + + public ListMembers() throws IOException {} + + public static void main(String[] args) { + try { + new ListMembers().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String groupId = "01HF714PHPH9SQ2BNWSCY2068R"; + + LOGGER.info("List members for groupId: " + groupId); + + Collection response = client.sms().groups().listMembers(groupId); + + response.iterator().forEachRemaining(LOGGER::info); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/Replace.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/Replace.java new file mode 100644 index 00000000..dcdc05ff --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/Replace.java @@ -0,0 +1,40 @@ +package com.sinch.sample.sms.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters; +import java.io.IOException; +import java.util.Arrays; +import java.util.logging.Logger; + +public class Replace extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Replace.class.getName()); + + public Replace() throws IOException {} + + public static void main(String[] args) { + try { + new Replace().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String groupId = "01HF70ZG5VDZA9EP56HCHVB1R0"; + GroupReplaceRequestParameters parameters = + GroupReplaceRequestParameters.builder() + .setName("foo") + .setMembers(Arrays.asList("+3312345678", "+3312345678")) + .build(); + + LOGGER.info("Replace group: " + groupId + " with: " + parameters); + + Group response = client.sms().groups().replace(groupId, parameters); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/Update.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/Update.java new file mode 100644 index 00000000..f1e356d9 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/Update.java @@ -0,0 +1,36 @@ +package com.sinch.sample.sms.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters; +import java.io.IOException; +import java.util.logging.Logger; + +public class Update extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Update.class.getName()); + + public Update() throws IOException {} + + public static void main(String[] args) { + try { + new Update().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String groupId = "01HF70ZG5VDZA9EP56HCHVB1R0"; + GroupUpdateRequestParameters parameters = + GroupUpdateRequestParameters.builder().setName("new name").build(); + + LOGGER.info("Update group: " + groupId + " with: " + parameters); + + Group response = client.sms().groups().update(groupId, parameters); + + LOGGER.info("Response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/inbounds/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/inbounds/Get.java new file mode 100644 index 00000000..a7366463 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/inbounds/Get.java @@ -0,0 +1,32 @@ +package com.sinch.sample.sms.inbounds; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.Inbound; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + private static final Logger LOGGER = + Logger.getLogger(com.sinch.sample.sms.deliveryReports.Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String inboundId = "foo id"; + LOGGER.info("Get for: " + inboundId); + + Inbound response = client.sms().inbounds().get(inboundId); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/inbounds/List.java b/sample-app/src/main/java/com/sinch/sample/sms/inbounds/List.java new file mode 100644 index 00000000..60ba5bb2 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/inbounds/List.java @@ -0,0 +1,34 @@ +package com.sinch.sample.sms.inbounds; + +import com.sinch.sample.BaseApplication; +import java.io.IOException; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("List inbounds"); + + LOGGER.info("Response:"); + client + .sms() + .inbounds() + .list(null) + .autoPageIter() + .forEachRemaining(f -> LOGGER.info(f.toString())); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/webhooks/DeliveryReport.java b/sample-app/src/main/java/com/sinch/sample/sms/webhooks/DeliveryReport.java new file mode 100644 index 00000000..b0b11415 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/webhooks/DeliveryReport.java @@ -0,0 +1,46 @@ +package com.sinch.sample.sms.webhooks; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.BaseDeliveryReport; +import java.io.IOException; +import java.util.logging.Logger; + +public class DeliveryReport extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(DeliveryReport.class.getName()); + + public DeliveryReport() throws IOException {} + + public static void main(String[] args) { + try { + new DeliveryReport().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String payload = + "{\n" + + " \"type\": \"delivery_report_sms\",\n" + + " \"batch_id\": \"01FC66621XXXXX119Z8PMV1QPQ\",\n" + + " \"statuses\": [\n" + + " {\n" + + " \"code\": 0,\n" + + " \"count\": 1,\n" + + " \"recipients\": [\n" + + " \"44231235674\"\n" + + " ],\n" + + " \"status\": \"Delivered\"\n" + + " }\n" + + " ],\n" + + " \"total_message_count\": 1\n" + + "}"; + LOGGER.info("Convert payload" + payload); + + BaseDeliveryReport value = client.sms().webHooks().deliveryReport(payload); + + LOGGER.info("Conversion result: " + value); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/webhooks/IncomingSMS.java b/sample-app/src/main/java/com/sinch/sample/sms/webhooks/IncomingSMS.java new file mode 100644 index 00000000..9da76d45 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/webhooks/IncomingSMS.java @@ -0,0 +1,59 @@ +package com.sinch.sample.sms.webhooks; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.Inbound; +import java.io.IOException; +import java.util.logging.Logger; + +public class IncomingSMS extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(IncomingSMS.class.getName()); + + public IncomingSMS() throws IOException {} + + public static void main(String[] args) { + try { + new IncomingSMS().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + String payload = + "{\n" + + " \"body\": \"This is a test message.\",\n" + + " \"from\": \"16051234567\",\n" + + " \"id\": \"01XXXXX21XXXXX119Z8P1XXXXX\",\n" + + " \"operator_id\": \"string\",\n" + + " \"received_at\": \"2022-08-24T14:15:22Z\",\n" + + " \"to\": \"13185551234\",\n" + + " \"type\": \"mo_text\"\n" + + "}"; + LOGGER.info("Convert MOText payload" + payload); + + Inbound value = client.sms().webHooks().incomingSMS(payload); + + LOGGER.info("Conversion result: " + value); + + payload = + "{\n" + + " \"body\": \"a body\",\n" + + " \"client_reference\": \"a client reference\",\n" + + " \"from\": \"+11203494390\",\n" + + " \"id\": \"01FC66621XXXXX119Z8PMV1QPA\",\n" + + " \"operator_id\": \"35000\",\n" + + " \"received_at\": \"2019-08-24T14:17:22Z\",\n" + + " \"sent_at\": \"2019-08-24T14:15:22Z\",\n" + + " \"to\": \"11203453453\",\n" + + " \"type\": \"mo_binary\",\n" + + " \"udh\": \"foo udh\"\n" + + "}"; + LOGGER.info("Convert MOBinary payload" + payload); + + value = client.sms().webHooks().incomingSMS(payload); + + LOGGER.info("Conversion result: " + value); + } +} diff --git a/sample-app/src/main/resources/logging.properties b/sample-app/src/main/resources/logging.properties index 50a9f671..2101070c 100644 --- a/sample-app/src/main/resources/logging.properties +++ b/sample-app/src/main/resources/logging.properties @@ -1,6 +1,6 @@ handlers = java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.level = FINEST -com.sinch.sdk.level = INFO +com.sinch.level = INFO java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s %2$s] %5$s %n diff --git a/test-resources/src/test/resources/domains/sms/v1/DeliveryReportBatchMMSDto.json b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportBatchMMSDto.json new file mode 100644 index 00000000..a1bf1338 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportBatchMMSDto.json @@ -0,0 +1,15 @@ +{ + "type": "delivery_report_mms", + "batch_id": "01FC66621XXXXX119Z8PMV1QPQ", + "statuses": [ + { + "code": 0, + "count": 1, + "recipients": [ + "44231235674" + ], + "status": "Delivered" + } + ], + "total_message_count": 1 +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/DeliveryReportBatchSMSDto.json b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportBatchSMSDto.json new file mode 100644 index 00000000..f35d84e4 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportBatchSMSDto.json @@ -0,0 +1,15 @@ +{ + "type": "delivery_report_sms", + "batch_id": "01FC66621XXXXX119Z8PMV1QPQ", + "statuses": [ + { + "code": 0, + "count": 1, + "recipients": [ + "44231235674" + ], + "status": "Delivered" + } + ], + "total_message_count": 1 +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/DeliveryReportRecipientMMSDto.json b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportRecipientMMSDto.json new file mode 100644 index 00000000..3c1fcaeb --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportRecipientMMSDto.json @@ -0,0 +1,14 @@ +{ + "type": "recipient_delivery_report_mms", + "batch_id": "01FC66621XXXXX119Z8PMV1QPQ", + "recipient": "+44231235674", + "code": 401, + "status": "Dispatched", + "at": "2022-08-30T08:16:08.930Z", + "operator": "operator", + "applied_originator": "applied originator", + "client_reference": "client reference", + "encoding": "encoding", + "number_of_message_parts": 123, + "operator_status_at": "2022-08-30T08:16:08.150Z" +} diff --git a/test-resources/src/test/resources/domains/sms/v1/DeliveryReportRecipientSMSDto.json b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportRecipientSMSDto.json new file mode 100644 index 00000000..0a36fcaa --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/DeliveryReportRecipientSMSDto.json @@ -0,0 +1,14 @@ +{ + "type": "recipient_delivery_report_sms", + "batch_id": "01FC66621XXXXX119Z8PMV1QPQ", + "recipient": "+44231235674", + "code": 401, + "status": "Dispatched", + "at": "2022-08-30T08:16:08.930Z", + "operator": "operator", + "applied_originator": "applied originator", + "client_reference": "client reference", + "encoding": "encoding", + "number_of_message_parts": 123, + "operator_status_at": "2022-08-30T08:16:08.150Z" +} diff --git a/test-resources/src/test/resources/domains/sms/v1/DryRunResponseDto.json b/test-resources/src/test/resources/domains/sms/v1/DryRunResponseDto.json new file mode 100644 index 00000000..10d9dbe1 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/DryRunResponseDto.json @@ -0,0 +1,12 @@ +{ + "number_of_recipients": 123, + "number_of_messages": 456, + "per_recipient": [ + { + "recipient": "recipient string", + "message_part": "message part string", + "body": "body string", + "encoding": "encoding string" + } + ] +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/GroupCreateRequestParametersDto.json b/test-resources/src/test/resources/domains/sms/v1/GroupCreateRequestParametersDto.json new file mode 100644 index 00000000..f94104b2 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/GroupCreateRequestParametersDto.json @@ -0,0 +1,18 @@ +{ + "name": "My new customers", + "members": ["foo"], + "child_groups": [ + "01FC66621XXXXX119Z8PMV1AHY", + "01FC66621XXXXX119Z8PMV1A00" + ], + "auto_update": { + "to": 15551231234, + "add": { + "first_word": "Add 1st keyword" + }, + "remove":{ + "first_word": "remove 1st keyword", + "second_word": "remove 2nd keyword" + } + } +} diff --git a/test-resources/src/test/resources/domains/sms/v1/GroupReplaceRequestParametersDto.json b/test-resources/src/test/resources/domains/sms/v1/GroupReplaceRequestParametersDto.json new file mode 100644 index 00000000..0b2c6322 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/GroupReplaceRequestParametersDto.json @@ -0,0 +1,4 @@ +{ + "name": "My new customers", + "members": ["foo"] +} diff --git a/test-resources/src/test/resources/domains/sms/v1/GroupResponseDto.json b/test-resources/src/test/resources/domains/sms/v1/GroupResponseDto.json new file mode 100644 index 00000000..ffa0a0ea --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/GroupResponseDto.json @@ -0,0 +1,21 @@ +{ + "id": "01FC66621XXXXX119Z8PMV1QPU", + "name": "My new customers", + "size": 2, + "created_at": "2019-08-24T14:15:22Z", + "modified_at": "2019-08-24T14:15:44Z", + "child_groups": [ + "01FC66621XXXXX119Z8PMV1AHY", + "01FC66621XXXXX119Z8PMV1A00" + ], + "auto_update": { + "to": 15551231234, + "add": { + "first_word": "Add 1st keyword" + }, + "remove":{ + "first_word": "remove 1st keyword", + "second_word": "remove 2nd keyword" + } + } +} diff --git a/test-resources/src/test/resources/domains/sms/v1/GroupUpdateRequestParametersDto.json b/test-resources/src/test/resources/domains/sms/v1/GroupUpdateRequestParametersDto.json new file mode 100644 index 00000000..de0b878b --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/GroupUpdateRequestParametersDto.json @@ -0,0 +1,22 @@ +{ + "name": "My new customers", + "add": [ + "foo" + ], + "remove": [ + "01FC66621XXXXX119Z8PMV1AHY", + "01FC66621XXXXX119Z8PMV1A00" + ], + "add_from_group": "add from group string", + "remove_from_group": "remove from group string", + "auto_update": { + "to": 15551231234, + "add": { + "first_word": "Add 1st keyword" + }, + "remove": { + "first_word": "remove 1st keyword", + "second_word": "remove 2nd keyword" + } + } +} diff --git a/test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage0.json b/test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage0.json new file mode 100644 index 00000000..a3944d6e --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage0.json @@ -0,0 +1,31 @@ +{ + "count": 3, + "page": 0, + "page_size": 2, + "groups": [ + { + "id": "01FC66621XXXXX119Z8PMV1QPU", + "name": "My new customers", + "size": 2, + "created_at": "2019-08-24T14:15:22Z", + "modified_at": "2019-08-24T14:15:44Z", + "child_groups": [ + "01FC66621XXXXX119Z8PMV1AHY", + "01FC66621XXXXX119Z8PMV1A00" + ], + "auto_update": { + "to": 15551231234, + "add": { + "first_word": "Add 1st keyword" + }, + "remove": { + "first_word": "remove 1st keyword", + "second_word": "remove 2nd keyword" + } + } + }, + { + "id": "foo id" + } + ] +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage1.json b/test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage1.json new file mode 100644 index 00000000..75247563 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage1.json @@ -0,0 +1,28 @@ +{ + "count": 3, + "page": 1, + "page_size": 2, + "groups": [ + { + "id": "01FC66621XXXXX119Z8PMV1QPU", + "name": "My new customers", + "size": 2, + "created_at": "2019-08-24T14:15:22Z", + "modified_at": "2019-08-24T14:15:44Z", + "child_groups": [ + "01FC66621XXXXX119Z8PMV1AHY", + "01FC66621XXXXX119Z8PMV1A00" + ], + "auto_update": { + "to": 15551231234, + "add": { + "first_word": "Add 1st keyword" + }, + "remove": { + "first_word": "remove 1st keyword", + "second_word": "remove 2nd keyword" + } + } + } + ] +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage0.json b/test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage0.json new file mode 100644 index 00000000..d62097fa --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage0.json @@ -0,0 +1,30 @@ +{ + "count": 3, + "page": 0, + "inbounds": [ + { + "body": "a body", + "client_reference": "a client reference", + "from": "+11203494390", + "id": "01FC66621XXXXX119Z8PMV1QPA", + "operator_id": "35000", + "received_at": "2019-08-24T14:17:22Z", + "sent_at": "2019-08-24T14:15:22Z", + "to": "11203453453", + "type": "mo_binary", + "udh": "foo udh" + }, + { + "body": "a body", + "client_reference": "a client reference", + "from": "+11203494390", + "id": "01FC66621XXXXX119Z8PMV1QPA", + "operator_id": "35000", + "received_at": "2019-08-24T14:17:22Z", + "sent_at": "2019-08-24T14:15:22Z", + "to": "11203453453", + "type": "mo_text" + } + ], + "page_size": 2 +} diff --git a/test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage1.json b/test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage1.json new file mode 100644 index 00000000..6dd9da1d --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage1.json @@ -0,0 +1,19 @@ +{ + "count": 3, + "page": 1, + "inbounds": [ + { + "body": "a body", + "client_reference": "a client reference", + "from": "+11203494390", + "id": "01FC66621XXXXX119Z8PMV1QPA", + "operator_id": "35000", + "received_at": "2019-08-24T14:17:22Z", + "sent_at": "2019-08-24T14:15:22Z", + "to": "11203453453", + "type": "mo_binary", + "udh": "foo udh" + } + ], + "page_size": 2 +} diff --git a/test-resources/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage0.json b/test-resources/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage0.json new file mode 100644 index 00000000..9f99361a --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage0.json @@ -0,0 +1,39 @@ +{ + "count": 3, + "page": 0, + "batches": [ + { + "id": "01HEAWCHESCXG8SDG5R10VF8E1", + "to": [ + "339876543213" + ], + "from": "33123456789", + "canceled": false, + "body": "the body", + "type": "mt_binary", + "created_at": "2023-11-03T15:21:21.113Z", + "modified_at": "2023-11-03T15:21:21.568Z", + "delivery_report": "none", + "expire_at": "2023-11-06T15:21:21.973Z", + "client_reference": "a client reference", + "feedback_enabled": false, + "flash_message": false + }, + { + "id": "01HEAC0AG69SVYYQ675VPYT28Q", + "to": [ + "3300000000" + ], + "canceled": false, + "body": "the body", + "type": "mt_text", + "created_at": "2023-11-03T10:35:03.558Z", + "modified_at": "2023-11-03T10:35:03.666Z", + "delivery_report": "none", + "expire_at": "2023-11-03T10:35:03.558Z", + "feedback_enabled": true, + "flash_message": false + } + ], + "page_size": 2 +} diff --git a/test-resources/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage1.json b/test-resources/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage1.json new file mode 100644 index 00000000..17259ab3 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage1.json @@ -0,0 +1,24 @@ +{ + "count": 3, + "page": 1, + "batches": [ + { + "id": "01HEABZ9S80D4ENE3X6CPMATZR", + "to": [ + "331111111" + ], + "canceled": false, + "body": { + "url": "an URL" + }, + "type": "mt_media", + "created_at": "2023-11-03T10:34:30.056Z", + "modified_at": "2023-11-03T10:34:30.156Z", + "delivery_report": "summary", + "expire_at": "2023-11-06T10:34:30.256Z", + "feedback_enabled": false + } + ], + "page_size": 2 +} + diff --git a/test-resources/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage0.json b/test-resources/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage0.json new file mode 100644 index 00000000..4e32f81e --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage0.json @@ -0,0 +1,35 @@ +{ + "count": 3, + "page": 0, + "delivery_reports": [ + { + "type": "recipient_delivery_report_sms", + "batch_id": "01FC66621XXXXX119Z8PMV1QPQ", + "recipient": "+44231235674", + "code": 401, + "status": "Dispatched", + "at": "2022-08-30T08:16:08.930Z", + "operator": "operator", + "applied_originator": "applied originator", + "client_reference": "client reference", + "encoding": "encoding", + "number_of_message_parts": 123, + "operator_status_at": "2022-08-30T08:16:08.150Z" + }, + { + "type": "recipient_delivery_report_mms", + "batch_id": "01FC66621XXXXX119Z8PMV1QPQ", + "recipient": "+44231235674", + "code": 401, + "status": "Dispatched", + "at": "2022-08-30T08:16:08.930Z", + "operator": "operator", + "applied_originator": "applied originator", + "client_reference": "client reference", + "encoding": "encoding", + "number_of_message_parts": 123, + "operator_status_at": "2022-08-30T08:16:08.150Z" + } + ], + "page_size": 2 +} diff --git a/test-resources/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage1.json b/test-resources/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage1.json new file mode 100644 index 00000000..162d7ff3 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage1.json @@ -0,0 +1,21 @@ +{ + "count": 3, + "page": 1, + "delivery_reports": [ + { + "type": "recipient_delivery_report_sms", + "batch_id": "01FC66621XXXXX119Z8PMV1QPQ", + "recipient": "+44231235674", + "code": 401, + "status": "Dispatched", + "at": "2022-08-30T08:16:08.930Z", + "operator": "operator", + "applied_originator": "applied originator", + "client_reference": "client reference", + "encoding": "encoding", + "number_of_message_parts": 123, + "operator_status_at": "2022-08-30T08:16:08.150Z" + } + ], + "page_size": 2 +} diff --git a/test-resources/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json index 61e8e29a..ea7e7801 100644 --- a/test-resources/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json +++ b/test-resources/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json @@ -9,13 +9,16 @@ "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" }, "parameters": { - "name": { - "12345678910": "Joe", - "default": "there" + "{parameter_key}": { + "{msisdn}": "msisdn value", + "default": "default value" + }, + "an identifier": { + "a key": "a value" } }, "type": "mt_media", - "delivery_report": "none", + "delivery_report": "summary", "send_at": "2019-08-24T14:16:22Z", "expire_at": "2019-08-24T14:17:22Z", "callback_url": "callback url", diff --git a/test-resources/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json index dfa4029a..9d7ff8a6 100644 --- a/test-resources/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json +++ b/test-resources/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json @@ -18,9 +18,12 @@ "from_ton": 6, "from_npi": 18, "parameters": { - "name": { - "12345678910": "Joe", - "default": "there" + "{parameter_key}": { + "{msisdn}": "msisdn value", + "default": "default value" + }, + "an identifier": { + "a key": "a value" } } } \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json new file mode 100644 index 00000000..2df9a741 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json @@ -0,0 +1,18 @@ +{ + "to_add": [ + "+15551231234", + "+15987365412" + ], + "to_remove": [ + "+0123456789", + "+9876543210" + ], + "from": "+15551231234", + "body": "Hi ${name}! How are you?", + "type": "mt_binary", + "delivery_report": "full", + "send_at": "2019-08-24T14:19:22Z", + "expire_at": "2019-08-24T14:21:22Z", + "callback_url": "callback url", + "udh": "foo udh" +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json new file mode 100644 index 00000000..a17cdf9f --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json @@ -0,0 +1,26 @@ +{ + "to_remove": [ + "+15551231234", + "+15551256344" + ], + "from": "+15551231234", + "body": { + "message": "Media message from Sinch!", + "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" + }, + "parameters": { + "{parameter_key}": { + "{msisdn}": "msisdn value", + "default": "default value" + }, + "an identifier": { + "a key": "a value" + } + }, + "type": "mt_media", + "delivery_report": "summary", + "send_at": "2019-08-24T14:16:22Z", + "expire_at": "2019-08-24T14:17:22Z", + "callback_url": "callback url", + "strict_validation": true +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json new file mode 100644 index 00000000..fe552725 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json @@ -0,0 +1,22 @@ +{ + "to_add": [ + "+15551231234", + "+15551256344" + ], + "from": "+15551231234", + "body": "Hi ${name}! How are you?", + "type": "mt_text", + "delivery_report": "none", + "send_at": "2019-08-24T14:19:22Z", + "expire_at": "2019-08-24T14:21:22Z", + "callback_url": "callback url", + "parameters": { + "{parameter_key}": { + "{msisdn}": "msisdn value", + "default": "default value" + }, + "an identifier": { + "a key": "a value" + } + } +} \ No newline at end of file