-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from sinch/DEVEXP-469-SMS-V1-design
DEVEXP- 469: SMS V1 design for batches
- Loading branch information
Showing
95 changed files
with
12,617 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sinch.sdk.domains.sms.api.v1; | ||
|
||
import com.sinch.sdk.core.exceptions.ApiException; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; | ||
|
||
public interface BatchesService { | ||
|
||
BatchResponse send(BatchRequest batch) throws ApiException; | ||
|
||
ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException; | ||
|
||
DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch); | ||
|
||
BatchResponse get(String batchId) throws ApiException; | ||
|
||
BatchResponse replace(String batchId, BatchRequest batch) throws ApiException; | ||
|
||
BatchResponse cancel(String batchId) throws ApiException; | ||
|
||
void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest recipients) | ||
throws ApiException; | ||
|
||
BatchResponse update(String batchId, UpdateBatchRequest request) throws ApiException; | ||
} |
6 changes: 6 additions & 0 deletions
6
client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sinch.sdk.domains.sms.api.v1; | ||
|
||
public interface SMSService { | ||
|
||
BatchesService batches(); | ||
} |
89 changes: 89 additions & 0 deletions
89
client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.sinch.sdk.domains.sms.api.v1.adapters; | ||
|
||
import com.sinch.sdk.core.exceptions.ApiException; | ||
import com.sinch.sdk.core.http.AuthManager; | ||
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.domains.sms.api.v1.internal.BatchesApi; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; | ||
import com.sinch.sdk.models.SmsContext; | ||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
public class BatchesService implements com.sinch.sdk.domains.sms.api.v1.BatchesService { | ||
|
||
private final BatchesApi api; | ||
|
||
public BatchesService( | ||
String uriUUID, | ||
SmsContext context, | ||
HttpClient httpClient, | ||
Map<String, AuthManager> authManagers) { | ||
this.api = | ||
new BatchesApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); | ||
} | ||
|
||
protected BatchesApi getApi() { | ||
return this.api; | ||
} | ||
|
||
public BatchResponse send(BatchRequest batch) throws ApiException { | ||
return getApi().send(batch); | ||
} | ||
|
||
public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException { | ||
|
||
ListBatchesRequest guardParameters = | ||
null != parameters ? parameters : ListBatchesRequest.builder().build(); | ||
|
||
ApiBatchList response = | ||
getApi() | ||
.list( | ||
guardParameters.getPage().orElse(null), | ||
guardParameters.getPageSize().orElse(null), | ||
guardParameters.getFrom().orElse(null), | ||
guardParameters.getStartDate().map(Instant::toString).orElse(null), | ||
guardParameters.getEndDate().map(Instant::toString).orElse(null), | ||
guardParameters.getClientReference().orElse(null)); | ||
|
||
SMSCursorPageNavigator navigator = | ||
new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); | ||
|
||
return new ListBatchesResponse( | ||
this, new Page<>(guardParameters, response.getBatches(), navigator)); | ||
} | ||
|
||
public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch) { | ||
return getApi().dryRun(perRecipient, numberOfRecipient, batch); | ||
} | ||
|
||
public BatchResponse get(String batchId) throws ApiException { | ||
return getApi().get(batchId); | ||
} | ||
|
||
public BatchResponse replace(String batchId, BatchRequest batch) throws ApiException { | ||
return getApi().replace(batchId, batch); | ||
} | ||
|
||
public BatchResponse cancel(String batchId) throws ApiException { | ||
return getApi().cancel(batchId); | ||
} | ||
|
||
public void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest request) | ||
throws ApiException { | ||
getApi().sendDeliveryFeedback(batchId, request); | ||
} | ||
|
||
public BatchResponse update(String batchId, UpdateBatchRequest request) throws ApiException { | ||
return getApi().update(batchId, request); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.sinch.sdk.domains.sms.api.v1.adapters; | ||
|
||
import com.sinch.sdk.auth.adapters.BearerAuthManager; | ||
import com.sinch.sdk.auth.adapters.OAuthManager; | ||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.core.http.HttpMapper; | ||
import com.sinch.sdk.core.models.ServerConfiguration; | ||
import com.sinch.sdk.core.utils.StringUtil; | ||
import com.sinch.sdk.models.SmsContext; | ||
import com.sinch.sdk.models.SmsServicePlanCredentials; | ||
import com.sinch.sdk.models.UnifiedCredentials; | ||
import java.util.AbstractMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class SMSService implements com.sinch.sdk.domains.sms.api.v1.SMSService { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(SMSService.class.getName()); | ||
|
||
private static final String SECURITY_SCHEME_KEYWORD_SMS = "BearerAuth"; | ||
private final String uriUUID; | ||
private final SmsContext context; | ||
private final HttpClient httpClient; | ||
private BatchesService batches; | ||
private final Map<String, AuthManager> authManagers; | ||
|
||
public SMSService( | ||
UnifiedCredentials credentials, | ||
SmsContext context, | ||
ServerConfiguration oAuthServer, | ||
HttpClient httpClient) { | ||
|
||
Objects.requireNonNull(credentials, "Credentials must be defined"); | ||
Objects.requireNonNull(context, "Context must be defined"); | ||
StringUtil.requireNonEmpty(credentials.getKeyId(), "'keyId' must be defined"); | ||
StringUtil.requireNonEmpty(credentials.getKeySecret(), "'keySecret' must be defined"); | ||
StringUtil.requireNonEmpty(credentials.getProjectId(), "'projectId' must be defined"); | ||
StringUtil.requireNonEmpty(context.getSmsUrl(), "'smsUrl' must be defined"); | ||
|
||
LOGGER.fine("Activate SMS API with server='" + context.getSmsServer().getUrl() + "'"); | ||
|
||
OAuthManager oAuthManager = | ||
new OAuthManager(credentials, oAuthServer, new HttpMapper(), httpClient); | ||
|
||
this.uriUUID = credentials.getProjectId(); | ||
this.context = context; | ||
this.httpClient = httpClient; | ||
this.authManagers = | ||
Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_SMS, oAuthManager)) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
public SMSService( | ||
SmsServicePlanCredentials credentials, SmsContext context, HttpClient httpClient) { | ||
|
||
Objects.requireNonNull(credentials, "Credentials must be defined"); | ||
Objects.requireNonNull(context, "Context must be defined"); | ||
StringUtil.requireNonEmpty(credentials.getServicePlanId(), "'servicePlanId' must be defined"); | ||
StringUtil.requireNonEmpty(credentials.getApiToken(), "'apiToken' must be defined"); | ||
StringUtil.requireNonEmpty(context.getSmsUrl(), "'smsUrl' must be defined"); | ||
|
||
LOGGER.fine( | ||
"Activate SMS API with service plan ID support and server='" | ||
+ context.getSmsServer().getUrl() | ||
+ "'"); | ||
|
||
BearerAuthManager authManager = new BearerAuthManager(credentials.getApiToken()); | ||
|
||
this.uriUUID = credentials.getServicePlanId(); | ||
this.context = context; | ||
this.httpClient = httpClient; | ||
this.authManagers = | ||
Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_SMS, authManager)) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
@Override | ||
public BatchesService batches() { | ||
if (null == this.batches) { | ||
this.batches = new BatchesService(uriUUID, context, httpClient, authManagers); | ||
} | ||
return this.batches; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.sinch.sdk.domains.sms.models.v1.batches.internal; | ||
|
||
import com.sinch.sdk.core.models.pagination.PageNavigator; | ||
|
||
public class SMSCursorPageNavigator extends PageNavigator<Integer> { | ||
|
||
private final Integer currentPage; | ||
private final Integer pageSize; | ||
|
||
public SMSCursorPageNavigator(Integer currentPage, Integer pageSize) { | ||
super(null); | ||
this.currentPage = currentPage; | ||
this.pageSize = pageSize; | ||
} | ||
|
||
private Integer computeNextPageCursor() { | ||
return null == pageSize || pageSize == 0 ? null : currentPage + 1; | ||
} | ||
|
||
@Override | ||
public Integer getToken() { | ||
return computeNextPageCursor(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SMSCursorPageNavigator{" | ||
+ "currentPage=" | ||
+ currentPage | ||
+ ", pageSize=" | ||
+ pageSize | ||
+ "} " | ||
+ super.toString(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.sinch.sdk.domains.sms.models.v1.batches.request; | ||
|
||
public interface BatchRequest {} |
Oops, something went wrong.