Search in sources :

Example 1 with EndpointUser

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

the class AddExampleEndpoints method updateEndpointsViaBatch.

// snippet-start:[pinpoint.java2.update_batch.main]
public static void updateEndpointsViaBatch(PinpointClient pinpoint, String applicationId) {
    try {
        List<String> myList = new ArrayList<String>();
        myList.add("music");
        myList.add("books");
        Map myMap = new HashMap<String, List>();
        myMap.put("attributes", myList);
        List<String> myNames = new ArrayList<String>();
        myList.add("Richard");
        myList.add("Roe");
        Map myMap2 = new HashMap<String, List>();
        myMap2.put("name", myNames);
        EndpointUser richardRoe = EndpointUser.builder().userId("example_user_1").userAttributes(myMap2).build();
        // Create an EndpointBatchItem object for Richard Roe.
        EndpointBatchItem richardRoesEmailEndpoint = EndpointBatchItem.builder().channelType(ChannelType.EMAIL).address("richard_roe@example.com").id("example_endpoint_1").attributes(myMap).user(richardRoe).build();
        List<String> myListMary = new ArrayList<String>();
        myListMary.add("cooking");
        myListMary.add("politics");
        myListMary.add("finance");
        Map myMapMary = new HashMap<String, List>();
        myMapMary.put("interests", myListMary);
        List<String> myNameMary = new ArrayList<String>();
        myNameMary.add("Mary ");
        myNameMary.add("Major");
        Map maryName = new HashMap<String, List>();
        myMapMary.put("name", myNameMary);
        EndpointUser maryMajor = EndpointUser.builder().userId("example_user_2").userAttributes(maryName).build();
        // Create an EndpointBatchItem object for Mary Major.
        EndpointBatchItem maryMajorsSmsEndpoint = EndpointBatchItem.builder().channelType(ChannelType.SMS).address("+16145550100").id("example_endpoint_2").attributes(myMapMary).user(maryMajor).build();
        // Adds multiple endpoint definitions to a single request object.
        EndpointBatchRequest endpointList = EndpointBatchRequest.builder().item(richardRoesEmailEndpoint).item(maryMajorsSmsEndpoint).build();
        // Create the UpdateEndpointsBatchRequest.
        UpdateEndpointsBatchRequest batchRequest = UpdateEndpointsBatchRequest.builder().applicationId(applicationId).endpointBatchRequest(endpointList).build();
        // Updates the endpoints with Amazon Pinpoint.
        UpdateEndpointsBatchResponse result = pinpoint.updateEndpointsBatch(batchRequest);
        System.out.format("Update endpoints batch result: %s\n", result.messageBody().message());
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : UpdateEndpointsBatchRequest(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointsBatchRequest) HashMap(java.util.HashMap) EndpointBatchRequest(software.amazon.awssdk.services.pinpoint.model.EndpointBatchRequest) UpdateEndpointsBatchResponse(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointsBatchResponse) EndpointUser(software.amazon.awssdk.services.pinpoint.model.EndpointUser) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) ArrayList(java.util.ArrayList) EndpointBatchItem(software.amazon.awssdk.services.pinpoint.model.EndpointBatchItem) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with EndpointUser

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

the class UpdateEndpoint method createEndpointRequestData.

private static EndpointRequest createEndpointRequestData() {
    try {
        List<String> favoriteTeams = new ArrayList<>();
        favoriteTeams.add("Lakers");
        favoriteTeams.add("Warriors");
        HashMap<String, List<String>> customAttributes = new HashMap<>();
        customAttributes.put("team", favoriteTeams);
        EndpointDemographic demographic = EndpointDemographic.builder().appVersion("1.0").make("apple").model("iPhone").modelVersion("7").platform("ios").platformVersion("10.1.1").timezone("America/Los_Angeles").build();
        EndpointLocation location = EndpointLocation.builder().city("Los Angeles").country("US").latitude(34.0).longitude(-118.2).postalCode("90068").region("CA").build();
        Map<String, Double> metrics = new HashMap<>();
        metrics.put("health", 100.00);
        metrics.put("luck", 75.00);
        EndpointUser user = EndpointUser.builder().userId(UUID.randomUUID().toString()).build();
        // 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 = EndpointRequest.builder().address(UUID.randomUUID().toString()).attributes(customAttributes).channelType("APNS").demographic(demographic).effectiveDate(nowAsISO).location(location).metrics(metrics).optOut("NONE").requestId(UUID.randomUUID().toString()).user(user).build();
        return endpointRequest;
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : HashMap(java.util.HashMap) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) ArrayList(java.util.ArrayList) GetEndpointRequest(software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest) UpdateEndpointRequest(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest) EndpointRequest(software.amazon.awssdk.services.pinpoint.model.EndpointRequest) Date(java.util.Date) EndpointDemographic(software.amazon.awssdk.services.pinpoint.model.EndpointDemographic) EndpointLocation(software.amazon.awssdk.services.pinpoint.model.EndpointLocation) EndpointUser(software.amazon.awssdk.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 3 with EndpointUser

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

the class AddExampleUser method updatePinpointEndpoint.

// snippet-start:[pinpoint.java2.update_endpoint.main]
public static void updatePinpointEndpoint(PinpointClient pinpoint, String applicationId, String endPointId) {
    try {
        List<String> wangXiList = new ArrayList<String>();
        wangXiList.add("cooking");
        wangXiList.add("running");
        wangXiList.add("swimming");
        Map myMapWang = new HashMap<String, List>();
        myMapWang.put("interests", wangXiList);
        List<String> myNameWang = new ArrayList<String>();
        myNameWang.add("Wang ");
        myNameWang.add("Xiulan");
        Map wangName = new HashMap<String, List>();
        wangName.put("name", myNameWang);
        EndpointUser wangMajor = EndpointUser.builder().userId("example_user_10").userAttributes(wangName).build();
        // Create an EndpointBatchItem object for Mary Major.
        EndpointRequest wangXiulanEndpoint = EndpointRequest.builder().channelType(ChannelType.EMAIL).address("wang_xiulan@example.com").attributes(myMapWang).user(wangMajor).build();
        // Adds multiple endpoint definitions to a single request object.
        UpdateEndpointRequest endpointList = UpdateEndpointRequest.builder().applicationId(applicationId).endpointRequest(wangXiulanEndpoint).endpointId(endPointId).build();
        UpdateEndpointResponse result = pinpoint.updateEndpoint(endpointList);
        System.out.format("Update endpoint result: %s\n", result.messageBody().message());
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : UpdateEndpointResponse(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointResponse) HashMap(java.util.HashMap) EndpointUser(software.amazon.awssdk.services.pinpoint.model.EndpointUser) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) ArrayList(java.util.ArrayList) UpdateEndpointRequest(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest) Map(java.util.Map) HashMap(java.util.HashMap) UpdateEndpointRequest(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest) EndpointRequest(software.amazon.awssdk.services.pinpoint.model.EndpointRequest)

Aggregations

ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 EndpointUser (software.amazon.awssdk.services.pinpoint.model.EndpointUser)3 PinpointException (software.amazon.awssdk.services.pinpoint.model.PinpointException)3 Map (java.util.Map)2 EndpointRequest (software.amazon.awssdk.services.pinpoint.model.EndpointRequest)2 UpdateEndpointRequest (software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 EndpointBatchItem (software.amazon.awssdk.services.pinpoint.model.EndpointBatchItem)1 EndpointBatchRequest (software.amazon.awssdk.services.pinpoint.model.EndpointBatchRequest)1 EndpointDemographic (software.amazon.awssdk.services.pinpoint.model.EndpointDemographic)1 EndpointLocation (software.amazon.awssdk.services.pinpoint.model.EndpointLocation)1 GetEndpointRequest (software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest)1 UpdateEndpointResponse (software.amazon.awssdk.services.pinpoint.model.UpdateEndpointResponse)1 UpdateEndpointsBatchRequest (software.amazon.awssdk.services.pinpoint.model.UpdateEndpointsBatchRequest)1 UpdateEndpointsBatchResponse (software.amazon.awssdk.services.pinpoint.model.UpdateEndpointsBatchResponse)1