Search in sources :

Example 1 with UpdateEndpointRequest

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

the class CreateEndpoint method createEndpoint.

public static EndpointResponse createEndpoint(AmazonPinpoint client, String appId) {
    String endpointId = UUID.randomUUID().toString();
    System.out.println("Endpoint ID: " + endpointId);
    EndpointRequest endpointRequest = createEndpointRequestData();
    UpdateEndpointRequest updateEndpointRequest = new UpdateEndpointRequest().withApplicationId(appId).withEndpointId(endpointId).withEndpointRequest(endpointRequest);
    UpdateEndpointResult updateEndpointResponse = client.updateEndpoint(updateEndpointRequest);
    System.out.println("Update Endpoint Response: " + updateEndpointResponse.getMessageBody());
    GetEndpointRequest getEndpointRequest = new GetEndpointRequest().withApplicationId(appId).withEndpointId(endpointId);
    GetEndpointResult getEndpointResult = client.getEndpoint(getEndpointRequest);
    System.out.println("Got Endpoint: " + getEndpointResult.getEndpointResponse().getId());
    return getEndpointResult.getEndpointResponse();
}
Also used : GetEndpointResult(com.amazonaws.services.pinpoint.model.GetEndpointResult) 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) GetEndpointRequest(com.amazonaws.services.pinpoint.model.GetEndpointRequest) GetEndpointRequest(com.amazonaws.services.pinpoint.model.GetEndpointRequest)

Example 2 with UpdateEndpointRequest

use of com.amazonaws.services.pinpoint.model.UpdateEndpointRequest 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 UpdateEndpointRequest

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

the class TargetingClientTest method updateEndpointEmptyUserId.

@Test
public void updateEndpointEmptyUserId() {
    final ArgumentCaptor<UpdateEndpointRequest> requestArgumentCaptor = ArgumentCaptor.forClass(UpdateEndpointRequest.class);
    EndpointProfile endpointProfile = new EndpointProfile(mockContext);
    EndpointProfileUser user = new EndpointProfileUser();
    user.setUserId("");
    endpointProfile.setUser(user);
    targetingClient.updateEndpointProfile(endpointProfile);
    verifyAndRunExecutorService(1);
    verify(mockPinpointServiceClient, times(1)).updateEndpoint(requestArgumentCaptor.capture());
    for (final UpdateEndpointRequest request : requestArgumentCaptor.getAllValues()) {
        assertNotNull(request.getEndpointRequest().getUser());
        assertEquals(request.getEndpointRequest().getUser().getUserId(), "");
    }
}
Also used : EndpointProfileUser(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileUser) EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) UpdateEndpointRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointRequest) Test(org.junit.Test)

Example 4 with UpdateEndpointRequest

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

the class TargetingClientTest method updateEndpointNullUserId.

@Test
public void updateEndpointNullUserId() {
    final ArgumentCaptor<UpdateEndpointRequest> requestArgumentCaptor = ArgumentCaptor.forClass(UpdateEndpointRequest.class);
    targetingClient.updateEndpointProfile();
    verifyAndRunExecutorService(1);
    verify(mockPinpointServiceClient, times(1)).updateEndpoint(requestArgumentCaptor.capture());
    for (final UpdateEndpointRequest request : requestArgumentCaptor.getAllValues()) {
        assertNull(request.getEndpointRequest().getUser());
    }
}
Also used : UpdateEndpointRequest(com.amazonaws.services.pinpoint.model.UpdateEndpointRequest) Test(org.junit.Test)

Example 5 with UpdateEndpointRequest

use of com.amazonaws.services.pinpoint.model.UpdateEndpointRequest 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

UpdateEndpointRequest (com.amazonaws.services.pinpoint.model.UpdateEndpointRequest)5 EndpointRequest (com.amazonaws.services.pinpoint.model.EndpointRequest)3 EndpointUser (com.amazonaws.services.pinpoint.model.EndpointUser)2 UpdateEndpointResult (com.amazonaws.services.pinpoint.model.UpdateEndpointResult)2 Test (org.junit.Test)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 EndpointProfile (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile)1 EndpointProfileUser (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileUser)1 AmazonPinpoint (com.amazonaws.services.pinpoint.AmazonPinpoint)1 EndpointDemographic (com.amazonaws.services.pinpoint.model.EndpointDemographic)1 EndpointLocation (com.amazonaws.services.pinpoint.model.EndpointLocation)1 GetEndpointRequest (com.amazonaws.services.pinpoint.model.GetEndpointRequest)1 GetEndpointResult (com.amazonaws.services.pinpoint.model.GetEndpointResult)1 Date (java.util.Date)1