Search in sources :

Example 6 with PinpointException

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

the class UpdateChannel method toggleSmsChannel.

private static void toggleSmsChannel(PinpointClient client, String appId, SMSChannelResponse getResponse) {
    boolean enabled = true;
    if (getResponse.enabled()) {
        enabled = false;
    }
    try {
        SMSChannelRequest request = SMSChannelRequest.builder().enabled(enabled).build();
        UpdateSmsChannelRequest updateRequest = UpdateSmsChannelRequest.builder().smsChannelRequest(request).applicationId(appId).build();
        UpdateSmsChannelResponse result = client.updateSmsChannel(updateRequest);
        System.out.println("Channel state: " + result.smsChannelResponse().enabled());
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SMSChannelRequest(software.amazon.awssdk.services.pinpoint.model.SMSChannelRequest) UpdateSmsChannelRequest(software.amazon.awssdk.services.pinpoint.model.UpdateSmsChannelRequest) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) UpdateSmsChannelResponse(software.amazon.awssdk.services.pinpoint.model.UpdateSmsChannelResponse)

Example 7 with PinpointException

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

the class UpdateEndpoint method createEndpoint.

// snippet-start:[pinpoint.java2.createendpoint.main]
// snippet-start:[pinpoint.java2.createendpoint.helper]
public static EndpointResponse createEndpoint(PinpointClient client, String appId) {
    String endpointId = UUID.randomUUID().toString();
    System.out.println("Endpoint ID: " + endpointId);
    try {
        EndpointRequest endpointRequest = createEndpointRequestData();
        UpdateEndpointRequest updateEndpointRequest = UpdateEndpointRequest.builder().applicationId(appId).endpointId(endpointId).endpointRequest(endpointRequest).build();
        UpdateEndpointResponse updateEndpointResponse = client.updateEndpoint(updateEndpointRequest);
        System.out.println("Update Endpoint Response: " + updateEndpointResponse.messageBody());
        GetEndpointRequest getEndpointRequest = GetEndpointRequest.builder().applicationId(appId).endpointId(endpointId).build();
        GetEndpointResponse getEndpointResponse = client.getEndpoint(getEndpointRequest);
        System.out.println(getEndpointResponse.endpointResponse().address());
        System.out.println(getEndpointResponse.endpointResponse().channelType());
        System.out.println(getEndpointResponse.endpointResponse().applicationId());
        System.out.println(getEndpointResponse.endpointResponse().endpointStatus());
        System.out.println(getEndpointResponse.endpointResponse().requestId());
        System.out.println(getEndpointResponse.endpointResponse().user());
        return getEndpointResponse.endpointResponse();
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : GetEndpointResponse(software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse) UpdateEndpointResponse(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointResponse) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) UpdateEndpointRequest(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest) GetEndpointRequest(software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest) UpdateEndpointRequest(software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest) EndpointRequest(software.amazon.awssdk.services.pinpoint.model.EndpointRequest) GetEndpointRequest(software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest)

Example 8 with PinpointException

use of software.amazon.awssdk.services.pinpoint.model.PinpointException 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 9 with PinpointException

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

the class DeleteEndpoint method deletePinEncpoint.

// snippet-start:[pinpoint.java2.deleteendpoint.main]
public static void deletePinEncpoint(PinpointClient pinpoint, String appId, String endpointId) {
    try {
        DeleteEndpointRequest appRequest = DeleteEndpointRequest.builder().applicationId(appId).endpointId(endpointId).build();
        DeleteEndpointResponse result = pinpoint.deleteEndpoint(appRequest);
        String id = result.endpointResponse().id();
        System.out.println("The deleted endpoint id  " + id);
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    System.out.println("Done");
}
Also used : DeleteEndpointResponse(software.amazon.awssdk.services.pinpoint.model.DeleteEndpointResponse) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) DeleteEndpointRequest(software.amazon.awssdk.services.pinpoint.model.DeleteEndpointRequest)

Example 10 with PinpointException

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

the class SendMessage method sendSMSMessage.

// snippet-start:[pinpoint.java2.sendmsg.main]
public static void sendSMSMessage(PinpointClient pinpoint, String message, String appId, String originationNumber, String destinationNumber) {
    try {
        Map<String, AddressConfiguration> addressMap = new HashMap<String, AddressConfiguration>();
        AddressConfiguration addConfig = AddressConfiguration.builder().channelType(ChannelType.SMS).build();
        addressMap.put(destinationNumber, addConfig);
        SMSMessage smsMessage = SMSMessage.builder().body(message).messageType(messageType).originationNumber(originationNumber).senderId(senderId).keyword(registeredKeyword).build();
        // Create a DirectMessageConfiguration object
        DirectMessageConfiguration direct = DirectMessageConfiguration.builder().smsMessage(smsMessage).build();
        MessageRequest msgReq = MessageRequest.builder().addresses(addressMap).messageConfiguration(direct).build();
        // create a  SendMessagesRequest object
        SendMessagesRequest request = SendMessagesRequest.builder().applicationId(appId).messageRequest(msgReq).build();
        SendMessagesResponse response = pinpoint.sendMessages(request);
        MessageResponse msg1 = response.messageResponse();
        Map map1 = msg1.result();
        // Write out the result of sendMessage
        map1.forEach((k, v) -> System.out.println((k + ":" + v)));
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SendMessagesResponse(software.amazon.awssdk.services.pinpoint.model.SendMessagesResponse) MessageRequest(software.amazon.awssdk.services.pinpoint.model.MessageRequest) SMSMessage(software.amazon.awssdk.services.pinpoint.model.SMSMessage) SendMessagesRequest(software.amazon.awssdk.services.pinpoint.model.SendMessagesRequest) HashMap(java.util.HashMap) MessageResponse(software.amazon.awssdk.services.pinpoint.model.MessageResponse) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) DirectMessageConfiguration(software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration) AddressConfiguration(software.amazon.awssdk.services.pinpoint.model.AddressConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PinpointException (software.amazon.awssdk.services.pinpoint.model.PinpointException)19 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 EndpointRequest (software.amazon.awssdk.services.pinpoint.model.EndpointRequest)3 EndpointUser (software.amazon.awssdk.services.pinpoint.model.EndpointUser)3 GetEndpointRequest (software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest)3 UpdateEndpointRequest (software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 AddressConfiguration (software.amazon.awssdk.services.pinpoint.model.AddressConfiguration)2 DirectMessageConfiguration (software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration)2 EndpointResponse (software.amazon.awssdk.services.pinpoint.model.EndpointResponse)2 GetEndpointResponse (software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse)2 GetExportJobRequest (software.amazon.awssdk.services.pinpoint.model.GetExportJobRequest)2 MessageRequest (software.amazon.awssdk.services.pinpoint.model.MessageRequest)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DateFormat (java.text.DateFormat)1 List (java.util.List)1