-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sms delivery reports #6
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
27a25dd
feat: SMS Delivery Reports (Get)
JPPortier 7d2bcb0
refactor: rename 'DeliveryReport' to 'DeliveryReportType'
JPPortier a31395c
refactor: renamed and moved webhooks.DeliveryReport* to DeliveryRepor…
JPPortier f545a5b
feature: Share and consume generated DTO classes for DeliveryReport i…
JPPortier 0d97a50
feature: Support 'Retrieve a recipient delivery report': getForNumber
JPPortier 01ea3cf
feature: Use DeliveryReportBatchGetRequestParameters for filtering 'g…
JPPortier 203f305
test: Set sample project compilation settings
JPPortier 89d0cf7
feature: SMS Delivery Report (List)
JPPortier a10e5f7
refactor: Define Delivery report error codes as enums and extend enum…
JPPortier 855034c
test: use enum in place of Integer
JPPortier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
68 changes: 68 additions & 0 deletions
68
client/src/main/com/sinch/sdk/domains/sms/DeliveryReportsService.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,68 @@ | ||
package com.sinch.sdk.domains.sms; | ||
|
||
import com.sinch.sdk.core.exceptions.ApiException; | ||
import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; | ||
import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; | ||
import com.sinch.sdk.domains.sms.models.requests.DeliveryReportBatchGetRequestParameters; | ||
import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; | ||
import com.sinch.sdk.domains.sms.models.responses.DeliveryReportsListResponse; | ||
|
||
/** | ||
* Delivery reports Service | ||
* | ||
* <p>The REST API uses message statuses and error codes in delivery reports, which refer to the | ||
* state of the batch and can be present in either <a | ||
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByBatchId">Retrieve | ||
* a delivery report</a> or sent as a callback. | ||
* | ||
* @see <a | ||
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports</a> | ||
* @since 1.0 | ||
*/ | ||
public interface DeliveryReportsService { | ||
|
||
/** | ||
* Retrieve a batch delivery report <br> | ||
* Delivery reports can be retrieved even if no callback was requested. The difference between a | ||
* summary and a full report is only that the full report contains the phone numbers in <a | ||
* href="https://community.sinch.com/t5/Glossary/E-164/ta-p/7537">E.164</a> format for each status | ||
* code. | ||
* | ||
* @param batchId The batch ID you received from sending a message param type param status param | ||
* code | ||
* @param parameters Filtering parameters | ||
* @return Delivery report related to batchId according to filters | ||
* @see <a | ||
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByBatchId">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByBatchId</a> | ||
* @since 1.0 | ||
*/ | ||
DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestParameters parameters) | ||
throws ApiException; | ||
|
||
/** | ||
* Retrieve a recipient delivery report <br> | ||
* A recipient delivery report contains the message status for a single recipient phone number. | ||
* | ||
* @param batchId The batch ID you received from sending a message param type param status param | ||
* code | ||
* @param recipient Phone number for which you to want to search | ||
* @return Delivery report related to batchId according to filters | ||
* @see <a | ||
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByPhoneNumber">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByPhoneNumber</a> | ||
* @since 1.0 | ||
*/ | ||
DeliveryReportRecipient getForNumber(String batchId, String recipient) throws ApiException; | ||
|
||
/** | ||
* Get a list of finished delivery reports.<br> | ||
* This operation supports pagination. | ||
* | ||
* @param parameters Filtering parameters | ||
* @return Delivery report related to batchId according to filters | ||
* @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 | ||
*/ | ||
DeliveryReportsListResponse list(DeliveryReportListRequestParameters parameters) | ||
throws ApiException; | ||
} |
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
109 changes: 109 additions & 0 deletions
109
client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.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,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.EnumDynamic; | ||
import com.sinch.sdk.core.utils.Pair; | ||
import com.sinch.sdk.domains.sms.adapters.api.v1.DeliveryReportsApi; | ||
import com.sinch.sdk.domains.sms.adapters.converters.DeliveryReportDtoConverter; | ||
import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; | ||
import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; | ||
import com.sinch.sdk.domains.sms.models.DeliveryReportType; | ||
import com.sinch.sdk.domains.sms.models.dto.v1.DeliveryReportListDto; | ||
import com.sinch.sdk.domains.sms.models.requests.DeliveryReportBatchGetRequestParameters; | ||
import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; | ||
import com.sinch.sdk.domains.sms.models.responses.DeliveryReportsListResponse; | ||
import com.sinch.sdk.models.Configuration; | ||
import java.time.Instant; | ||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Delivery reports Service | ||
* | ||
* <p>The REST API uses message statuses and error codes in delivery reports, which refer to the | ||
* state of the batch and can be present in either <a | ||
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports/#tag/Delivery-reports/operation/GetDeliveryReportByBatchId">Retrieve | ||
* a delivery report</a> or sent as a callback. | ||
* | ||
* @see <a | ||
* href="https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports">https://developers.sinch.com/docs/sms/api-reference/sms/tag/Delivery-reports</a> | ||
* @since 1.0 | ||
*/ | ||
public class DeliveryReportsService implements com.sinch.sdk.domains.sms.DeliveryReportsService { | ||
|
||
private Configuration configuration; | ||
private DeliveryReportsApi api; | ||
|
||
public DeliveryReportsService() {} | ||
|
||
private DeliveryReportsApi getApi() { | ||
return this.api; | ||
} | ||
|
||
public DeliveryReportsService(Configuration configuration, HttpClient httpClient) { | ||
this.configuration = configuration; | ||
this.api = new DeliveryReportsApi(httpClient, configuration.getSmsServer(), new HttpMapper()); | ||
} | ||
|
||
public DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestParameters parameters) | ||
throws ApiException { | ||
|
||
DeliveryReportBatchGetRequestParameters guardParameters = | ||
null != parameters ? parameters : DeliveryReportBatchGetRequestParameters.builder().build(); | ||
|
||
return DeliveryReportDtoConverter.convert( | ||
getApi() | ||
.getDeliveryReportByBatchId( | ||
configuration.getProjectId(), | ||
batchId, | ||
guardParameters.getType().map(DeliveryReportType::value).orElse(null), | ||
guardParameters | ||
.geStatues() | ||
.map(f -> f.stream().map(EnumDynamic::value).collect(Collectors.joining(","))) | ||
.orElse(null), | ||
guardParameters | ||
.getCodes() | ||
.map(f -> f.stream().map(Object::toString).collect(Collectors.joining(","))) | ||
.orElse(null))); | ||
} | ||
|
||
public DeliveryReportRecipient getForNumber(String batchId, String recipient) | ||
throws ApiException { | ||
return DeliveryReportDtoConverter.convert( | ||
getApi().getDeliveryReportByPhoneNumber(configuration.getProjectId(), batchId, recipient)); | ||
} | ||
|
||
public DeliveryReportsListResponse list(DeliveryReportListRequestParameters parameters) | ||
throws ApiException { | ||
DeliveryReportListRequestParameters guardParameters = | ||
null != parameters ? parameters : DeliveryReportListRequestParameters.builder().build(); | ||
|
||
DeliveryReportListDto response = | ||
getApi() | ||
.getDeliveryReports( | ||
configuration.getProjectId(), | ||
guardParameters.getPage().orElse(null), | ||
guardParameters.getPageSize().orElse(null), | ||
guardParameters.getStartDate().map(Instant::toString).orElse(null), | ||
guardParameters.getEndDate().map(Instant::toString).orElse(null), | ||
guardParameters | ||
.getStatuses() | ||
.map(f -> f.stream().map(EnumDynamic::value).collect(Collectors.joining(","))) | ||
.orElse(null), | ||
guardParameters | ||
.getCodes() | ||
.map(f -> f.stream().map(Object::toString).collect(Collectors.joining(","))) | ||
.orElse(null), | ||
guardParameters.getClientReference().orElse(null)); | ||
|
||
Pair<Collection<DeliveryReportRecipient>, PageToken<Integer>> content = | ||
DeliveryReportDtoConverter.convert(response); | ||
|
||
return new DeliveryReportsListResponse( | ||
this, new Page<>(guardParameters, content.getLeft(), content.getRight())); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
allows to set the variable only once anywhere, be it constructor, or another method. Does it makes sense to mark this variables asfinal
in this context?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should yes.
But I'm facing an issue (not yet finalized) due to unit testing and mocking library: when set to
final
mocking lib is not able to set variables and test execution are facing null pointer.I'll have to take time to fix this...