Search in sources :

Example 1 with EndpointUser

use of com.amazonaws.services.pinpoint.model.EndpointUser in project aws-doc-sdk-examples by awsdocs.

the class CreateEndpoint method createEndpointRequestData.

private static EndpointRequest createEndpointRequestData() {
    HashMap<String, List<String>> customAttributes = new HashMap<>();
    List<String> favoriteTeams = new ArrayList<>();
    favoriteTeams.add("Lakers");
    favoriteTeams.add("Warriors");
    customAttributes.put("team", favoriteTeams);
    EndpointDemographic demographic = new EndpointDemographic().withAppVersion("1.0").withMake("apple").withModel("iPhone").withModelVersion("7").withPlatform("ios").withPlatformVersion("10.1.1").withTimezone("America/Los_Angeles");
    EndpointLocation location = new EndpointLocation().withCity("Los Angeles").withCountry("US").withLatitude(34.0).withLongitude(-118.2).withPostalCode("90068").withRegion("CA");
    Map<String, Double> metrics = new HashMap<>();
    metrics.put("health", 100.00);
    metrics.put("luck", 75.00);
    EndpointUser user = new EndpointUser().withUserId(UUID.randomUUID().toString());
    // Quoted "Z" to indicate UTC, no timezone offset
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    String nowAsISO = df.format(new Date());
    EndpointRequest endpointRequest = new EndpointRequest().withAddress(UUID.randomUUID().toString()).withAttributes(customAttributes).withChannelType("APNS").withDemographic(demographic).withEffectiveDate(nowAsISO).withLocation(location).withMetrics(metrics).withOptOut("NONE").withRequestId(UUID.randomUUID().toString()).withUser(user);
    return endpointRequest;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EndpointRequest(com.amazonaws.services.pinpoint.model.EndpointRequest) UpdateEndpointRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointRequest) GetEndpointRequest(com.amazonaws.services.pinpoint.model.GetEndpointRequest) Date(java.util.Date) EndpointDemographic(com.amazonaws.services.pinpoint.model.EndpointDemographic) EndpointLocation(com.amazonaws.services.pinpoint.model.EndpointLocation) EndpointUser(com.amazonaws.services.pinpoint.model.EndpointUser) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with EndpointUser

use of com.amazonaws.services.pinpoint.model.EndpointUser 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());
}
Also used : EndpointUser(com.amazonaws.services.pinpoint.model.EndpointUser) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) UpdateEndpointRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointRequest) UpdateEndpointResult(com.amazonaws.services.pinpoint.model.UpdateEndpointResult) EndpointRequest(com.amazonaws.services.pinpoint.model.EndpointRequest) UpdateEndpointRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointRequest)

Example 3 with EndpointUser

use of com.amazonaws.services.pinpoint.model.EndpointUser in project aws-sdk-android by aws-amplify.

the class EventRecorder method buildEndpointPayload.

private void buildEndpointPayload(EndpointProfile endpointProfile, PublicEndpoint endpoint) {
    final EndpointDemographic demographic = new EndpointDemographic().withAppVersion(endpointProfile.getDemographic().getAppVersion()).withLocale(endpointProfile.getDemographic().getLocale().toString()).withTimezone(endpointProfile.getDemographic().getTimezone()).withMake(endpointProfile.getDemographic().getMake()).withModel(endpointProfile.getDemographic().getModel()).withPlatform(endpointProfile.getDemographic().getPlatform()).withPlatformVersion(endpointProfile.getDemographic().getPlatformVersion());
    final EndpointLocation location = new EndpointLocation().withLatitude(endpointProfile.getLocation().getLatitude()).withLongitude(endpointProfile.getLocation().getLongitude()).withPostalCode(endpointProfile.getLocation().getPostalCode()).withCity(endpointProfile.getLocation().getCity()).withRegion(endpointProfile.getLocation().getRegion()).withCountry(endpointProfile.getLocation().getCountry());
    final EndpointUser user;
    if (endpointProfile.getUser().getUserId() == null) {
        user = null;
    } else {
        user = new EndpointUser().withUserId(endpointProfile.getUser().getUserId()).withUserAttributes(endpointProfile.getUser().getUserAttributes());
    }
    endpoint.withChannelType(endpointProfile.getChannelType()).withAddress(endpointProfile.getAddress()).withLocation(location).withDemographic(demographic).withEffectiveDate(DateUtils.formatISO8601Date(new Date(endpointProfile.getEffectiveDate()))).withOptOut(endpointProfile.getOptOut()).withAttributes(endpointProfile.getAllAttributes()).withMetrics(endpointProfile.getAllMetrics()).withUser(user);
}
Also used : EndpointDemographic(com.amazonaws.services.pinpoint.model.EndpointDemographic) EndpointLocation(com.amazonaws.services.pinpoint.model.EndpointLocation) EndpointUser(com.amazonaws.services.pinpoint.model.EndpointUser) Date(java.util.Date)

Example 4 with EndpointUser

use of com.amazonaws.services.pinpoint.model.EndpointUser 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());
}
Also used : UpdateEndpointsBatchRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointsBatchRequest) UpdateEndpointsBatchResult(com.amazonaws.services.pinpoint.model.UpdateEndpointsBatchResult) EndpointBatchRequest(com.amazonaws.services.pinpoint.model.EndpointBatchRequest) EndpointUser(com.amazonaws.services.pinpoint.model.EndpointUser) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) EndpointBatchItem(com.amazonaws.services.pinpoint.model.EndpointBatchItem)

Example 5 with EndpointUser

use of com.amazonaws.services.pinpoint.model.EndpointUser in project aws-sdk-android by aws-amplify.

the class TargetingClient method executeUpdate.

@SuppressWarnings("checkstyle:hiddenfield")
private void executeUpdate(EndpointProfile endpointProfile) {
    if (endpointProfile == null) {
        log.error("EndpointProfile is null, failed to update profile.");
        return;
    }
    final EndpointDemographic demographic = new EndpointDemographic().withAppVersion(endpointProfile.getDemographic().getAppVersion()).withLocale(endpointProfile.getDemographic().getLocale().toString()).withTimezone(endpointProfile.getDemographic().getTimezone()).withMake(endpointProfile.getDemographic().getMake()).withModel(endpointProfile.getDemographic().getModel()).withPlatform(endpointProfile.getDemographic().getPlatform()).withPlatformVersion(endpointProfile.getDemographic().getPlatformVersion());
    final EndpointLocation location = new EndpointLocation().withLatitude(endpointProfile.getLocation().getLatitude()).withLongitude(endpointProfile.getLocation().getLongitude()).withPostalCode(endpointProfile.getLocation().getPostalCode()).withCity(endpointProfile.getLocation().getCity()).withRegion(endpointProfile.getLocation().getRegion()).withCountry(endpointProfile.getLocation().getCountry());
    final EndpointUser user;
    if (endpointProfile.getUser().getUserId() == null) {
        user = null;
    } else {
        user = new EndpointUser().withUserId(endpointProfile.getUser().getUserId()).withUserAttributes(endpointProfile.getUser().getUserAttributes());
    }
    final EndpointRequest endpointRequest = new EndpointRequest().withChannelType(endpointProfile.getChannelType()).withAddress(endpointProfile.getAddress()).withLocation(location).withDemographic(demographic).withEffectiveDate(DateUtils.formatISO8601Date(new Date(endpointProfile.getEffectiveDate()))).withOptOut(endpointProfile.getOptOut()).withAttributes(endpointProfile.getAllAttributes()).withMetrics(endpointProfile.getAllMetrics()).withUser(user);
    final UpdateEndpointRequest updateEndpointRequest = new UpdateEndpointRequest().withApplicationId(endpointProfile.getApplicationId()).withEndpointId(endpointProfile.getEndpointId()).withEndpointRequest(endpointRequest);
    updateEndpointRequest.getRequestClientOptions().appendUserAgent(USER_AGENT);
    endpointRunnableQueue.execute(new Runnable() {

        @Override
        public void run() {
            try {
                log.info("Updating EndpointProfile.");
                context.getPinpointServiceClient().updateEndpoint(updateEndpointRequest);
                log.info("EndpointProfile updated successfully.");
            } catch (final AmazonServiceException e) {
                log.error("AmazonServiceException occurred during endpoint update:", e);
            } catch (final AmazonClientException e) {
                log.info("AmazonClientException occurred during endpoint update:", e);
            }
        }
    });
}
Also used : EndpointDemographic(com.amazonaws.services.pinpoint.model.EndpointDemographic) EndpointLocation(com.amazonaws.services.pinpoint.model.EndpointLocation) EndpointUser(com.amazonaws.services.pinpoint.model.EndpointUser) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) UpdateEndpointRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointRequest) EndpointRequest(com.amazonaws.services.pinpoint.model.EndpointRequest) UpdateEndpointRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointRequest) Date(java.util.Date)

Aggregations

EndpointUser (com.amazonaws.services.pinpoint.model.EndpointUser)5 EndpointDemographic (com.amazonaws.services.pinpoint.model.EndpointDemographic)3 EndpointLocation (com.amazonaws.services.pinpoint.model.EndpointLocation)3 EndpointRequest (com.amazonaws.services.pinpoint.model.EndpointRequest)3 UpdateEndpointRequest (com.amazonaws.services.pinpoint.model.UpdateEndpointRequest)3 Date (java.util.Date)3 AmazonPinpoint (com.amazonaws.services.pinpoint.AmazonPinpoint)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 EndpointBatchItem (com.amazonaws.services.pinpoint.model.EndpointBatchItem)1 EndpointBatchRequest (com.amazonaws.services.pinpoint.model.EndpointBatchRequest)1 GetEndpointRequest (com.amazonaws.services.pinpoint.model.GetEndpointRequest)1 UpdateEndpointResult (com.amazonaws.services.pinpoint.model.UpdateEndpointResult)1 UpdateEndpointsBatchRequest (com.amazonaws.services.pinpoint.model.UpdateEndpointsBatchRequest)1 UpdateEndpointsBatchResult (com.amazonaws.services.pinpoint.model.UpdateEndpointsBatchResult)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1