From e0027dda1fe6289f51146170b6d8ce08b6b2383e Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier <141755467+JPPortier@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:54:08 +0100 Subject: [PATCH] SMS: inbounds & groups feat: SMS Inbounds & Groups --- .../sinch/sdk/domains/sms/GroupsService.java | 122 +++++++ .../sdk/domains/sms/InboundsService.java | 47 +++ .../com/sinch/sdk/domains/sms/SMSService.java | 16 + .../sdk/domains/sms/WebHooksService.java | 4 +- .../domains/sms/adapters/BatchesService.java | 4 + .../sms/adapters/DeliveryReportsService.java | 4 + .../domains/sms/adapters/GroupsService.java | 109 +++++++ .../domains/sms/adapters/InboundsService.java | 67 ++++ .../sdk/domains/sms/adapters/SMSService.java | 20 ++ .../domains/sms/adapters/WebHooksService.java | 23 +- .../converters/GroupsDtoConverter.java | 196 +++++++++++ .../converters/InboundsDtoConverter.java | 74 +++++ .../sinch/sdk/domains/sms/models/Group.java | 151 +++++++++ .../domains/sms/models/GroupAutoUpdate.java | 71 ++++ .../sms/models/GroupAutoUpdateKeyword.java | 66 ++++ .../sinch/sdk/domains/sms/models/Inbound.java | 159 +++++++++ ...omingSMSBinary.java => InboundBinary.java} | 60 +++- .../IncomingSMSText.java => InboundText.java} | 53 ++- .../DeliveryReportListRequestParameters.java | 9 + .../GroupCreateRequestParameters.java | 117 +++++++ .../GroupReplaceRequestParameters.java | 75 +++++ .../GroupUpdateRequestParameters.java | 156 +++++++++ .../requests/GroupsListRequestParameters.java | 68 ++++ .../InboundsListRequestParameters.java | 135 ++++++++ .../models/responses/GroupsListResponse.java | 50 +++ .../responses/InboundsListResponse.java | 50 +++ .../sms/models/webhooks/BaseIncomingSMS.java | 98 ------ .../sms/models/webhooks/package-info.java | 6 - .../sms/adapters/GroupsServiceTest.java | 222 +++++++++++++ .../sms/adapters/InboundsServiceTest.java | 153 +++++++++ .../sms/adapters/WebHooksServiceTest.java | 27 +- .../converters/GroupsDtoConverterTest.java | 131 ++++++++ .../com/sinch/sdk/core/utils/DateUtil.java | 19 ++ .../sms/adapters/api/v1/GroupsApi.java | 9 +- .../sms/adapters/api/v1/InboundsApi.java | 11 +- .../sms/models/dto/v1/AddKeywordDto.java | 118 +++++++ .../models/dto/v1/ApiGroupAutoUpdateDto.java | 145 +++++++++ .../sms/models/dto/v1/ApiGroupDto.java | 166 +++++++++- ...0ResponseDto.java => ApiGroupListDto.java} | 136 ++++---- .../sms/models/dto/v1/ApiInboundListDto.java | 10 +- .../sms/models/dto/v1/GroupAutoUpdateDto.java | 16 +- ...tInboundsInnerDto.java => InboundDto.java} | 84 +++-- .../sms/models/dto/v1/MOBinaryDto.java | 38 +-- .../domains/sms/models/dto/v1/MOTextDto.java | 2 +- .../sms/models/dto/v1/RemoveKeywordDto.java | 118 +++++++ .../RetrieveInboundMessage200ResponseDto.java | 307 ------------------ .../models/dto/v1/GroupResponseDtoTest.java | 44 +++ ...sponseDtoTest.java => InboundDtoTest.java} | 12 +- .../sms/models/dto/v1/MOBinaryDtoTest.java | 4 +- .../sms/models/dto/v1/MOTextDtoTest.java | 4 +- .../v1/webhooks/IncomingSMSBinaryDtoTest.java | 34 -- .../v1/webhooks/IncomingSMSTextDtoTest.java | 33 -- sample-app/README.md | 56 ++-- .../com/sinch/sample/sms/groups/Create.java | 30 ++ .../com/sinch/sample/sms/groups/Delete.java | 32 ++ .../java/com/sinch/sample/sms/groups/Get.java | 31 ++ .../com/sinch/sample/sms/groups/List.java | 31 ++ .../sinch/sample/sms/groups/ListMembers.java | 33 ++ .../com/sinch/sample/sms/groups/Replace.java | 40 +++ .../com/sinch/sample/sms/groups/Update.java | 36 ++ .../com/sinch/sample/sms/inbounds/Get.java | 32 ++ .../com/sinch/sample/sms/inbounds/List.java | 34 ++ .../sample/sms/webhooks/IncomingSMS.java | 25 +- .../v1/GroupCreateRequestParametersDto.json | 18 + .../v1/GroupReplaceRequestParametersDto.json | 4 + .../domains/sms/v1/GroupResponseDto.json | 21 ++ .../v1/GroupUpdateRequestParametersDto.json | 22 ++ .../sms/v1/GroupsListResponseDtoPage0.json | 31 ++ .../sms/v1/GroupsListResponseDtoPage1.json | 28 ++ .../sms/v1/InboundsListResponseDtoPage0.json | 30 ++ .../sms/v1/InboundsListResponseDtoPage1.json | 19 ++ .../sms/v1/webhooks/IncomingSMSBinary.json | 11 - .../sms/v1/webhooks/IncomingSMSText.json | 9 - 73 files changed, 3675 insertions(+), 751 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/GroupsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/InboundsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverter.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/adapters/converters/InboundsDtoConverter.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/Group.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdate.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/GroupAutoUpdateKeyword.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/Inbound.java rename client/src/main/com/sinch/sdk/domains/sms/models/{webhooks/IncomingSMSBinary.java => InboundBinary.java} (59%) rename client/src/main/com/sinch/sdk/domains/sms/models/{webhooks/IncomingSMSText.java => InboundText.java} (55%) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupCreateRequestParameters.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupReplaceRequestParameters.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupUpdateRequestParameters.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/GroupsListRequestParameters.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/InboundsListRequestParameters.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/responses/GroupsListResponse.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/responses/InboundsListResponse.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/webhooks/BaseIncomingSMS.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/webhooks/package-info.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java create mode 100644 core/src/main/com/sinch/sdk/core/utils/DateUtil.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/AddKeywordDto.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/ApiGroupAutoUpdateDto.java rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/{ListGroups200ResponseDto.java => ApiGroupListDto.java} (71%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/{ApiInboundListInboundsInnerDto.java => InboundDto.java} (77%) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RemoveKeywordDto.java delete mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessage200ResponseDto.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java rename openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/{RetrieveInboundMessageResponseDtoTest.java => InboundDtoTest.java} (79%) delete mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/webhooks/IncomingSMSBinaryDtoTest.java delete mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/webhooks/IncomingSMSTextDtoTest.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/groups/Create.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/groups/Delete.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/groups/Get.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/groups/List.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/groups/Replace.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/groups/Update.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/inbounds/Get.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/inbounds/List.java create mode 100644 test-resources/src/test/resources/domains/sms/v1/GroupCreateRequestParametersDto.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/GroupReplaceRequestParametersDto.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/GroupResponseDto.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/GroupUpdateRequestParametersDto.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage0.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage1.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage0.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage1.json delete mode 100644 test-resources/src/test/resources/domains/sms/v1/webhooks/IncomingSMSBinary.json delete mode 100644 test-resources/src/test/resources/domains/sms/v1/webhooks/IncomingSMSText.json 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 2ed9e20d..1d0da811 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/SMSService.java @@ -32,4 +32,20 @@ public interface SMSService { * @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 index 67ef865a..185ada01 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/WebHooksService.java @@ -2,7 +2,7 @@ import com.sinch.sdk.core.exceptions.ApiMappingException; import com.sinch.sdk.domains.sms.models.BaseDeliveryReport; -import com.sinch.sdk.domains.sms.models.webhooks.BaseIncomingSMS; +import com.sinch.sdk.domains.sms.models.Inbound; /** * WebHooks @@ -53,7 +53,7 @@ public interface WebHooksService { * href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/#tag/Webhooks/operation/incomingSMS">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/#tag/Webhooks/operation/incomingSMS * @since 1.0 */ - BaseIncomingSMS incomingSMS(String jsonPayload) throws ApiMappingException; + Inbound incomingSMS(String jsonPayload) throws ApiMappingException; /** * Delivery Report WebHook 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 c39dbf2a..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 @@ -56,6 +56,10 @@ public DryRun dryRun(boolean perRecipient, int numberOfRecipient, BaseBatch b BatchDtoConverter.convert(batch))); } + public BatchesListResponse list() throws ApiException { + return this.list(null); + } + public BatchesListResponse list(BatchesListRequestParameters parameters) throws ApiException { BatchesListRequestParameters guardParameters = 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 index 13b0e62b..833be282 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java @@ -77,6 +77,10 @@ public DeliveryReportRecipient getForNumber(String batchId, String recipient) getApi().getDeliveryReportByPhoneNumber(configuration.getProjectId(), batchId, recipient)); } + public DeliveryReportsListResponse list() throws ApiException { + return this.list(null); + } + public DeliveryReportsListResponse list(DeliveryReportListRequestParameters parameters) throws ApiException { DeliveryReportListRequestParameters guardParameters = 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 08b76a3d..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 @@ -3,6 +3,7 @@ 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; @@ -13,6 +14,8 @@ public class SMSService implements com.sinch.sdk.domains.sms.SMSService { private BatchesService batches; private WebHooksService webHooks; private DeliveryReportsService deliveryReports; + private InboundsService inbounds; + private GroupsService groups; public SMSService(Configuration configuration, HttpClient httpClient) { this.configuration = configuration; @@ -44,4 +47,21 @@ public DeliveryReportsService deliveryReports() { } 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 index 7fc32510..7cd2c35e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/WebHooksService.java @@ -2,27 +2,34 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.sinch.sdk.core.exceptions.ApiMappingException; -import com.sinch.sdk.core.utils.StringUtil; 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 com.sinch.sdk.domains.sms.models.webhooks.BaseIncomingSMS; import java.util.Objects; public class WebHooksService implements com.sinch.sdk.domains.sms.WebHooksService { @Override - public BaseIncomingSMS incomingSMS(String jsonPayload) throws ApiMappingException { + public Inbound incomingSMS(String jsonPayload) throws ApiMappingException { try { - BaseIncomingSMS generic = - Mapper.getInstance().readValue(jsonPayload, BaseIncomingSMS.class); - if (null == generic && !StringUtil.isEmpty(jsonPayload)) { - throw new ApiMappingException(jsonPayload, null); + MOBinaryDto binary = Mapper.getInstance().readValue(jsonPayload, MOBinaryDto.class); + if (null != binary + && (Objects.equals(binary.getType(), MOBinaryDto.TypeEnum.MO_BINARY.getValue()))) { + return InboundsDtoConverter.convert(binary); } - return generic; + 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); } 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/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/webhooks/IncomingSMSBinary.java b/client/src/main/com/sinch/sdk/domains/sms/models/InboundBinary.java similarity index 59% rename from client/src/main/com/sinch/sdk/domains/sms/models/webhooks/IncomingSMSBinary.java rename to client/src/main/com/sinch/sdk/domains/sms/models/InboundBinary.java index 764647eb..70081c01 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/webhooks/IncomingSMSBinary.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/InboundBinary.java @@ -1,17 +1,14 @@ -package com.sinch.sdk.domains.sms.models.webhooks; +package com.sinch.sdk.domains.sms.models; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.time.OffsetDateTime; +import java.time.Instant; /** * Incoming SMS Binary * * @since 1.0 */ -public class IncomingSMSBinary extends BaseIncomingSMS { +public class InboundBinary extends Inbound { - static final String JSON_PROPERTY_UDH = "udh"; private final String udh; /** @@ -32,17 +29,16 @@ public class IncomingSMSBinary extends BaseIncomingSMS { * operator. * @param udh The UDH header of a binary message HEX encoded. Max 140 bytes together with body. */ - @JsonCreator - public IncomingSMSBinary( - @JsonProperty(JSON_PROPERTY_BODY) String body, - @JsonProperty(JSON_PROPERTY_FROM) String from, - @JsonProperty(JSON_PROPERTY_ID) String id, - @JsonProperty(JSON_PROPERTY_RECEIVED_AT) OffsetDateTime receivedAt, - @JsonProperty(JSON_PROPERTY_TO) String to, - @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) String clientReference, - @JsonProperty(JSON_PROPERTY_OPERATOR_ID) String operatorId, - @JsonProperty(JSON_PROPERTY_SENT_AT) OffsetDateTime sendAt, - @JsonProperty(JSON_PROPERTY_UDH) String udh) { + 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; } @@ -53,6 +49,34 @@ public String getUdh() { @Override public String toString() { - return "IncomingSMSBinary{" + "udh='" + udh + '\'' + "} " + super.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/webhooks/IncomingSMSText.java b/client/src/main/com/sinch/sdk/domains/sms/models/InboundText.java similarity index 55% rename from client/src/main/com/sinch/sdk/domains/sms/models/webhooks/IncomingSMSText.java rename to client/src/main/com/sinch/sdk/domains/sms/models/InboundText.java index b560119e..9d68027f 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/webhooks/IncomingSMSText.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/InboundText.java @@ -1,15 +1,13 @@ -package com.sinch.sdk.domains.sms.models.webhooks; +package com.sinch.sdk.domains.sms.models; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.time.OffsetDateTime; +import java.time.Instant; /** * Incoming SMS Text * * @since 1.0 */ -public class IncomingSMSText extends BaseIncomingSMS { +public class InboundText extends Inbound { /** * Text MO class @@ -25,24 +23,43 @@ public class IncomingSMSText extends BaseIncomingSMS { * 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 + * @param sentAt When the message left the originating device. Only available if provided by * operator. */ - @JsonCreator - public IncomingSMSText( - @JsonProperty(JSON_PROPERTY_BODY) String body, - @JsonProperty(JSON_PROPERTY_FROM) String from, - @JsonProperty(JSON_PROPERTY_ID) String id, - @JsonProperty(JSON_PROPERTY_RECEIVED_AT) OffsetDateTime receivedAt, - @JsonProperty(JSON_PROPERTY_TO) String to, - @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) String clientReference, - @JsonProperty(JSON_PROPERTY_OPERATOR_ID) String operatorId, - @JsonProperty(JSON_PROPERTY_SENT_AT) OffsetDateTime sendAt) { - super(body, from, id, receivedAt, to, clientReference, operatorId, sendAt); + 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 "IncomingSMSText{} " + super.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/requests/DeliveryReportListRequestParameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParameters.java index ae104360..566b4667 100644 --- 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 @@ -23,6 +23,15 @@ public class DeliveryReportListRequestParameters { 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, 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/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/webhooks/BaseIncomingSMS.java b/client/src/main/com/sinch/sdk/domains/sms/models/webhooks/BaseIncomingSMS.java deleted file mode 100644 index 608e7073..00000000 --- a/client/src/main/com/sinch/sdk/domains/sms/models/webhooks/BaseIncomingSMS.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.sinch.sdk.domains.sms.models.webhooks; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.util.Optional; - -/** - * Base class for Incoming SMS Webhook - * - * @param Type of SMS body - * @since 1.0 - */ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "type", - visible = true) -@JsonSubTypes({ - @JsonSubTypes.Type(value = IncomingSMSBinary.class, name = "mo_binary"), - @JsonSubTypes.Type(value = IncomingSMSText.class, name = "mo_text") -}) -public abstract class BaseIncomingSMS { - - static final String JSON_PROPERTY_BODY = "body"; - private final T body; - static final String JSON_PROPERTY_FROM = "from"; - private final String from; - static final String JSON_PROPERTY_ID = "id"; - private final String id; - static final String JSON_PROPERTY_RECEIVED_AT = "received_at"; - private final Instant receivedAt; - static final String JSON_PROPERTY_TO = "to"; - private final String to; - static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; - private final String clientReference; - static final String JSON_PROPERTY_OPERATOR_ID = "operator_id"; - private final String operatorId; - static final String JSON_PROPERTY_SENT_AT = "sent_at"; - private final Instant sentAt; - - @JsonCreator - public BaseIncomingSMS( - @JsonProperty(JSON_PROPERTY_BODY) T body, - @JsonProperty(JSON_PROPERTY_FROM) String from, - @JsonProperty(JSON_PROPERTY_ID) String id, - @JsonProperty(JSON_PROPERTY_RECEIVED_AT) OffsetDateTime receivedAt, - @JsonProperty(JSON_PROPERTY_TO) String to, - @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) String clientReference, - @JsonProperty(JSON_PROPERTY_OPERATOR_ID) String operatorId, - @JsonProperty(JSON_PROPERTY_SENT_AT) OffsetDateTime sentAt) { - this.body = body; - this.from = from; - this.id = id; - this.receivedAt = receivedAt.toInstant(); - this.to = to; - this.clientReference = clientReference; - this.operatorId = operatorId; - this.sentAt = null != sentAt ? sentAt.toInstant() : null; - } - - 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); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/webhooks/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/webhooks/package-info.java deleted file mode 100644 index daf15120..00000000 --- a/client/src/main/com/sinch/sdk/domains/sms/models/webhooks/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * SMS WebHooks models - * - * @since 1.0 - */ -package com.sinch.sdk.domains.sms.models.webhooks; 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 index 7053fda9..286a1269 100644 --- 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 @@ -9,18 +9,19 @@ 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.webhooks.IncomingSMSBinaryDtoTest; -import com.sinch.sdk.domains.sms.models.dto.v1.webhooks.IncomingSMSTextDtoTest; -import com.sinch.sdk.domains.sms.models.webhooks.BaseIncomingSMS; -import com.sinch.sdk.domains.sms.models.webhooks.IncomingSMSBinary; -import com.sinch.sdk.domains.sms.models.webhooks.IncomingSMSText; +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; @@ -28,10 +29,10 @@ @TestWithResources public class WebHooksServiceTest extends BaseTest { - @GivenTextResource("/domains/sms/v1/webhooks/IncomingSMSBinary.json") + @GivenTextResource("/domains/sms/v1/MOBinaryDto.json") String incomingSMSBinaryJsonString; - @GivenTextResource("/domains/sms/v1/webhooks/IncomingSMSText.json") + @GivenTextResource("/domains/sms/v1/MOTextDto.json") String incomingSMSTextJsonString; @GivenTextResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") @@ -51,23 +52,23 @@ public class WebHooksServiceTest extends BaseTest { @Test void incomingSMSBinary() throws ApiException { - BaseIncomingSMS response = service.incomingSMS(incomingSMSBinaryJsonString); + Inbound response = service.incomingSMS(incomingSMSBinaryJsonString); - Assertions.assertThat(response).isInstanceOf(IncomingSMSBinary.class); + Assertions.assertThat(response).isInstanceOf(InboundBinary.class); Assertions.assertThat(response) .usingRecursiveComparison() - .isEqualTo(IncomingSMSBinaryDtoTest.incomingSMSBinary); + .isEqualTo(InboundsDtoConverter.convert(MOBinaryDtoTest.dto)); } @Test void incomingSMSText() throws ApiException { - BaseIncomingSMS response = service.incomingSMS(incomingSMSTextJsonString); + Inbound response = service.incomingSMS(incomingSMSTextJsonString); - Assertions.assertThat(response).isInstanceOf(IncomingSMSText.class); + Assertions.assertThat(response).isInstanceOf(InboundText.class); Assertions.assertThat(response) .usingRecursiveComparison() - .isEqualTo(IncomingSMSTextDtoTest.incomingSMSText); + .isEqualTo(InboundsDtoConverter.convert(MOTextDtoTest.dto)); } @Test 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/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/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 6b47edeb..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; @@ -279,10 +279,10 @@ 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( @@ -300,8 +300,7 @@ public ListGroups200ResponseDto listGroups(String servicePlanId, Integer page, I 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: 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 e04bc496..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; @@ -210,11 +210,11 @@ 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] " @@ -228,8 +228,7 @@ public RetrieveInboundMessage200ResponseDto retrieveInboundMessage( 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: 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/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/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/RetrieveInboundMessageResponseDtoTest.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/RetrieveInboundMessageResponseDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java index 3aa6007e..8e36a4b9 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/RetrieveInboundMessageResponseDtoTest.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 RetrieveInboundMessageResponseDtoTest 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 RetrieveInboundMessageResponseDtoTest 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/webhooks/IncomingSMSBinaryDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/webhooks/IncomingSMSBinaryDtoTest.java deleted file mode 100644 index c4427793..00000000 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/webhooks/IncomingSMSBinaryDtoTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.sinch.sdk.domains.sms.models.dto.v1.webhooks; - -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.webhooks.IncomingSMSBinary; -import java.time.OffsetDateTime; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -@TestWithResources -public class IncomingSMSBinaryDtoTest extends BaseTest { - - @GivenJsonResource("/domains/sms/v1/webhooks/IncomingSMSBinary.json") - IncomingSMSBinary client; - - public static IncomingSMSBinary incomingSMSBinary = - new IncomingSMSBinary( - "VGV4dCBtZXNzYWdl", - "16051234567", - "01XXXXX21XXXXX119Z8P1XXXXX", - OffsetDateTime.parse("2022-08-24T14:15:22Z"), - "13185551234", - null, - "operator", - OffsetDateTime.parse("2022-08-24T14:15:44Z"), - "10010203040506070809000a0b0c0d0e0f"); - - @Test - void deserialize() { - - Assertions.assertThat(incomingSMSBinary).usingRecursiveComparison().isEqualTo(client); - } -} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/webhooks/IncomingSMSTextDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/webhooks/IncomingSMSTextDtoTest.java deleted file mode 100644 index c049199b..00000000 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/webhooks/IncomingSMSTextDtoTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.sinch.sdk.domains.sms.models.dto.v1.webhooks; - -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.webhooks.IncomingSMSText; -import java.time.OffsetDateTime; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -@TestWithResources -public class IncomingSMSTextDtoTest extends BaseTest { - - @GivenJsonResource("/domains/sms/v1/webhooks/IncomingSMSText.json") - IncomingSMSText client; - - public static IncomingSMSText incomingSMSText = - new IncomingSMSText( - "This is a test message.", - "16051234567", - "01XXXXX21XXXXX119Z8P1XXXXX", - OffsetDateTime.parse("2022-08-24T14:15:22Z"), - "13185551234", - null, - "string", - null); - - @Test - void deserialize() { - - Assertions.assertThat(incomingSMSText).usingRecursiveComparison().isEqualTo(client); - } -} diff --git a/sample-app/README.md b/sample-app/README.md index 2397f916..c4d5bb0e 100644 --- a/sample-app/README.md +++ b/sample-app/README.md @@ -49,24 +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 | -| | | - 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 | +| 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/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/IncomingSMS.java b/sample-app/src/main/java/com/sinch/sample/sms/webhooks/IncomingSMS.java index 1889bd59..9da76d45 100644 --- 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 @@ -1,7 +1,7 @@ package com.sinch.sample.sms.webhooks; import com.sinch.sample.BaseApplication; -import com.sinch.sdk.domains.sms.models.webhooks.BaseIncomingSMS; +import com.sinch.sdk.domains.sms.models.Inbound; import java.io.IOException; import java.util.logging.Logger; @@ -31,9 +31,28 @@ public void run() { + " \"to\": \"13185551234\",\n" + " \"type\": \"mo_text\"\n" + "}"; - LOGGER.info("Convert payload" + payload); + LOGGER.info("Convert MOText payload" + payload); - BaseIncomingSMS value = client.sms().webHooks().incomingSMS(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/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/webhooks/IncomingSMSBinary.json b/test-resources/src/test/resources/domains/sms/v1/webhooks/IncomingSMSBinary.json deleted file mode 100644 index 2c698b57..00000000 --- a/test-resources/src/test/resources/domains/sms/v1/webhooks/IncomingSMSBinary.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "body": "VGV4dCBtZXNzYWdl", - "from": "16051234567", - "id": "01XXXXX21XXXXX119Z8P1XXXXX", - "operator_id": "operator", - "received_at": "2022-08-24T14:15:22Z", - "sent_at": "2022-08-24T14:15:44Z", - "to": "13185551234", - "type": "mo_binary", - "udh": "10010203040506070809000a0b0c0d0e0f" -} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/webhooks/IncomingSMSText.json b/test-resources/src/test/resources/domains/sms/v1/webhooks/IncomingSMSText.json deleted file mode 100644 index a97b50f0..00000000 --- a/test-resources/src/test/resources/domains/sms/v1/webhooks/IncomingSMSText.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "body": "This is a test message.", - "from": "16051234567", - "id": "01XXXXX21XXXXX119Z8P1XXXXX", - "operator_id": "string", - "received_at": "2022-08-24T14:15:22Z", - "to": "13185551234", - "type": "mo_text" -} \ No newline at end of file