Skip to content

Commit

Permalink
SMS: inbounds & groups
Browse files Browse the repository at this point in the history
feat: SMS Inbounds & Groups
  • Loading branch information
JPPortier committed Nov 16, 2023
1 parent 7c7b012 commit e0027dd
Show file tree
Hide file tree
Showing 73 changed files with 3,675 additions and 751 deletions.
122 changes: 122 additions & 0 deletions client/src/main/com/sinch/sdk/domains/sms/GroupsService.java
Original file line number Diff line number Diff line change
@@ -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
*
* <p>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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups</a>
* @since 1.0
*/
public interface GroupsService {

/**
* Retrieve a group
*
* <p>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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/RetrieveGroup">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/RetrieveGroup</a>
* @since 1.0
*/
Group get(String groupId) throws ApiException;

/**
* Create a group
*
* <p>A group is a set of phone numbers (MSISDNs) that can be used as a target in the <code>
* send_batch_msg</code> 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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/CreateGroup">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/CreateGroup</a>
* @since 1.0
*/
Group create(GroupCreateRequestParameters parameters) throws ApiException;

Group create() throws ApiException;

/**
* List Groups
*
* <p>With the list operation you can list all groups that you have created. This operation
* supports pagination.
*
* <p>Groups are returned in reverse chronological order.
*
* @param parameters Filtering parameters
* @return group list
* @see <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ListGroups">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ListGroups</a>
* @since 1.0
*/
GroupsListResponse list(GroupsListRequestParameters parameters) throws ApiException;

GroupsListResponse list() throws ApiException;

/**
* Replace a group
*
* <p>The replace operation will replace all parameters, including members, of an existing group
* with new values.
*
* <p>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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ReplaceGroup">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ReplaceGroup</a>
* @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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/UpdateGroup">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/UpdateGroup</a>
* @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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup</a>
* @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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup</a>
* @since 1.0
*/
Collection<String> listMembers(String groupId) throws ApiException;
}
47 changes: 47 additions & 0 deletions client/src/main/com/sinch/sdk/domains/sms/InboundsService.java
Original file line number Diff line number Diff line change
@@ -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
*
* <p>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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Inbounds/">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Inbounds/</a>
* @since 1.0
*/
public interface InboundsService {

/**
* List incoming messages
*
* <p>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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/getDeliveryReports">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/getDeliveryReports</a>
* @since 1.0
*/
InboundsListResponse list(InboundsListRequestParameters parameters) throws ApiException;

/**
* Retrieve inbound message
*
* <p>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 <a
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Inbounds/#tag/Inbounds/operation/RetrieveInboundMessage">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Inbounds/#tag/Inbounds/operation/RetrieveInboundMessage</a>
* @since 1.0
*/
Inbound<?> get(String inboundId) throws ApiException;
}
16 changes: 16 additions & 0 deletions client/src/main/com/sinch/sdk/domains/sms/SMSService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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</a>
* @since 1.0
*/
BaseIncomingSMS<?> incomingSMS(String jsonPayload) throws ApiMappingException;
Inbound<?> incomingSMS(String jsonPayload) throws ApiMappingException;

/**
* Delivery Report WebHook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
109 changes: 109 additions & 0 deletions client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java
Original file line number Diff line number Diff line change
@@ -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<Collection<Group>, PageToken<Integer>> 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<String> listMembers(String groupId) throws ApiException {
return getApi().getMembers(configuration.getProjectId(), groupId);
}
}
Loading

0 comments on commit e0027dd

Please sign in to comment.