Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions snippets/sms/batches/Send.java

This file was deleted.

30 changes: 30 additions & 0 deletions snippets/src/main/java/sms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SMS snippets
Sinch Java SDK Code Snippets Repository for SMS APIs

See main [README.md](../../../../../README.md) for how to execute snippets

- Batches
- [sms/batches/Send](./batches/Send.java)
- [sms/batches/List](./batches/List.java)
- [sms/batches/DryRun](./batches/DryRun.java)
- [sms/batches/Get](./batches/Get.java)
- [sms/batches/Update](./batches/Update.java)
- [sms/batches/Replace](./batches/Replace.java)
- [sms/batches/Cancel](./batches/Cancel.java)
- [sms/batches/SendDeliveryFeedback](./batches/SendDeliveryFeedback.java)
- Delivery reports
- [sms/deliveryReports/Get](./deliveryReports/Get.java)
- [sms/deliveryReports/GetForNumber](./deliveryReports/GetForNumber.java)
- [sms/deliveryReports/List](./deliveryReports/List.java)
- Inbounds
- [sms/inbounds/List](./inbounds/List.java)
- [sms/inbounds/Get](./inbounds/Get.java)
- Groups
- [sms/groups/List](./groups/List.java)
- [sms/groups/Create](./groups/Create.java)
- [sms/groups/Get](./groups/Get.java)
- [sms/groups/Update](./groups/Update.java)
- [sms/groups/Replace](./groups/Replace.java)
- [sms/groups/Delete](./groups/Delete.java)
- [sms/groups/ListMembers](./groups/ListMembers.java)

46 changes: 46 additions & 0 deletions snippets/src/main/java/sms/batches/Cancel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Sinch Java Snippet
*
* <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets
*
* <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details
*/
package sms.batches;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse;
import com.sinch.sdk.models.Configuration;
import java.util.logging.Logger;
import utils.Settings;

public class Cancel {

private static final Logger LOGGER = Logger.getLogger(Cancel.class.getName());

public static void main(String[] args) {

String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");

String batchId = "A_BATCH_ID";

Configuration configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.build();

SinchClient client = new SinchClient(configuration);

BatchesService batchesService = client.sms().v1().batches();

LOGGER.info(String.format("Cancelling batch with ID '%s'", batchId));

BatchResponse response = batchesService.cancel(batchId);

LOGGER.info("Response: " + response);
}
}
55 changes: 55 additions & 0 deletions snippets/src/main/java/sms/batches/DryRun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Sinch Java Snippet
*
* <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets
*
* <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details
*/
package sms.batches;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse;
import com.sinch.sdk.models.Configuration;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import utils.Settings;

public class DryRun {

private static final Logger LOGGER = Logger.getLogger(DryRun.class.getName());

public static void main(String[] args) {

String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");

String phoneNumber = Settings.getPhoneNumber().orElse("MY_SINCH_PHONE_NUMBER");

List<String> recipients = Arrays.asList("A_RECIPIENT_PHONE_NUMBER");
String body = "A body text here";

Configuration configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.build();

SinchClient client = new SinchClient(configuration);

BatchesService batchesService = client.sms().v1().batches();

LOGGER.info("DryRun Request");

TextRequest request =
TextRequest.builder().setFrom(phoneNumber).setTo(recipients).setBody(body).build();

DryRunResponse response = batchesService.dryRun(request);

LOGGER.info("Response: " + response);
}
}
46 changes: 46 additions & 0 deletions snippets/src/main/java/sms/batches/Get.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Sinch Java Snippet
*
* <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets
*
* <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details
*/
package sms.batches;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse;
import com.sinch.sdk.models.Configuration;
import java.util.logging.Logger;
import utils.Settings;

public class Get {

private static final Logger LOGGER = Logger.getLogger(Get.class.getName());

public static void main(String[] args) {

String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");

String batchId = "A_BATCH_ID";

Configuration configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.build();

SinchClient client = new SinchClient(configuration);

BatchesService batchesService = client.sms().v1().batches();

LOGGER.info(String.format("Get information for batch with ID '%s'", batchId));

BatchResponse response = batchesService.get(batchId);

LOGGER.info("Response: " + response);
}
}
42 changes: 42 additions & 0 deletions snippets/src/main/java/sms/batches/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Sinch Java Snippet
*
* <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets
*
* <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details
*/
package sms.batches;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.models.Configuration;
import java.util.logging.Logger;
import utils.Settings;

public class List {
private static final Logger LOGGER = Logger.getLogger(List.class.getName());

public static void main(String[] args) {

String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");

Configuration configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.build();

SinchClient client = new SinchClient(configuration);

BatchesService batchesService = client.sms().v1().batches();

LOGGER.info("List batches");

LOGGER.info("Response:");

batchesService.list().iterator().forEachRemaining(f -> LOGGER.info(f.toString()));
}
}
53 changes: 53 additions & 0 deletions snippets/src/main/java/sms/batches/Replace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Sinch Java Snippet
*
* <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets
*
* <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details
*/
package sms.batches;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse;
import com.sinch.sdk.models.Configuration;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import utils.Settings;

public class Replace {

private static final Logger LOGGER = Logger.getLogger(Replace.class.getName());

public static void main(String[] args) {

String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");

String batchId = "A_BATCH_ID";
List<String> recipients = Arrays.asList("A_NEW_RECIPIENT_PHONE_NUMBER");
String body = "A message body updated";

Configuration configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.build();

SinchClient client = new SinchClient(configuration);

BatchesService batchesService = client.sms().v1().batches();

LOGGER.info(String.format("Replacing batch with ID '%s'", batchId));

TextRequest request = TextRequest.builder().setTo(recipients).setBody(body).build();

BatchResponse response = batchesService.replace(batchId, request);

LOGGER.info("Response: " + response);
}
}
55 changes: 55 additions & 0 deletions snippets/src/main/java/sms/batches/Send.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Sinch Java Snippet
*
* <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets
*
* <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details
*/
package sms.batches;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse;
import com.sinch.sdk.models.Configuration;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import utils.Settings;

public class Send {

private static final Logger LOGGER = Logger.getLogger(Send.class.getName());

public static void main(String[] args) {

String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");

String phoneNumber = Settings.getPhoneNumber().orElse("MY_SINCH_PHONE_NUMBER");

List<String> recipients = Arrays.asList("A_RECIPIENT_PHONE_NUMBER");
String body = "This is a test SMS message using the Sinch Java SDK.";

Configuration configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.build();

SinchClient client = new SinchClient(configuration);

BatchesService batchesService = client.sms().v1().batches();

LOGGER.info(String.format("Sending SMS Text to recipients '%s'", recipients));

TextRequest request =
TextRequest.builder().setTo(recipients).setBody(body).setFrom(phoneNumber).build();

BatchResponse response = batchesService.send(request);

LOGGER.info("Response: " + response);
}
}
Loading
Loading