Search in sources :

Example 11 with PinpointException

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

the class UpdateChannel method getSMSChannel.

// snippet-start:[pinpoint.java2.updatechannel.main]
private static SMSChannelResponse getSMSChannel(PinpointClient client, String appId) {
    try {
        GetSmsChannelRequest request = GetSmsChannelRequest.builder().applicationId(appId).build();
        SMSChannelResponse response = client.getSmsChannel(request).smsChannelResponse();
        System.out.println("Channel state is " + response.enabled());
        return response;
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : SMSChannelResponse(software.amazon.awssdk.services.pinpoint.model.SMSChannelResponse) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) GetSmsChannelRequest(software.amazon.awssdk.services.pinpoint.model.GetSmsChannelRequest)

Example 12 with PinpointException

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

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

Example 14 with PinpointException

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

the class CreateCampaign method createCampaign.

public static CampaignResponse createCampaign(PinpointClient client, String appID, String segmentID) {
    try {
        Schedule schedule = Schedule.builder().startTime("IMMEDIATE").build();
        Message defaultMessage = Message.builder().action(Action.OPEN_APP).body("My message body.").title("My message title.").build();
        MessageConfiguration messageConfiguration = MessageConfiguration.builder().defaultMessage(defaultMessage).build();
        WriteCampaignRequest request = WriteCampaignRequest.builder().description("My description").schedule(schedule).name("MyCampaign").segmentId(segmentID).messageConfiguration(messageConfiguration).build();
        CreateCampaignResponse result = client.createCampaign(CreateCampaignRequest.builder().applicationId(appID).writeCampaignRequest(request).build());
        System.out.println("Campaign ID: " + result.campaignResponse().id());
        return result.campaignResponse();
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : MessageConfiguration(software.amazon.awssdk.services.pinpoint.model.MessageConfiguration) Message(software.amazon.awssdk.services.pinpoint.model.Message) CreateCampaignResponse(software.amazon.awssdk.services.pinpoint.model.CreateCampaignResponse) Schedule(software.amazon.awssdk.services.pinpoint.model.Schedule) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) WriteCampaignRequest(software.amazon.awssdk.services.pinpoint.model.WriteCampaignRequest)

Example 15 with PinpointException

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

the class CreateApp method createApplication.

// snippet-start:[pinpoint.java2.createapp.main]
public static String createApplication(PinpointClient pinpoint, String appName) {
    try {
        CreateApplicationRequest appRequest = CreateApplicationRequest.builder().name(appName).build();
        CreateAppRequest request = CreateAppRequest.builder().createApplicationRequest(appRequest).build();
        CreateAppResponse result = pinpoint.createApp(request);
        return result.applicationResponse().id();
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : CreateApplicationRequest(software.amazon.awssdk.services.pinpoint.model.CreateApplicationRequest) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) CreateAppResponse(software.amazon.awssdk.services.pinpoint.model.CreateAppResponse) CreateAppRequest(software.amazon.awssdk.services.pinpoint.model.CreateAppRequest)

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