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

Mslres 5205 #35

Merged
merged 13 commits into from
Jul 11, 2023
Merged
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.2</version>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
Expand All @@ -396,7 +396,12 @@
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
<version>1.10.0</version>
<version>1.17.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.0.1-jre</version>
</dependency>

<dependency>
Expand Down
130 changes: 109 additions & 21 deletions src/main/java/com/sinch/xms/ApiConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
import com.sinch.xms.api.MtBatchBinarySmsResult;
import com.sinch.xms.api.MtBatchBinarySmsUpdate;
import com.sinch.xms.api.MtBatchDryRunResult;
import com.sinch.xms.api.MtBatchMmsCreate;
import com.sinch.xms.api.MtBatchMmsResult;
import com.sinch.xms.api.MtBatchMmsUpdate;
import com.sinch.xms.api.MtBatchResult;
import com.sinch.xms.api.MtBatchSmsCreate;
import com.sinch.xms.api.MtBatchSmsResult;
import com.sinch.xms.api.MtBatchTextSmsCreate;
import com.sinch.xms.api.MtBatchTextSmsResult;
import com.sinch.xms.api.MtBatchTextSmsUpdate;
Expand Down Expand Up @@ -327,7 +330,7 @@ private URI endpoint(@Nonnull String subPath, @Nonnull List<NameValuePair> param
}

/**
* Like {@link #endpoint(String, String)} but with no query parameters.
* Like {@link #endpoint(String, List<NameValuePair>)} but with no query parameters.
*
* @param subPath path fragment to place after the base path
* @return a non-null endpoint URL
Expand Down Expand Up @@ -604,6 +607,49 @@ public Future<MtBatchBinarySmsResult> createBatchAsync(
.execute(requestProducer, responseConsumer, callbackWrapper().wrap(callback));
}

/**
* Creates the given batch and schedules it for submission. If {@link MtBatchMmsCreate#sendAt()}
* returns <code>null</code> then the batch submission will begin immediately.
*
* <p>This method blocks until the request completes and its use is discouraged. Please consider
* using the asynchronous method {@link #createBatchAsync(MtBatchMmsCreate, FutureCallback)}
* instead.
*
* @param mms the batch to create
* @return a batch creation result
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws ApiException if an error occurred while communicating with XMS
*/
public MtBatchMmsResult createBatch(MtBatchMmsCreate mms)
throws InterruptedException, ApiException {
try {
return createBatchAsync(mms, null).get();
} catch (ExecutionException e) {
throw Utils.unwrapExecutionException(e);
}
}

/**
* Asynchronously creates the given mms batch and schedules it for submission. If {@link
* MtBatchMmsCreate#sendAt()} returns <code>null</code> then the batch submission will begin
* immediately.
*
* @param mms the batch to create
* @param callback a callback that is invoked when batch is created
* @return a future whose result is the creation response
*/
public Future<MtBatchMmsResult> createBatchAsync(
MtBatchMmsCreate mms, FutureCallback<MtBatchMmsResult> callback) {
HttpPost req = post(batchesEndpoint(), mms);

HttpAsyncRequestProducer requestProducer = new BasicAsyncRequestProducer(endpointHost(), req);
HttpAsyncResponseConsumer<MtBatchMmsResult> responseConsumer =
jsonAsyncConsumer(MtBatchMmsResult.class);

return httpClient()
.execute(requestProducer, responseConsumer, callbackWrapper().wrap(callback));
}

/**
* Replaces the batch with the given identifier. After this method completes the batch will match
* the provided batch description.
Expand Down Expand Up @@ -778,6 +824,48 @@ public Future<MtBatchBinarySmsResult> updateBatchAsync(
return httpClient().execute(producer, consumer, callbackWrapper().wrap(callback));
}

/**
* Updates the given mms batch.
*
* <p>This method blocks until the request completes and its use is discouraged. Please consider
* using the asynchronous method {@link #updateBatchAsync(BatchId, MtBatchMmsUpdate,
* FutureCallback)} instead.
*
* @param id identifier of the batch to update
* @param mms a description of the desired updated
* @return the batch with the updates applied
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws ApiException if an error occurred while communicating with XMS
*/
public MtBatchMmsResult updateBatch(BatchId id, MtBatchMmsUpdate mms)
throws InterruptedException, ApiException {
try {
return updateBatchAsync(id, mms, null).get();
} catch (ExecutionException e) {
throw Utils.unwrapExecutionException(e);
}
}

/**
* Asynchronously updates the mms batch with the given batch ID. The batch is updated to match the
* given update object.
*
* @param batchId the batch that should be updated
* @param mms description of the desired update
* @param callback called at call success, failure, or cancellation
* @return a future containing the updated batch
*/
public Future<MtBatchMmsResult> updateBatchAsync(
BatchId batchId, MtBatchMmsUpdate mms, FutureCallback<MtBatchMmsResult> callback) {
HttpPost req = post(batchEndpoint(batchId), mms);

HttpAsyncRequestProducer producer = new BasicAsyncRequestProducer(endpointHost(), req);
HttpAsyncResponseConsumer<MtBatchMmsResult> consumer =
jsonAsyncConsumer(MtBatchMmsResult.class);

return httpClient().execute(producer, consumer, callbackWrapper().wrap(callback));
}

/**
* Fetches the given batch.
*
Expand All @@ -789,7 +877,7 @@ public Future<MtBatchBinarySmsResult> updateBatchAsync(
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws ApiException if an error occurred while communicating with XMS
*/
public MtBatchSmsResult fetchBatch(BatchId id) throws InterruptedException, ApiException {
public MtBatchResult fetchBatch(BatchId id) throws InterruptedException, ApiException {
try {
return fetchBatchAsync(id, null).get();
} catch (ExecutionException e) {
Expand All @@ -804,14 +892,13 @@ public MtBatchSmsResult fetchBatch(BatchId id) throws InterruptedException, ApiE
* @param callback a callback that is activated at call completion
* @return a future yielding the desired batch
*/
public Future<MtBatchSmsResult> fetchBatchAsync(
BatchId batchId, FutureCallback<MtBatchSmsResult> callback) {
public Future<MtBatchResult> fetchBatchAsync(
BatchId batchId, FutureCallback<MtBatchResult> callback) {
HttpGet req = get(batchEndpoint(batchId));

HttpAsyncRequestProducer producer = new BasicAsyncRequestProducer(endpointHost(), req);

HttpAsyncResponseConsumer<MtBatchSmsResult> consumer =
jsonAsyncConsumer(MtBatchSmsResult.class);
HttpAsyncResponseConsumer<MtBatchResult> consumer = jsonAsyncConsumer(MtBatchResult.class);

return httpClient().execute(producer, consumer, callbackWrapper().wrap(callback));
}
Expand All @@ -823,12 +910,12 @@ public Future<MtBatchSmsResult> fetchBatchAsync(
* @param filter the batch filter
* @return a future page
*/
public PagedFetcher<MtBatchSmsResult> fetchBatches(final BatchFilter filter) {
return new PagedFetcher<MtBatchSmsResult>() {
public PagedFetcher<MtBatchResult> fetchBatches(final BatchFilter filter) {
return new PagedFetcher<MtBatchResult>() {

@Override
Future<Page<MtBatchSmsResult>> fetchAsync(
int page, FutureCallback<Page<MtBatchSmsResult>> callback) {
Future<Page<MtBatchResult>> fetchAsync(
int page, FutureCallback<Page<MtBatchResult>> callback) {
return fetchBatches(page, filter, callbackWrapper().wrap(callback));
}
};
Expand All @@ -842,16 +929,16 @@ Future<Page<MtBatchSmsResult>> fetchAsync(
* @param callback the callback to invoke when call is finished
* @return a future page
*/
private Future<Page<MtBatchSmsResult>> fetchBatches(
int page, BatchFilter filter, FutureCallback<Page<MtBatchSmsResult>> callback) {
private Future<Page<MtBatchResult>> fetchBatches(
int page, BatchFilter filter, FutureCallback<Page<MtBatchResult>> callback) {
List<NameValuePair> params = filter.toQueryParams(page);
URI url = endpoint("/batches", params);

HttpGet req = get(url);

HttpAsyncRequestProducer producer = new BasicAsyncRequestProducer(endpointHost(), req);

HttpAsyncResponseConsumer<Page<MtBatchSmsResult>> consumer =
HttpAsyncResponseConsumer<Page<MtBatchResult>> consumer =
jsonAsyncConsumer(PagedBatchResult.class);

return httpClient().execute(producer, consumer, callbackWrapper().wrap(callback));
Expand All @@ -868,7 +955,7 @@ private Future<Page<MtBatchSmsResult>> fetchBatches(
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws ApiException if an error occurred while communicating with XMS
*/
public MtBatchSmsResult cancelBatch(BatchId batchId) throws InterruptedException, ApiException {
public MtBatchResult cancelBatch(BatchId batchId) throws InterruptedException, ApiException {
try {
return cancelBatchAsync(batchId, null).get();
} catch (ExecutionException e) {
Expand All @@ -883,14 +970,13 @@ public MtBatchSmsResult cancelBatch(BatchId batchId) throws InterruptedException
* @param callback the callback invoked when request completes
* @return a future containing the batch that was cancelled
*/
public Future<MtBatchSmsResult> cancelBatchAsync(
BatchId batchId, FutureCallback<MtBatchSmsResult> callback) {
public Future<MtBatchResult> cancelBatchAsync(
BatchId batchId, FutureCallback<MtBatchResult> callback) {
HttpDelete req = delete(batchEndpoint(batchId));

HttpAsyncRequestProducer producer = new BasicAsyncRequestProducer(endpointHost(), req);

HttpAsyncResponseConsumer<MtBatchSmsResult> consumer =
jsonAsyncConsumer(MtBatchSmsResult.class);
HttpAsyncResponseConsumer<MtBatchResult> consumer = jsonAsyncConsumer(MtBatchResult.class);

return httpClient().execute(producer, consumer, callbackWrapper().wrap(callback));
}
Expand Down Expand Up @@ -1080,7 +1166,8 @@ private Future<Page<RecipientDeliveryReport>> fetchDeliveryReports(
}

/**
* Create a delivery feedback for the batch with the given batch ID.
* Create a delivery feedback for the batch with the given batch ID. Feedback can only be provided
* if feedback_enabled was set when batch was submitted.
*
* <p>This method blocks until the request completes and its use is discouraged. Please consider
* using the asynchronous method {@link #createDeliveryFeedbackAsync(BatchId,
Expand All @@ -1101,7 +1188,8 @@ public Void createDeliveryFeedback(BatchId id, FeedbackDeliveryCreate feedbackDe
}

/**
* Create a delivery feedback for the batch with the given batch ID and recipients
* Create a delivery feedback for the batch with the given batch ID. Feedback can only be provided
* if feedback_enabled was set when batch was submitted.
*
* @param id identifier of the batch
* @param feedbackDeliveryCreate create delivery feedback input with recipients
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/sinch/xms/ErrorResponseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
* the XMS API has been broken, the error code and text indicates the specifics.
*
* <p>For information about specific errors please refer to the <a href=
* "https://www.clxcommunications.com/docs/sms/http-rest.html#http-errors">XMS API
* documentation</a>.
* "https://developers.sinch.com/docs/sms/api-reference/status-codes/">XMS API documentation</a>.
*/
public class ErrorResponseException extends ApiException {

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/sinch/xms/SinchSMSApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import com.sinch.xms.api.FeedbackDeliveryCreate;
import com.sinch.xms.api.GroupCreate;
import com.sinch.xms.api.GroupUpdate;
import com.sinch.xms.api.MediaBody;
import com.sinch.xms.api.MtBatchBinarySmsCreate;
import com.sinch.xms.api.MtBatchBinarySmsUpdate;
import com.sinch.xms.api.MtBatchMmsCreate;
import com.sinch.xms.api.MtBatchMmsUpdate;
import com.sinch.xms.api.MtBatchTextSmsCreate;
import com.sinch.xms.api.MtBatchTextSmsUpdate;
import com.sinch.xms.api.ParameterValues;
Expand Down Expand Up @@ -77,6 +80,26 @@ public static MtBatchBinarySmsUpdate.Builder batchBinarySmsUpdate() {
return MtBatchBinarySmsUpdate.builder();
}

/**
* Returns a freshly created batch MMS message builder.
*
* @return a builder of MMS batch messages
*/
@Nonnull
public static MtBatchMmsCreate.Builder batchMms() {
return MtBatchMmsCreate.builder();
}

/**
* Returns a freshly created builder for MMS message updates.
*
* @return a builder of MMS message updates
*/
@Nonnull
public static MtBatchMmsUpdate.Builder batchMmsUpdate() {
return MtBatchMmsUpdate.builder();
}

/**
* Returns a freshly created builder for delivery feedback.
*
Expand Down Expand Up @@ -186,4 +209,14 @@ public static BatchDeliveryReportParams.Builder batchDeliveryReportParams() {
public static DeliveryReportFilter.Builder deliveryReportFilter() {
return DeliveryReportFilter.builder();
}

/**
* Returns a freshly created builder of delivery report filters.
*
* @return a builder of delivery report filters
*/
@Nonnull
public static MediaBody.Builder mediaBody() {
return MediaBody.builder();
}
}
Loading