use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class AddExampleUser method main.
public static void main(String[] args) {
final String USAGE = "\n" + "AddExampleUser - Adds a user definition to the specified Amazon Pinpoint endpoint." + "Usage: AddExampleUser <endpointId> <applicationId>" + "Where:\n" + " endpointId - The ID of the endpoint to add the user to." + " applicationId - The ID of the Amazon Pinpoint application that contains the endpoint.";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String endpointId = args[0];
String applicationId = args[1];
// Creates a new user definition.
EndpointUser wangXiulan = new EndpointUser().withUserId("example_user");
// Assigns custom user attributes.
wangXiulan.addUserAttributesEntry("name", Arrays.asList("Wang", "Xiulan"));
wangXiulan.addUserAttributesEntry("gender", Collections.singletonList("female"));
wangXiulan.addUserAttributesEntry("age", Collections.singletonList("39"));
// Adds the user definition to the EndpointRequest that is passed to the Amazon Pinpoint client.
EndpointRequest wangXiulansIphone = new EndpointRequest().withUser(wangXiulan);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
// Updates the specified endpoint with Amazon Pinpoint.
UpdateEndpointResult result = pinpointClient.updateEndpoint(new UpdateEndpointRequest().withEndpointRequest(wangXiulansIphone).withApplicationId(applicationId).withEndpointId(endpointId));
System.out.format("Update endpoint result: %s\n", result.getMessageBody().getMessage());
}
use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class SendMessages method main.
public static void main(String[] args) throws IOException {
try {
Map<String, AddressConfiguration> addressMap = new HashMap<String, AddressConfiguration>();
addressMap.put(toAddress, new AddressConfiguration().withChannelType(ChannelType.EMAIL));
AmazonPinpoint client = AmazonPinpointClientBuilder.standard().withRegion(region).build();
SendMessagesRequest request = (new SendMessagesRequest().withApplicationId(appId).withMessageRequest(new MessageRequest().withAddresses(addressMap).withMessageConfiguration(new DirectMessageConfiguration().withEmailMessage(new EmailMessage().withSimpleEmail(new SimpleEmail().withHtmlPart(new SimpleEmailPart().withCharset(charset).withData(htmlBody)).withTextPart(new SimpleEmailPart().withCharset(charset).withData(textBody)).withSubject(new SimpleEmailPart().withCharset(charset).withData(subject)))))));
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 CreateEndpoint method main.
public static void main(String[] args) {
final String USAGE = "\n" + "CreateEndpoint - create an endpoint for an application in pinpoint\n\n" + "Usage: CreateEndpoint <appId>\n\n" + "Where:\n" + " appId - the ID of the application to create an endpoint for.\n\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String appId = args[0];
AmazonPinpoint pinpoint = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
EndpointResponse response = createEndpoint(pinpoint, appId);
System.out.println(response.getAddress());
System.out.println(response.getChannelType());
System.out.println(response.getApplicationId());
System.out.println(response.getEndpointStatus());
System.out.println(response.getRequestId());
System.out.println(response.getUser());
}
use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class AddExampleEndpoints method main.
public static void main(String[] args) {
final String USAGE = "\n" + "AddExampleEndpoints - Adds example endpoints to an Amazon Pinpoint application." + "Usage: AddExampleEndpoints <applicationId>" + "Where:\n" + " applicationId - The ID of the Amazon Pinpoint application to add the example endpoints to.";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String applicationId = args[0];
// Initializes an endpoint definition with channel type, address, and ID.
EndpointBatchItem richardRoesEmailEndpoint = new EndpointBatchItem().withChannelType(ChannelType.EMAIL).withAddress("richard_roe@example.com").withId("example_endpoint_1");
// Adds custom attributes to the endpoint.
richardRoesEmailEndpoint.addAttributesEntry("interests", Arrays.asList("music", "books"));
// Adds custom metrics to the endpoint.
richardRoesEmailEndpoint.addMetricsEntry("music_interest_level", 3.0);
richardRoesEmailEndpoint.addMetricsEntry("books_interest_level", 7.0);
// Initializes a user definition with a user ID.
EndpointUser richardRoe = new EndpointUser().withUserId("example_user_1");
// Adds custom user attributes.
richardRoe.addUserAttributesEntry("name", Arrays.asList("Richard", "Roe"));
// Adds the user definition to the endpoint.
richardRoesEmailEndpoint.setUser(richardRoe);
// Initializes an endpoint definition with channel type, address, and ID.
EndpointBatchItem maryMajorsSmsEndpoint = new EndpointBatchItem().withChannelType(ChannelType.SMS).withAddress("+16145550100").withId("example_endpoint_2");
// Adds custom attributes to the endpoint.
maryMajorsSmsEndpoint.addAttributesEntry("interests", Arrays.asList("cooking", "politics", "finance"));
// Adds custom metrics to the endpoint.
maryMajorsSmsEndpoint.addMetricsEntry("cooking_interest_level", 5.0);
maryMajorsSmsEndpoint.addMetricsEntry("politics_interest_level", 8.0);
maryMajorsSmsEndpoint.addMetricsEntry("finance_interest_level", 4.0);
// Initializes a user definition with a user ID.
EndpointUser maryMajor = new EndpointUser().withUserId("example_user_2");
// Adds custom user attributes.
maryMajor.addUserAttributesEntry("name", Arrays.asList("Mary", "Major"));
// Adds the user definition to the endpoint.
maryMajorsSmsEndpoint.setUser(maryMajor);
// Adds multiple endpoint definitions to a single request object.
EndpointBatchRequest endpointList = new EndpointBatchRequest().withItem(richardRoesEmailEndpoint).withItem(maryMajorsSmsEndpoint);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
// Updates or creates the endpoints with Amazon Pinpoint.
UpdateEndpointsBatchResult result = pinpointClient.updateEndpointsBatch(new UpdateEndpointsBatchRequest().withApplicationId(applicationId).withEndpointBatchRequest(endpointList));
System.out.format("Update endpoints batch result: %s\n", result.getMessageBody().getMessage());
}
use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class AddExampleEndpoint method main.
public static void main(String[] args) {
final String USAGE = "\n" + "AddExampleEndpoint - Adds an example endpoint to an Amazon Pinpoint application." + "Usage: AddExampleEndpoint <applicationId>" + "Where:\n" + " applicationId - The ID of the Amazon Pinpoint application to add the example " + "endpoint to.";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String applicationId = args[0];
// The device token assigned to the user's device by Apple Push Notification service (APNs).
String deviceToken = "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f";
// Initializes an endpoint definition with channel type and address.
EndpointRequest wangXiulansIphoneEndpoint = new EndpointRequest().withChannelType(ChannelType.APNS).withAddress(deviceToken);
// Adds custom attributes to the endpoint.
wangXiulansIphoneEndpoint.addAttributesEntry("interests", Arrays.asList("technology", "music", "travel"));
// Adds custom metrics to the endpoint.
wangXiulansIphoneEndpoint.addMetricsEntry("technology_interest_level", 9.0);
wangXiulansIphoneEndpoint.addMetricsEntry("music_interest_level", 6.0);
wangXiulansIphoneEndpoint.addMetricsEntry("travel_interest_level", 4.0);
// Adds standard demographic attributes.
wangXiulansIphoneEndpoint.setDemographic(new EndpointDemographic().withAppVersion("1.0").withMake("apple").withModel("iPhone").withModelVersion("8").withPlatform("ios").withPlatformVersion("11.3.1").withTimezone("America/Los_Angeles"));
// Adds standard location attributes.
wangXiulansIphoneEndpoint.setLocation(new EndpointLocation().withCountry("US").withCity("Seattle").withPostalCode("98121").withLatitude(47.61).withLongitude(-122.33));
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
// Updates or creates the endpoint with Amazon Pinpoint.
UpdateEndpointResult result = pinpointClient.updateEndpoint(new UpdateEndpointRequest().withApplicationId(applicationId).withEndpointId("example_endpoint").withEndpointRequest(wangXiulansIphoneEndpoint));
System.out.format("Update endpoint result: %s\n", result.getMessageBody().getMessage());
}
Aggregations