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;
}
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);
}
}
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");
}
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);
}
}
Aggregations