-
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.
- Loading branch information
Showing
12 changed files
with
527 additions
and
6 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
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
140 changes: 140 additions & 0 deletions
140
...c/main/com/sinch/sdk/domains/sms/models/requests/DeliveryReportListRequestParameters.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,140 @@ | ||
package com.sinch.sdk.domains.sms.models.requests; | ||
|
||
import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; | ||
import java.time.Instant; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Parameters request to list delivery reports for a project | ||
* | ||
* @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 | ||
*/ | ||
public class DeliveryReportListRequestParameters { | ||
|
||
private final Instant startDate; | ||
private final Instant endDate; | ||
private final String clientReference; | ||
private final Integer page; | ||
private final Integer pageSize; | ||
private final Collection<DeliveryReportStatus> statuses; | ||
private final Collection<Integer> codes; | ||
|
||
public DeliveryReportListRequestParameters( | ||
Instant startDate, | ||
Instant endDate, | ||
String clientReference, | ||
Integer page, | ||
Integer pageSize, | ||
Collection<DeliveryReportStatus> statuses, | ||
Collection<Integer> codes) { | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.clientReference = clientReference; | ||
this.page = page; | ||
this.pageSize = pageSize; | ||
this.statuses = statuses; | ||
this.codes = codes; | ||
} | ||
|
||
public Optional<Instant> getStartDate() { | ||
return Optional.ofNullable(startDate); | ||
} | ||
|
||
public Optional<Instant> getEndDate() { | ||
return Optional.ofNullable(endDate); | ||
} | ||
|
||
public Optional<String> getClientReference() { | ||
return Optional.ofNullable(clientReference); | ||
} | ||
|
||
public Optional<Integer> getPage() { | ||
return Optional.ofNullable(page); | ||
} | ||
|
||
public Optional<Integer> getPageSize() { | ||
return Optional.ofNullable(pageSize); | ||
} | ||
|
||
public Optional<Collection<DeliveryReportStatus>> getStatuses() { | ||
return Optional.ofNullable(statuses); | ||
} | ||
|
||
public Optional<Collection<Integer>> getCodes() { | ||
return Optional.ofNullable(codes); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static Builder builder(DeliveryReportListRequestParameters parameters) { | ||
return new Builder(parameters); | ||
} | ||
|
||
public static class Builder { | ||
|
||
Instant startDate; | ||
Instant endDate; | ||
String clientReference; | ||
Integer page; | ||
Integer pageSize; | ||
Collection<DeliveryReportStatus> statuses; | ||
Collection<Integer> codes; | ||
|
||
private Builder() {} | ||
|
||
private Builder(DeliveryReportListRequestParameters parameters) { | ||
this.startDate = parameters.startDate; | ||
this.endDate = parameters.endDate; | ||
this.clientReference = parameters.clientReference; | ||
this.page = parameters.page; | ||
this.pageSize = parameters.pageSize; | ||
this.statuses = parameters.statuses; | ||
this.codes = parameters.codes; | ||
} | ||
|
||
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 setStatuses(Collection<DeliveryReportStatus> statuses) { | ||
this.statuses = statuses; | ||
return this; | ||
} | ||
|
||
public Builder setCodes(Collection<Integer> codes) { | ||
this.codes = codes; | ||
return this; | ||
} | ||
|
||
public DeliveryReportListRequestParameters build() { | ||
return new DeliveryReportListRequestParameters( | ||
startDate, endDate, clientReference, page, pageSize, statuses, codes); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
client/src/main/com/sinch/sdk/domains/sms/models/responses/DeliveryReportsListResponse.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,51 @@ | ||
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.DeliveryReportsService; | ||
import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; | ||
import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; | ||
import java.util.Collection; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Lists batches response | ||
* | ||
* @since 1.0 | ||
*/ | ||
public class DeliveryReportsListResponse extends ListResponse<DeliveryReportRecipient> { | ||
|
||
private final Page<DeliveryReportListRequestParameters, DeliveryReportRecipient, Integer> page; | ||
private final DeliveryReportsService service; | ||
|
||
public DeliveryReportsListResponse( | ||
DeliveryReportsService service, | ||
Page<DeliveryReportListRequestParameters, DeliveryReportRecipient, Integer> page) { | ||
this.service = service; | ||
this.page = page; | ||
} | ||
|
||
public boolean hasNextPage() { | ||
return (null != page.getNextPageToken() && null != page.getNextPageToken().getToken()); | ||
} | ||
|
||
public DeliveryReportsListResponse nextPage() { | ||
if (!hasNextPage()) { | ||
throw new NoSuchElementException("Reached the last page of the API response"); | ||
} | ||
DeliveryReportListRequestParameters.Builder newParameters = | ||
DeliveryReportListRequestParameters.builder(page.getParameters()); | ||
Integer nextToken = page.getNextPageToken().getToken(); | ||
newParameters.setPage(nextToken); | ||
return service.list(newParameters.build()); | ||
} | ||
|
||
public Collection<DeliveryReportRecipient> getContent() { | ||
return page.getEntities(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DeliveryReportsListResponse{" + "page=" + page + '}'; | ||
} | ||
} |
Oops, something went wrong.