Search in sources :

Example 16 with PinpointException

use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.

the class CreateSegment method createSegment.

// snippet-start:[pinpoint.java2.createsegment.main]
public static SegmentResponse createSegment(PinpointClient client, String appId) {
    try {
        Map<String, AttributeDimension> segmentAttributes = new HashMap<>();
        segmentAttributes.put("Team", AttributeDimension.builder().attributeType(AttributeType.INCLUSIVE).values("Lakers").build());
        RecencyDimension recencyDimension = RecencyDimension.builder().duration("DAY_30").recencyType("ACTIVE").build();
        SegmentBehaviors segmentBehaviors = SegmentBehaviors.builder().recency(recencyDimension).build();
        SegmentDemographics segmentDemographics = SegmentDemographics.builder().build();
        SegmentLocation segmentLocation = SegmentLocation.builder().build();
        SegmentDimensions dimensions = SegmentDimensions.builder().attributes(segmentAttributes).behavior(segmentBehaviors).demographic(segmentDemographics).location(segmentLocation).build();
        WriteSegmentRequest writeSegmentRequest = WriteSegmentRequest.builder().name("MySegment").dimensions(dimensions).build();
        CreateSegmentRequest createSegmentRequest = CreateSegmentRequest.builder().applicationId(appId).writeSegmentRequest(writeSegmentRequest).build();
        CreateSegmentResponse createSegmentResult = client.createSegment(createSegmentRequest);
        System.out.println("Segment ID: " + createSegmentResult.segmentResponse().id());
        System.out.println("Done");
        return createSegmentResult.segmentResponse();
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : SegmentDimensions(software.amazon.awssdk.services.pinpoint.model.SegmentDimensions) CreateSegmentResponse(software.amazon.awssdk.services.pinpoint.model.CreateSegmentResponse) AttributeDimension(software.amazon.awssdk.services.pinpoint.model.AttributeDimension) WriteSegmentRequest(software.amazon.awssdk.services.pinpoint.model.WriteSegmentRequest) HashMap(java.util.HashMap) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) CreateSegmentRequest(software.amazon.awssdk.services.pinpoint.model.CreateSegmentRequest) SegmentBehaviors(software.amazon.awssdk.services.pinpoint.model.SegmentBehaviors) SegmentDemographics(software.amazon.awssdk.services.pinpoint.model.SegmentDemographics) SegmentLocation(software.amazon.awssdk.services.pinpoint.model.SegmentLocation) RecencyDimension(software.amazon.awssdk.services.pinpoint.model.RecencyDimension)

Example 17 with PinpointException

use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.

the class ListEndpointIds method listAllEndpoints.

// snippet-start:[pinpoint.java2.list_endpoints.main]
public static void listAllEndpoints(PinpointClient pinpoint, String applicationId, String userId) {
    try {
        GetUserEndpointsRequest endpointsRequest = GetUserEndpointsRequest.builder().userId(userId).applicationId(applicationId).build();
        GetUserEndpointsResponse response = pinpoint.getUserEndpoints(endpointsRequest);
        List<EndpointResponse> endpoints = response.endpointsResponse().item();
        // Display the results
        for (EndpointResponse endpoint : endpoints) {
            System.out.println("The channel type is: " + endpoint.channelType());
            System.out.println("The address is  " + endpoint.address());
        }
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : EndpointResponse(software.amazon.awssdk.services.pinpoint.model.EndpointResponse) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) GetUserEndpointsRequest(software.amazon.awssdk.services.pinpoint.model.GetUserEndpointsRequest) GetUserEndpointsResponse(software.amazon.awssdk.services.pinpoint.model.GetUserEndpointsResponse)

Example 18 with PinpointException

use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.

the class LookUpEndpoint method lookupPinpointEndpoint.

// snippet-start:[pinpoint.java2.lookup.main]
public static void lookupPinpointEndpoint(PinpointClient pinpoint, String appId, String endpoint) {
    try {
        GetEndpointRequest appRequest = GetEndpointRequest.builder().applicationId(appId).endpointId(endpoint).build();
        GetEndpointResponse result = pinpoint.getEndpoint(appRequest);
        EndpointResponse endResponse = result.endpointResponse();
        // 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(endResponse);
        System.out.println(endpointJson);
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    System.out.println("Done");
}
Also used : GetEndpointResponse(software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse) EndpointResponse(software.amazon.awssdk.services.pinpoint.model.EndpointResponse) GetEndpointResponse(software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse) GsonBuilder(com.google.gson.GsonBuilder) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) Gson(com.google.gson.Gson) GetEndpointRequest(software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest)

Example 19 with PinpointException

use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.

the class ExportEndpoints method printExportJobStatus.

private static void printExportJobStatus(PinpointClient pinpointClient, String applicationId, String jobId) {
    GetExportJobResponse getExportJobResult;
    String status = "";
    try {
        // Checks the job status until the job completes or fails
        GetExportJobRequest exportJobRequest = GetExportJobRequest.builder().jobId(jobId).applicationId(applicationId).build();
        do {
            getExportJobResult = pinpointClient.getExportJob(exportJobRequest);
            status = getExportJobResult.exportJobResponse().jobStatus().toString().toUpperCase();
            System.out.format("Export job %s . . .\n", status);
            TimeUnit.SECONDS.sleep(3);
        } while (!status.equals("COMPLETED") && !status.equals("FAILED"));
        if (status.equals("COMPLETED")) {
            System.out.println("Finished exporting endpoints.");
        } else {
            System.err.println("Failed to export endpoints.");
            System.exit(1);
        }
    } catch (PinpointException | InterruptedException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetExportJobResponse(software.amazon.awssdk.services.pinpoint.model.GetExportJobResponse) GetExportJobRequest(software.amazon.awssdk.services.pinpoint.model.GetExportJobRequest) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException)

Aggregations

PinpointException (software.amazon.awssdk.services.pinpoint.model.PinpointException)19 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 EndpointRequest (software.amazon.awssdk.services.pinpoint.model.EndpointRequest)3 EndpointUser (software.amazon.awssdk.services.pinpoint.model.EndpointUser)3 GetEndpointRequest (software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest)3 UpdateEndpointRequest (software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 AddressConfiguration (software.amazon.awssdk.services.pinpoint.model.AddressConfiguration)2 DirectMessageConfiguration (software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration)2 EndpointResponse (software.amazon.awssdk.services.pinpoint.model.EndpointResponse)2 GetEndpointResponse (software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse)2 GetExportJobRequest (software.amazon.awssdk.services.pinpoint.model.GetExportJobRequest)2 MessageRequest (software.amazon.awssdk.services.pinpoint.model.MessageRequest)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DateFormat (java.text.DateFormat)1 List (java.util.List)1