diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index c83cbcec..0d917bfb 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -2,7 +2,8 @@ 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.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; 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; @@ -13,9 +14,9 @@ public interface BatchesService { BatchResponse send(BatchRequest batch) throws ApiException; - ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException; + ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException; - DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch); + DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch); BatchResponse get(String batchId) throws ApiException; diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index b2d4d166..e189c948 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -8,7 +8,8 @@ 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.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; 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; @@ -16,7 +17,6 @@ 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 { @@ -40,20 +40,12 @@ public BatchResponse send(BatchRequest batch) throws ApiException { return getApi().send(batch); } - public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException { + public ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException { - ListBatchesRequest guardParameters = - null != parameters ? parameters : ListBatchesRequest.builder().build(); + ListBatchesQueryParameters guardParameters = + null != parameters ? parameters : ListBatchesQueryParameters.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)); + ApiBatchList response = getApi().list(parameters); SMSCursorPageNavigator navigator = new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); @@ -62,8 +54,8 @@ public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiExcepti this, new Page<>(guardParameters, response.getBatches(), navigator)); } - public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch) { - return getApi().dryRun(perRecipient, numberOfRecipient, batch); + public DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch) { + return getApi().dryRun(queryParameters, batch); } public BatchResponse get(String batchId) throws ApiException { diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java deleted file mode 100644 index b6415dd1..00000000 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.sinch.sdk.domains.sms.models.v1.batches.request; - -import com.sinch.sdk.core.models.OptionalValue; -import java.time.Instant; - -public class ListBatchesRequest { - - private final OptionalValue from; - private final OptionalValue startDate; - private final OptionalValue endDate; - private final OptionalValue clientReference; - private final OptionalValue page; - private final OptionalValue pageSize; - - private ListBatchesRequest( - OptionalValue from, - OptionalValue startDate, - OptionalValue endDate, - OptionalValue clientReference, - OptionalValue page, - OptionalValue pageSize) { - this.from = from; - this.startDate = startDate; - this.endDate = endDate; - this.clientReference = clientReference; - this.page = page; - this.pageSize = pageSize; - } - - public OptionalValue getFrom() { - return from; - } - - public OptionalValue getStartDate() { - return startDate; - } - - public OptionalValue getEndDate() { - return endDate; - } - - public OptionalValue getClientReference() { - return clientReference; - } - - public OptionalValue getPage() { - return page; - } - - public OptionalValue getPageSize() { - return pageSize; - } - - public static Builder builder() { - return new Builder(); - } - - public static Builder builder(ListBatchesRequest parameters) { - return new Builder(parameters); - } - - public static class Builder { - - OptionalValue from = OptionalValue.empty(); - OptionalValue startDate = OptionalValue.empty(); - OptionalValue endDate = OptionalValue.empty(); - OptionalValue clientReference = OptionalValue.empty(); - OptionalValue page = OptionalValue.empty(); - OptionalValue pageSize = OptionalValue.empty(); - - private Builder() {} - - private Builder(ListBatchesRequest parameters) { - this.from = parameters.from; - this.startDate = parameters.startDate; - this.endDate = parameters.endDate; - this.clientReference = parameters.clientReference; - this.page = parameters.page; - this.pageSize = parameters.pageSize; - } - - /** - * @param from Only list messages sent from this sender number. Multiple originating numbers can - * be comma separated. Must be phone numbers or short code. - * @return current builder - */ - public Builder setFrom(String from) { - this.from = OptionalValue.of(from); - return this; - } - - /** - * @param startDate Only list messages received at or after this date/time. - * @return current builder - */ - public Builder setStartDate(Instant startDate) { - this.startDate = OptionalValue.of(startDate); - return this; - } - - /** - * @param endDate Only list messages received before this date/time - * @return current builder - */ - public Builder setEndDate(Instant endDate) { - this.endDate = OptionalValue.of(endDate); - return this; - } - - /** - * @param clientReference Client reference to include - * @return current builder - */ - public Builder setClientReference(String clientReference) { - this.clientReference = OptionalValue.of(clientReference); - return this; - } - - /** - * @param page The page number starting from 0 - * @return current builder - */ - public Builder setPage(Integer page) { - this.page = OptionalValue.of(page); - return this; - } - - /** - * @param pageSize Determines the size of a page - * @return current builder - */ - public Builder setPageSize(Integer pageSize) { - this.pageSize = OptionalValue.of(pageSize); - return this; - } - - public ListBatchesRequest build() { - return new ListBatchesRequest(from, startDate, endDate, clientReference, page, pageSize); - } - } -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java index 20a0ce6b..02bd716f 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java @@ -3,18 +3,18 @@ import com.sinch.sdk.core.models.pagination.ListResponse; import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.api.v1.BatchesService; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import java.util.Collection; import java.util.NoSuchElementException; public class ListBatchesResponse extends ListResponse { - private final Page page; + private final Page page; private final BatchesService service; private ListBatchesResponse nextPage; public ListBatchesResponse( - BatchesService service, Page page) { + BatchesService service, Page page) { this.service = service; this.page = page; } @@ -22,7 +22,8 @@ public ListBatchesResponse( public boolean hasNextPage() { if (null == nextPage) { - ListBatchesRequest.Builder newParameters = ListBatchesRequest.builder(page.getParameters()); + ListBatchesQueryParameters.Builder newParameters = + ListBatchesQueryParameters.builder(page.getParameters()); newParameters.setPage(page.getNextPageToken()); nextPage = service.list(newParameters.build()); } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java index 67189c06..1cc3825c 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java @@ -18,6 +18,8 @@ import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; import com.sinch.sdk.domains.sms.models.v1.batches.MediaBodyDtoTest; import com.sinch.sdk.domains.sms.models.v1.batches.request.BinaryRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.MediaRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; @@ -347,9 +349,12 @@ void sendText() throws ApiException { @Test void dryRun() throws ApiException { - when(api.dryRun(eq(true), eq(456), eq(sendSmsBatchTextRequest))).thenReturn(dryRunResponseDto); + DryRunQueryParameters queryParameters = + DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(456).build(); + when(api.dryRun(eq(queryParameters), eq(sendSmsBatchTextRequest))) + .thenReturn(dryRunResponseDto); - DryRunResponse response = service.dryRun(true, 456, sendSmsBatchTextRequest); + DryRunResponse response = service.dryRun(queryParameters, sendSmsBatchTextRequest); TestHelpers.recursiveEquals(response, dryRunResponseDto); } @@ -357,13 +362,14 @@ void dryRun() throws ApiException { @Test void list() throws ApiException { - when(api.list(eq(null), eq(null), eq(null), eq(null), eq(null), eq(null))) - .thenReturn(listBatchesResponseDtoPage0); - when(api.list(eq(1), eq(null), eq(null), eq(null), eq(null), eq(null))) - .thenReturn(listBatchesResponseDtoPage1); - when(api.list(eq(2), eq(null), eq(null), eq(null), eq(null), eq(null))) - .thenReturn(listBatchesResponseDtoPage2); - ListBatchesResponse response = service.list(null); + ListBatchesQueryParameters initialRequest = ListBatchesQueryParameters.builder().build(); + ListBatchesQueryParameters page1 = ListBatchesQueryParameters.builder().setPage(1).build(); + ListBatchesQueryParameters page2 = ListBatchesQueryParameters.builder().setPage(2).build(); + + when(api.list(initialRequest)).thenReturn(listBatchesResponseDtoPage0); + when(api.list(page1)).thenReturn(listBatchesResponseDtoPage1); + when(api.list(page2)).thenReturn(listBatchesResponseDtoPage2); + ListBatchesResponse response = service.list(initialRequest); Iterator iterator = response.iterator(); BatchResponse batch = iterator.next(); diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java deleted file mode 100644 index 085a39e8..00000000 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.sinch.sdk.domains.sms.models.v1.request; - -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; -import java.time.Instant; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -class ListBatchesRequestTest { - - static final String from = "foo from"; - - static Instant startDate = Instant.now(); - static Instant endDate = Instant.now(); - static String clientReference = "a client reference"; - static Integer page = 1; - static Integer pageSize = 3; - - public static final ListBatchesRequest value = - ListBatchesRequest.builder() - .setFrom(from) - .setStartDate(startDate) - .setEndDate(endDate) - .setClientReference(clientReference) - .setPage(page) - .setPageSize(pageSize) - .build(); - - @Test - void getFrom() { - Assertions.assertThat(value.getFrom().get()).isEqualTo(from); - } - - @Test - void getStartDate() { - Assertions.assertThat(value.getStartDate().get()).isEqualTo(startDate); - } - - @Test - void getEndDate() { - Assertions.assertThat(value.getEndDate().get()).isEqualTo(endDate); - } - - @Test - void getClientReference() { - Assertions.assertThat(value.getClientReference().get()).isEqualTo(clientReference); - } - - @Test - void getPage() { - Assertions.assertThat(value.getPage().get()).isEqualTo(page); - } - - @Test - void getPageSize() { - Assertions.assertThat(value.getPageSize().get()).isEqualTo(pageSize); - } -} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java index 7d58a5f8..a7372431 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java @@ -3,7 +3,8 @@ import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.sms.api.v1.BatchesService; import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; @@ -117,26 +118,31 @@ public void dryRun() { .setDeliveryReport(DeliveryReportType.NONE) .build(); - dryRunResponse = service.dryRun(true, 3, request); + DryRunQueryParameters queryParameters = + DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(3).build(); + dryRunResponse = service.dryRun(queryParameters, request); } @When("^I send a request to list the SMS batches$") public void listOnePage() { - ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + ListBatchesQueryParameters request = + ListBatchesQueryParameters.builder().setPageSize(2).build(); listOnePageResponse = service.list(request); } @When("^I send a request to list all the SMS batches$") public void listAll() { - ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + ListBatchesQueryParameters request = + ListBatchesQueryParameters.builder().setPageSize(2).build(); listAllResponse = service.list(request); } @When("^I iterate manually over the SMS batches pages$") public void listAllByPage() { - ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + ListBatchesQueryParameters request = + ListBatchesQueryParameters.builder().setPageSize(2).build(); listAllByPageResponse = service.list(request); } diff --git a/core/src/main/com/sinch/sdk/core/databind/QueryParameterSerializer.java b/core/src/main/com/sinch/sdk/core/databind/QueryParameterSerializer.java new file mode 100644 index 00000000..9b049d1f --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/databind/QueryParameterSerializer.java @@ -0,0 +1,5 @@ +package com.sinch.sdk.core.databind; + +import java.util.function.Function; + +public interface QueryParameterSerializer extends Function {} diff --git a/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java b/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java new file mode 100644 index 00000000..1381407a --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java @@ -0,0 +1,26 @@ +package com.sinch.sdk.core.databind.query_parameter; + +import com.sinch.sdk.core.databind.QueryParameterSerializer; +import java.time.Instant; + +public class InstantToIso8601Serializer implements QueryParameterSerializer { + + public static InstantToIso8601Serializer getInstance() { + return LazyHolder.INSTANCE; + } + + @Override + public String apply(Instant instant) { + if (null == instant) { + return null; + } + return instant.toString(); + } + + private static class LazyHolder { + private static final InstantToIso8601Serializer INSTANCE = new InstantToIso8601Serializer(); + } + + private InstantToIso8601Serializer() {} + ; +} diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameter.java b/core/src/main/com/sinch/sdk/core/http/URLParameter.java index 82a54171..c84d4c2b 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameter.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameter.java @@ -69,6 +69,17 @@ public enum STYLE { SIMPLE, SPACE_DELIMITED, PIPE_DELIMITED, - DEEP_OBJECT + DEEP_OBJECT; } + + // the following constants do not follow java standard by purpose + // Aim is to have direct access to OpenApi Spec authorized values as constant without overhead + // ref: https://spec.openapis.org/oas/latest.html#style-values + public static final STYLE matrix = STYLE.MATRIX; + public static final STYLE label = STYLE.LABEL; + public static final STYLE form = STYLE.FORM; + public static final STYLE simple = STYLE.SIMPLE; + public static final STYLE spaceDelimited = STYLE.SPACE_DELIMITED; + public static final STYLE pipeDelimited = STYLE.PIPE_DELIMITED; + public static final STYLE deepObject = STYLE.DEEP_OBJECT; } diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java index 7ced9d8b..6def5f84 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java @@ -1,6 +1,9 @@ package com.sinch.sdk.core.http; +import com.sinch.sdk.core.databind.QueryParameterSerializer; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.core.utils.EnumDynamic; import com.sinch.sdk.core.utils.StringUtil; import java.io.UnsupportedEncodingException; @@ -8,6 +11,7 @@ import java.security.InvalidParameterException; import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -26,7 +30,7 @@ public static String encodeParametersAsString(Collection parameter .collect(Collectors.joining("&")); } - public static Optional encode(URLParameter parameter) { + protected static Optional encode(URLParameter parameter) { if (null == parameter || StringUtil.isEmpty(parameter.getName()) @@ -195,7 +199,7 @@ private static Optional encodeObject(URLParameter parameter) { throw new ApiException("Not yet implemented '" + parameter + "'"); } - public static String encodeParameterValue(String value) { + private static String encodeParameterValue(String value) { try { return URLEncoder.encode(value, "UTF-8").replaceAll("\\.", "%2E"); @@ -203,4 +207,21 @@ public static String encodeParameterValue(String value) { return value; } } + + public static void addQueryParam( + OptionalValue optionalValue, + String paramName, + STYLE paramStyle, + QueryParameterSerializer serializer, + List queryParametersList, + boolean explode) { + optionalValue.ifPresent( + value -> + queryParametersList.add( + new URLParameter( + paramName, + null == serializer ? value : serializer.apply(value), + paramStyle, + explode))); + } } diff --git a/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java new file mode 100644 index 00000000..2806c58a --- /dev/null +++ b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java @@ -0,0 +1,29 @@ +package com.sinch.sdk.core.databind.query_parameter; + +import com.sinch.sdk.core.TestHelpers; +import java.time.Instant; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class InstantToIso8601SerializerTest { + + InstantToIso8601Serializer serializer = InstantToIso8601Serializer.getInstance(); + + @Test + void serialize() { + + Instant instant = Instant.parse("2024-05-04T10:00:00.123Z"); + + String serialized = serializer.apply(instant); + + TestHelpers.recursiveEquals("2024-05-04T10:00:00.123Z", serialized); + } + + @Test + void serializeNull() { + + String serialized = serializer.apply(null); + + Assertions.assertNull(serialized); + } +} diff --git a/core/src/test/java/com/sinch/sdk/core/http/URLParameterTest.java b/core/src/test/java/com/sinch/sdk/core/http/URLParameterTest.java new file mode 100644 index 00000000..f39bcf29 --- /dev/null +++ b/core/src/test/java/com/sinch/sdk/core/http/URLParameterTest.java @@ -0,0 +1,44 @@ +package com.sinch.sdk.core.http; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.sinch.sdk.core.http.URLParameter.STYLE; +import org.junit.jupiter.api.Test; + +class URLParameterTest { + + @Test + void matrix() { + assertEquals(STYLE.MATRIX, URLParameter.matrix); + } + + @Test + void label() { + assertEquals(STYLE.LABEL, URLParameter.label); + } + + @Test + void form() { + assertEquals(STYLE.FORM, URLParameter.form); + } + + @Test + void simple() { + assertEquals(STYLE.SIMPLE, URLParameter.simple); + } + + @Test + void spaceDelimited() { + assertEquals(STYLE.SPACE_DELIMITED, URLParameter.spaceDelimited); + } + + @Test + void pipeDelimited() { + assertEquals(STYLE.PIPE_DELIMITED, URLParameter.pipeDelimited); + } + + @Test + void deepObject() { + assertEquals(STYLE.DEEP_OBJECT, URLParameter.deepObject); + } +} diff --git a/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java b/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java index 35b58238..0d977de4 100644 --- a/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java +++ b/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java @@ -1,10 +1,18 @@ package com.sinch.sdk.core.http; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.databind.query_parameter.InstantToIso8601Serializer; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -374,4 +382,51 @@ void encodePipeDelimitedArrayExplode() { URLParameter.STYLE.PIPE_DELIMITED, true))); } + + @Test + void addQueryParamNotPresent() { + + // Collections.emptyList() is not modifiable and will throw an exception if trying to add an + // entry + assertDoesNotThrow( + () -> + URLParameterUtils.addQueryParam( + OptionalValue.empty(), + "foo name", + STYLE.DEEP_OBJECT, + null, + Collections.emptyList(), + false), + "Ignored empty value"); + } + + @Test + void addQueryParamInteger() { + ArrayList list = new ArrayList<>(); + + URLParameterUtils.addQueryParam( + OptionalValue.of(15), "foo name", STYLE.DEEP_OBJECT, null, list, true); + assertEquals(1, list.size()); + + TestHelpers.recursiveEquals( + list.get(0), new URLParameter("foo name", 15, STYLE.DEEP_OBJECT, true)); + } + + @Test + void addQueryParamInstant() { + ArrayList list = new ArrayList<>(); + + URLParameterUtils.addQueryParam( + OptionalValue.of(Instant.parse("2024-05-04T10:00:00.123Z")), + "foo name", + STYLE.DEEP_OBJECT, + InstantToIso8601Serializer.getInstance(), + list, + true); + assertEquals(1, list.size()); + + TestHelpers.recursiveEquals( + list.get(0), + new URLParameter("foo name", "2024-05-04T10:00:00.123Z", STYLE.DEEP_OBJECT, true)); + } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java index 608bb175..dfd0e385 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java @@ -11,6 +11,7 @@ package com.sinch.sdk.domains.sms.api.v1.internal; import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.databind.query_parameter.InstantToIso8601Serializer; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; import com.sinch.sdk.core.http.AuthManager; @@ -21,9 +22,12 @@ import com.sinch.sdk.core.http.HttpResponse; import com.sinch.sdk.core.http.HttpStatus; import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; 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; @@ -74,14 +78,7 @@ public BatchesApi( */ public BatchResponse cancel(String batchId) throws ApiException { - LOGGER.finest( - "[cancel]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "batchId: " - + batchId); + LOGGER.finest("[cancel]" + " " + "batchId: " + batchId); HttpRequest httpRequest = cancelRequestBuilder(batchId); HttpResponse response = @@ -146,33 +143,24 @@ private HttpRequest cancelRequestBuilder(String batchId) throws ApiException { * Dry run This operation will perform a dry run of a batch which calculates the bodies and number * of parts for all messages in the batch without actually sending any messages. * - * @param perRecipient Whether to include per recipient details in the response (optional) - * @param numberOfRecipients Max number of recipients to include per recipient details for in the - * response (optional, default to 100) + * @param queryParameter (optional) * @param sendRequest (optional) * @return DryRunResponse * @throws ApiException if fails to make API call */ - public DryRunResponse dryRun( - Boolean perRecipient, Integer numberOfRecipients, BatchRequest sendRequest) + public DryRunResponse dryRun(DryRunQueryParameters queryParameter, BatchRequest sendRequest) throws ApiException { LOGGER.finest( "[dryRun]" + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "perRecipient: " - + perRecipient - + ", " - + "numberOfRecipients: " - + numberOfRecipients + + "queryParameter: " + + queryParameter + ", " + "sendRequest: " + sendRequest); - HttpRequest httpRequest = dryRunRequestBuilder(perRecipient, numberOfRecipients, sendRequest); + HttpRequest httpRequest = dryRunRequestBuilder(queryParameter, sendRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -191,8 +179,7 @@ public DryRunResponse dryRun( } private HttpRequest dryRunRequestBuilder( - Boolean perRecipient, Integer numberOfRecipients, BatchRequest sendRequest) - throws ApiException { + DryRunQueryParameters queryParameter, BatchRequest sendRequest) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( @@ -206,21 +193,23 @@ private HttpRequest dryRunRequestBuilder( URLPathUtils.encodePathSegment(this.servicePlanId.toString())); List localVarQueryParams = new ArrayList<>(); - if (null != perRecipient) { - localVarQueryParams.add( - new URLParameter( - "per_recipient", - perRecipient, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true)); - } - if (null != numberOfRecipients) { - localVarQueryParams.add( - new URLParameter( - "number_of_recipients", - numberOfRecipients, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true)); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getPerRecipient(), + "per_recipient", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getNumberOfRecipients(), + "number_of_recipients", + URLParameter.form, + null, + localVarQueryParams, + true); } Map localVarHeaderParams = new HashMap<>(); @@ -252,8 +241,7 @@ private HttpRequest dryRunRequestBuilder( */ public BatchResponse get(String batchId) throws ApiException { - LOGGER.finest( - "[get]" + " " + "this.servicePlanId: " + this.servicePlanId + ", " + "batchId: " + batchId); + LOGGER.finest("[get]" + " " + "batchId: " + batchId); HttpRequest httpRequest = getRequestBuilder(batchId); HttpResponse response = @@ -318,55 +306,15 @@ private HttpRequest getRequestBuilder(String batchId) throws ApiException { * List Batches With the list operation you can list batch messages created in the last 14 days * that you have created. This operation supports pagination. * - * @param page The page number starting from 0. (optional, default to 0) - * @param pageSize Determines the size of a page. (optional, default to 30) - * @param from Only list messages sent from this sender number. Multiple originating numbers can - * be comma separated. Must be phone numbers or short code. (optional) - * @param startDate Only list messages received at or after this date/time. Formatted as - * [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`. - * Default: Now-24 (optional) - * @param endDate Only list messages received before this date/time. Formatted as - * [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`. - * (optional) - * @param clientReference Client reference to include (optional) + * @param queryParameter (optional) * @return ApiBatchList * @throws ApiException if fails to make API call */ - public ApiBatchList list( - Integer page, - Integer pageSize, - String from, - String startDate, - String endDate, - String clientReference) - throws ApiException { + public ApiBatchList list(ListBatchesQueryParameters queryParameter) throws ApiException { - LOGGER.finest( - "[list]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "page: " - + page - + ", " - + "pageSize: " - + pageSize - + ", " - + "from: " - + from - + ", " - + "startDate: " - + startDate - + ", " - + "endDate: " - + endDate - + ", " - + "clientReference: " - + clientReference); + LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); - HttpRequest httpRequest = - listRequestBuilder(page, pageSize, from, startDate, endDate, clientReference); + HttpRequest httpRequest = listRequestBuilder(queryParameter); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -384,13 +332,7 @@ public ApiBatchList list( mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest listRequestBuilder( - Integer page, - Integer pageSize, - String from, - String startDate, - String endDate, - String clientReference) + private HttpRequest listRequestBuilder(ListBatchesQueryParameters queryParameter) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { @@ -405,36 +347,45 @@ private HttpRequest listRequestBuilder( URLPathUtils.encodePathSegment(this.servicePlanId.toString())); List localVarQueryParams = new ArrayList<>(); - if (null != page) { - localVarQueryParams.add( - new URLParameter("page", page, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != pageSize) { - localVarQueryParams.add( - new URLParameter( - "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != from) { - localVarQueryParams.add( - new URLParameter("from", from, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != startDate) { - localVarQueryParams.add( - new URLParameter( - "start_date", startDate, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != endDate) { - localVarQueryParams.add( - new URLParameter( - "end_date", endDate, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != clientReference) { - localVarQueryParams.add( - new URLParameter( - "client_reference", - clientReference, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true)); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getPage(), "page", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getPageSize(), + "page_size", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getFrom(), "from", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getStartDate(), + "start_date", + URLParameter.form, + InstantToIso8601Serializer.getInstance(), + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getEndDate(), + "end_date", + URLParameter.form, + InstantToIso8601Serializer.getInstance(), + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getClientReference(), + "client_reference", + URLParameter.form, + null, + localVarQueryParams, + true); } Map localVarHeaderParams = new HashMap<>(); @@ -468,17 +419,7 @@ private HttpRequest listRequestBuilder( */ public BatchResponse replace(String batchId, BatchRequest sendRequest) throws ApiException { - LOGGER.finest( - "[replace]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "batchId: " - + batchId - + ", " - + "sendRequest: " - + sendRequest); + LOGGER.finest("[replace]" + " " + "batchId: " + batchId + ", " + "sendRequest: " + sendRequest); HttpRequest httpRequest = replaceRequestBuilder(batchId, sendRequest); HttpResponse response = @@ -561,9 +502,6 @@ public void sendDeliveryFeedback( LOGGER.finest( "[sendDeliveryFeedback]" + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " + "batchId: " + batchId + ", " @@ -653,14 +591,7 @@ private HttpRequest sendDeliveryFeedbackRequestBuilder( */ public BatchResponse send(BatchRequest sendRequest) throws ApiException { - LOGGER.finest( - "[send]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "sendRequest: " - + sendRequest); + LOGGER.finest("[send]" + " " + "sendRequest: " + sendRequest); HttpRequest httpRequest = sendRequestBuilder(sendRequest); HttpResponse response = @@ -730,9 +661,6 @@ public BatchResponse update(String batchId, UpdateBatchRequest updateBatchReques LOGGER.finest( "[update]" + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " + "batchId: " + batchId + ", " diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParameters.java new file mode 100644 index 00000000..2bc16fc1 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParameters.java @@ -0,0 +1,78 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; + +/** DryRunQueryParameters */ +public interface DryRunQueryParameters { + + /** + * Get perRecipient + * + * @return perRecipient + */ + OptionalValue getPerRecipient(); + + /** + * Get numberOfRecipients maximum: 1000 + * + * @return numberOfRecipients + */ + OptionalValue getNumberOfRecipients(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new DryRunQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(DryRunQueryParameters parameters) { + return new DryRunQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param perRecipient see getter + * @return Current builder + * @see #getPerRecipient + */ + Builder setPerRecipient(Boolean perRecipient); + + /** + * see getter + * + * @param numberOfRecipients see getter + * @return Current builder + * @see #getNumberOfRecipients + */ + Builder setNumberOfRecipients(Integer numberOfRecipients); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + DryRunQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java new file mode 100644 index 00000000..a5d2201c --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java @@ -0,0 +1,90 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +public class DryRunQueryParametersImpl implements DryRunQueryParameters { + + private final OptionalValue perRecipient; + private final OptionalValue numberOfRecipients; + + private DryRunQueryParametersImpl( + OptionalValue perRecipient, OptionalValue numberOfRecipients) { + this.perRecipient = perRecipient; + this.numberOfRecipients = numberOfRecipients; + } + + public OptionalValue getPerRecipient() { + return perRecipient; + } + + public OptionalValue getNumberOfRecipients() { + return numberOfRecipients; + } + + /** Return true if this DryRunQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DryRunQueryParametersImpl dryRunQueryParameters = (DryRunQueryParametersImpl) o; + return Objects.equals(this.perRecipient, dryRunQueryParameters.perRecipient) + && Objects.equals(this.numberOfRecipients, dryRunQueryParameters.numberOfRecipients); + } + + @Override + public int hashCode() { + return Objects.hash(perRecipient, numberOfRecipients); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DryRunQueryParametersImpl {\n"); + sb.append(" perRecipient: ").append(toIndentedString(perRecipient)).append("\n"); + sb.append(" numberOfRecipients: ").append(toIndentedString(numberOfRecipients)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + static class Builder implements DryRunQueryParameters.Builder { + OptionalValue perRecipient = OptionalValue.empty(); + OptionalValue numberOfRecipients = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(DryRunQueryParameters _parameters) { + DryRunQueryParametersImpl parameters = (DryRunQueryParametersImpl) _parameters; + this.perRecipient = parameters.getPerRecipient(); + this.numberOfRecipients = parameters.getNumberOfRecipients(); + } + + public Builder setPerRecipient(Boolean perRecipient) { + this.perRecipient = OptionalValue.of(perRecipient); + return this; + } + + public Builder setNumberOfRecipients(Integer numberOfRecipients) { + this.numberOfRecipients = OptionalValue.of(numberOfRecipients); + return this; + } + + public DryRunQueryParameters build() { + return new DryRunQueryParametersImpl(perRecipient, numberOfRecipients); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParameters.java new file mode 100644 index 00000000..d2032cd2 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParameters.java @@ -0,0 +1,143 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; + +/** ListBatchesQueryParameters */ +public interface ListBatchesQueryParameters { + + /** + * Get page minimum: 0 + * + * @return page + */ + OptionalValue getPage(); + + /** + * Get pageSize maximum: 100 + * + * @return pageSize + */ + OptionalValue getPageSize(); + + /** + * Get from + * + * @return from + */ + OptionalValue getFrom(); + + /** + * Get startDate + * + * @return startDate + */ + OptionalValue getStartDate(); + + /** + * Get endDate + * + * @return endDate + */ + OptionalValue getEndDate(); + + /** + * Get clientReference + * + * @return clientReference + */ + OptionalValue getClientReference(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ListBatchesQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(ListBatchesQueryParameters parameters) { + return new ListBatchesQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param startDate see getter + * @return Current builder + * @see #getStartDate + */ + Builder setStartDate(Instant startDate); + + /** + * see getter + * + * @param endDate see getter + * @return Current builder + * @see #getEndDate + */ + Builder setEndDate(Instant endDate); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ListBatchesQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java new file mode 100644 index 00000000..8372d2cc --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java @@ -0,0 +1,157 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Objects; + +public class ListBatchesQueryParametersImpl implements ListBatchesQueryParameters { + + private final OptionalValue page; + private final OptionalValue pageSize; + private final OptionalValue from; + private final OptionalValue startDate; + private final OptionalValue endDate; + private final OptionalValue clientReference; + + private ListBatchesQueryParametersImpl( + OptionalValue page, + OptionalValue pageSize, + OptionalValue from, + OptionalValue startDate, + OptionalValue endDate, + OptionalValue clientReference) { + this.page = page; + this.pageSize = pageSize; + this.from = from; + this.startDate = startDate; + this.endDate = endDate; + this.clientReference = clientReference; + } + + public OptionalValue getPage() { + return page; + } + + public OptionalValue getPageSize() { + return pageSize; + } + + public OptionalValue getFrom() { + return from; + } + + public OptionalValue getStartDate() { + return startDate; + } + + public OptionalValue getEndDate() { + return endDate; + } + + public OptionalValue getClientReference() { + return clientReference; + } + + /** Return true if this ListBatchesQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ListBatchesQueryParametersImpl listBatchesQueryParameters = (ListBatchesQueryParametersImpl) o; + return Objects.equals(this.page, listBatchesQueryParameters.page) + && Objects.equals(this.pageSize, listBatchesQueryParameters.pageSize) + && Objects.equals(this.from, listBatchesQueryParameters.from) + && Objects.equals(this.startDate, listBatchesQueryParameters.startDate) + && Objects.equals(this.endDate, listBatchesQueryParameters.endDate) + && Objects.equals(this.clientReference, listBatchesQueryParameters.clientReference); + } + + @Override + public int hashCode() { + return Objects.hash(page, pageSize, from, startDate, endDate, clientReference); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ListBatchesQueryParametersImpl {\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" startDate: ").append(toIndentedString(startDate)).append("\n"); + sb.append(" endDate: ").append(toIndentedString(endDate)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + static class Builder implements ListBatchesQueryParameters.Builder { + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue startDate = OptionalValue.empty(); + OptionalValue endDate = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(ListBatchesQueryParameters _parameters) { + ListBatchesQueryParametersImpl parameters = (ListBatchesQueryParametersImpl) _parameters; + this.page = parameters.getPage(); + this.pageSize = parameters.getPageSize(); + this.from = parameters.getFrom(); + this.startDate = parameters.getStartDate(); + this.endDate = parameters.getEndDate(); + this.clientReference = parameters.getClientReference(); + } + + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + public Builder setStartDate(Instant startDate) { + this.startDate = OptionalValue.of(startDate); + return this; + } + + public Builder setEndDate(Instant endDate) { + this.endDate = OptionalValue.of(endDate); + return this; + } + + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + public ListBatchesQueryParameters build() { + return new ListBatchesQueryParametersImpl( + page, pageSize, from, startDate, endDate, clientReference); + } + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java index 6ee19345..132f66fc 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java @@ -2,8 +2,10 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import java.io.IOException; +import java.time.Instant; +import java.time.Period; import java.util.logging.Logger; public class List extends BaseApplication { @@ -29,12 +31,12 @@ public void run() { LOGGER.info("Response:"); service .list( - ListBatchesRequest.builder() + ListBatchesQueryParameters.builder() // .setFrom(phoneNumber) // .setPage(15) .setPageSize(2) // .setClientReference("a client reference") - // .setStartDate(Instant.now()) + .setStartDate(Instant.now().minus(Period.ofWeeks(3))) .build()) .iterator() .forEachRemaining(f -> LOGGER.info(f.toString())); diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java index ab89da20..7ea8acb2 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java @@ -30,7 +30,7 @@ public void run() { SendDeliveryFeedbackRequest request = SendDeliveryFeedbackRequest.builder() - .setRecipients(Arrays.asList("foo number 1", "foo number 2")) + .setRecipients(Arrays.asList("+1234567890", "+0987654321")) .build(); service.sendDeliveryFeedback(batchId, request); LOGGER.info("Done"); diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java index 7fd0c48b..7a529a33 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java @@ -2,6 +2,7 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import java.io.IOException; @@ -28,10 +29,12 @@ public void run() { BatchesService service = client.sms().v1().batches(); LOGGER.info("DryRun Request"); + DryRunQueryParameters queryParameters = + DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(3).build(); + DryRunResponse value = service.dryRun( - true, - 3, + queryParameters, TextRequest.builder() .setTo(Collections.singletonList(phoneNumber)) .setBody("the body")