Search in sources :

Example 1 with AmazonPinpoint

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());
    }
}
Also used : MessageRequest(com.amazonaws.services.pinpoint.model.MessageRequest) SendMessagesRequest(com.amazonaws.services.pinpoint.model.SendMessagesRequest) SMSMessage(com.amazonaws.services.pinpoint.model.SMSMessage) HashMap(java.util.HashMap) DirectMessageConfiguration(com.amazonaws.services.pinpoint.model.DirectMessageConfiguration) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) AddressConfiguration(com.amazonaws.services.pinpoint.model.AddressConfiguration) IOException(java.io.IOException)

Example 2 with AmazonPinpoint

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);
    }
}
Also used : GetImportJobResult(com.amazonaws.services.pinpoint.model.GetImportJobResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) CreateImportJobRequest(com.amazonaws.services.pinpoint.model.CreateImportJobRequest) ImportJobRequest(com.amazonaws.services.pinpoint.model.ImportJobRequest) GetImportJobRequest(com.amazonaws.services.pinpoint.model.GetImportJobRequest) CreateImportJobRequest(com.amazonaws.services.pinpoint.model.CreateImportJobRequest) CreateImportJobResult(com.amazonaws.services.pinpoint.model.CreateImportJobResult) GetImportJobRequest(com.amazonaws.services.pinpoint.model.GetImportJobRequest)

Example 3 with AmazonPinpoint

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);
    }
}
Also used : DeleteEndpointRequest(com.amazonaws.services.pinpoint.model.DeleteEndpointRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) DeleteEndpointResult(com.amazonaws.services.pinpoint.model.DeleteEndpointResult)

Example 4 with AmazonPinpoint

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);
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint)

Example 5 with AmazonPinpoint

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);
}
Also used : EndpointResponse(com.amazonaws.services.pinpoint.model.EndpointResponse) GetEndpointResult(com.amazonaws.services.pinpoint.model.GetEndpointResult) GsonBuilder(com.google.gson.GsonBuilder) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) Gson(com.google.gson.Gson) GetEndpointRequest(com.amazonaws.services.pinpoint.model.GetEndpointRequest)

Aggregations

AmazonPinpoint (com.amazonaws.services.pinpoint.AmazonPinpoint)11 AmazonServiceException (com.amazonaws.AmazonServiceException)4 AddressConfiguration (com.amazonaws.services.pinpoint.model.AddressConfiguration)2 DirectMessageConfiguration (com.amazonaws.services.pinpoint.model.DirectMessageConfiguration)2 EndpointResponse (com.amazonaws.services.pinpoint.model.EndpointResponse)2 EndpointUser (com.amazonaws.services.pinpoint.model.EndpointUser)2 MessageRequest (com.amazonaws.services.pinpoint.model.MessageRequest)2 SendMessagesRequest (com.amazonaws.services.pinpoint.model.SendMessagesRequest)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CreateImportJobRequest (com.amazonaws.services.pinpoint.model.CreateImportJobRequest)1 CreateImportJobResult (com.amazonaws.services.pinpoint.model.CreateImportJobResult)1 DeleteEndpointRequest (com.amazonaws.services.pinpoint.model.DeleteEndpointRequest)1 DeleteEndpointResult (com.amazonaws.services.pinpoint.model.DeleteEndpointResult)1 EmailMessage (com.amazonaws.services.pinpoint.model.EmailMessage)1 EndpointBatchItem (com.amazonaws.services.pinpoint.model.EndpointBatchItem)1 EndpointBatchRequest (com.amazonaws.services.pinpoint.model.EndpointBatchRequest)1 EndpointRequest (com.amazonaws.services.pinpoint.model.EndpointRequest)1 GetEndpointRequest (com.amazonaws.services.pinpoint.model.GetEndpointRequest)1 GetEndpointResult (com.amazonaws.services.pinpoint.model.GetEndpointResult)1