Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-165 sms groups #9

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
JPPortier marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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;
JPPortier marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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;
JPPortier marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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;
}
8 changes: 8 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 @@ -40,4 +40,12 @@ public interface SMSService {
* @since 1.0
*/
InboundsService inbounds();

/**
* Groups Service instance
*
* @return service instance for project
* @since 1.0
*/
GroupsService groups();
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class SMSService implements com.sinch.sdk.domains.sms.SMSService {
private WebHooksService webHooks;
private DeliveryReportsService deliveryReports;
private InboundsService inbounds;
private GroupsService groups;

public SMSService(Configuration configuration, HttpClient httpClient) {
this.configuration = configuration;
Expand Down Expand Up @@ -55,4 +56,12 @@ public InboundsService inbounds() {
}
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;
}
}
Loading
Loading