use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class SendMessage method main.
public static void main(String[] args) throws IOException {
try {
Map<String, AddressConfiguration> addressMap = new HashMap<String, AddressConfiguration>();
addressMap.put(destinationNumber, new AddressConfiguration().withChannelType(ChannelType.SMS));
AmazonPinpoint client = AmazonPinpointClientBuilder.standard().withRegion(region).build();
SendMessagesRequest request = new SendMessagesRequest().withApplicationId(appId).withMessageRequest(new MessageRequest().withAddresses(addressMap).withMessageConfiguration(new DirectMessageConfiguration().withSMSMessage(new SMSMessage().withBody(message).withMessageType(messageType).withOriginationNumber(originationNumber).withSenderId(senderId).withKeyword(registeredKeyword))));
System.out.println("Sending message...");
client.sendMessages(request);
System.out.println("Message sent!");
} catch (Exception ex) {
System.out.println("The message wasn't sent. Error message: " + ex.getMessage());
}
}
use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class ImportEndpoints method importToPinpoint.
private static void importToPinpoint(String endpointsFileName, String s3BucketName, String iamImportRoleArn, String applicationId) {
// The S3 URL that Amazon Pinpoint requires to find the endpoints file.
String s3Url = "s3://" + s3BucketName + "/imports/" + endpointsFileName;
// Defines the import job that Amazon Pinpoint runs.
ImportJobRequest importJobRequest = new ImportJobRequest().withS3Url(s3Url).withRegisterEndpoints(true).withRoleArn(iamImportRoleArn).withFormat(Format.JSON);
CreateImportJobRequest createImportJobRequest = new CreateImportJobRequest().withApplicationId(applicationId).withImportJobRequest(importJobRequest);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
System.out.format("Importing endpoints in %s to Amazon Pinpoint application %s . . .\n", endpointsFileName, applicationId);
try {
// Runs the import job with Amazon Pinpoint.
CreateImportJobResult importResult = pinpointClient.createImportJob(createImportJobRequest);
String jobId = importResult.getImportJobResponse().getId();
GetImportJobResult getImportJobResult = null;
String jobStatus = null;
// Checks the job status until the job completes or fails.
do {
getImportJobResult = pinpointClient.getImportJob(new GetImportJobRequest().withJobId(jobId).withApplicationId(applicationId));
jobStatus = getImportJobResult.getImportJobResponse().getJobStatus();
System.out.format("Import job %s . . .\n", jobStatus.toLowerCase());
TimeUnit.SECONDS.sleep(3);
} while (!jobStatus.equals("COMPLETED") && !jobStatus.equals("FAILED"));
if (jobStatus.equals("COMPLETED")) {
System.out.println("Finished importing endpoints.");
} else {
System.err.println("Failed to import endpoints.");
System.exit(1);
}
// Checks for entries that failed to import.
// getFailures provides up to 100 of the first failed entries for the job, if any exist.
List<String> failedEndpoints = getImportJobResult.getImportJobResponse().getFailures();
if (failedEndpoints != null) {
System.out.println("Failed to import the following entries:");
for (String failedEndpoint : failedEndpoints) {
System.out.println(failedEndpoint);
}
}
} catch (AmazonServiceException | InterruptedException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class DeleteEndpoints method main.
public static void main(String[] args) {
final String USAGE = "\n" + "DeleteEndpoints - Removes one or more endpoints from an " + "Amazon Pinpoint application.\n\n" + "Usage: DeleteEndpoints <applicationId> <endpointId1> [endpointId2 ...]\n";
if (args.length < 2) {
System.out.println(USAGE);
System.exit(1);
}
String applicationId = args[0];
String[] endpointIds = Arrays.copyOfRange(args, 1, args.length);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
try {
// Deletes each of the specified endpoints with the Amazon Pinpoint client.
for (String endpointId : endpointIds) {
DeleteEndpointResult result = pinpointClient.deleteEndpoint(new DeleteEndpointRequest().withEndpointId(endpointId).withApplicationId(applicationId));
System.out.format("Deleted endpoint %s.\n", result.getEndpointResponse().getId());
}
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class ImportSegment method importSegment.
private static void importSegment(String endpointsFileName, String s3BucketName, String iamImportRoleArn, String segmentName, String applicationId) {
// The S3 URL that Amazon Pinpoint requires to find the endpoints file.
String s3Url = "s3://" + s3BucketName + "/imports/" + endpointsFileName;
// Defines the import job that Amazon Pinpoint runs.
ImportJobRequest importJobRequest = new ImportJobRequest().withS3Url(s3Url).withFormat(Format.JSON).withRoleArn(iamImportRoleArn).withRegisterEndpoints(true).withDefineSegment(true).withSegmentName(segmentName);
CreateImportJobRequest createImportJobRequest = new CreateImportJobRequest().withApplicationId(applicationId).withImportJobRequest(importJobRequest);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
System.out.format("Creating segment %s with the endpoints in %s . . .\n", segmentName, endpointsFileName);
try {
// Runs the import job with Amazon Pinpoint.
CreateImportJobResult importResult = pinpointClient.createImportJob(createImportJobRequest);
String jobId = importResult.getImportJobResponse().getId();
// Checks the job status until the job completes or fails.
GetImportJobResult getImportJobResult = null;
String jobStatus = null;
do {
getImportJobResult = pinpointClient.getImportJob(new GetImportJobRequest().withJobId(jobId).withApplicationId(applicationId));
jobStatus = getImportJobResult.getImportJobResponse().getJobStatus();
System.out.format("Import job %s . . .\n", jobStatus.toLowerCase());
if (jobStatus.equals("FAILED")) {
System.err.println("Failed to import segment.");
System.exit(1);
}
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
System.err.println(e.getMessage());
System.exit(1);
}
} while (!jobStatus.equals("COMPLETED"));
System.out.println("Finished importing segment.");
// Checks for entries that failed to import.
List<String> failedEndpoints = getImportJobResult.getImportJobResponse().getFailures();
if (failedEndpoints != null) {
System.out.println("Failed to import the following entries:");
for (String failedEndpoint : failedEndpoints) {
System.out.println(failedEndpoint);
}
}
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class LookUpEndpoint method main.
public static void main(String[] args) {
final String USAGE = "\n" + "LookUpEndpoint - Prints the definition of the endpoint that has the specified ID." + "Usage: LookUpEndpoint <applicationId> <endpointId>\n\n" + "Where:\n" + " applicationId - The ID of the Amazon Pinpoint application that has the " + "endpoint." + " endpointId - The ID of the endpoint ";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String applicationId = args[0];
String endpointId = args[1];
// Specifies the endpoint that the Amazon Pinpoint client looks up.
GetEndpointRequest request = new GetEndpointRequest().withEndpointId(endpointId).withApplicationId(applicationId);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
// Uses the Amazon Pinpoint client to get the endpoint definition.
GetEndpointResult result = pinpointClient.getEndpoint(request);
EndpointResponse endpoint = result.getEndpointResponse();
// Uses the Google Gson library to pretty print the endpoint JSON.
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).setPrettyPrinting().create();
String endpointJson = gson.toJson(endpoint);
System.out.println(endpointJson);
}
Aggregations