Search in sources :

Example 1 with WriteSegmentRequest

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

the class CreateSegment method createSegment.

// snippet-start:[pinpoint.java2.createsegment.main]
public static SegmentResponse createSegment(PinpointClient client, String appId) {
    try {
        Map<String, AttributeDimension> segmentAttributes = new HashMap<>();
        segmentAttributes.put("Team", AttributeDimension.builder().attributeType(AttributeType.INCLUSIVE).values("Lakers").build());
        RecencyDimension recencyDimension = RecencyDimension.builder().duration("DAY_30").recencyType("ACTIVE").build();
        SegmentBehaviors segmentBehaviors = SegmentBehaviors.builder().recency(recencyDimension).build();
        SegmentDemographics segmentDemographics = SegmentDemographics.builder().build();
        SegmentLocation segmentLocation = SegmentLocation.builder().build();
        SegmentDimensions dimensions = SegmentDimensions.builder().attributes(segmentAttributes).behavior(segmentBehaviors).demographic(segmentDemographics).location(segmentLocation).build();
        WriteSegmentRequest writeSegmentRequest = WriteSegmentRequest.builder().name("MySegment").dimensions(dimensions).build();
        CreateSegmentRequest createSegmentRequest = CreateSegmentRequest.builder().applicationId(appId).writeSegmentRequest(writeSegmentRequest).build();
        CreateSegmentResponse createSegmentResult = client.createSegment(createSegmentRequest);
        System.out.println("Segment ID: " + createSegmentResult.segmentResponse().id());
        System.out.println("Done");
        return createSegmentResult.segmentResponse();
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return null;
}
Also used : SegmentDimensions(software.amazon.awssdk.services.pinpoint.model.SegmentDimensions) CreateSegmentResponse(software.amazon.awssdk.services.pinpoint.model.CreateSegmentResponse) AttributeDimension(software.amazon.awssdk.services.pinpoint.model.AttributeDimension) WriteSegmentRequest(software.amazon.awssdk.services.pinpoint.model.WriteSegmentRequest) HashMap(java.util.HashMap) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) CreateSegmentRequest(software.amazon.awssdk.services.pinpoint.model.CreateSegmentRequest) SegmentBehaviors(software.amazon.awssdk.services.pinpoint.model.SegmentBehaviors) SegmentDemographics(software.amazon.awssdk.services.pinpoint.model.SegmentDemographics) SegmentLocation(software.amazon.awssdk.services.pinpoint.model.SegmentLocation) RecencyDimension(software.amazon.awssdk.services.pinpoint.model.RecencyDimension)

Aggregations

HashMap (java.util.HashMap)1 AttributeDimension (software.amazon.awssdk.services.pinpoint.model.AttributeDimension)1 CreateSegmentRequest (software.amazon.awssdk.services.pinpoint.model.CreateSegmentRequest)1 CreateSegmentResponse (software.amazon.awssdk.services.pinpoint.model.CreateSegmentResponse)1 PinpointException (software.amazon.awssdk.services.pinpoint.model.PinpointException)1 RecencyDimension (software.amazon.awssdk.services.pinpoint.model.RecencyDimension)1 SegmentBehaviors (software.amazon.awssdk.services.pinpoint.model.SegmentBehaviors)1 SegmentDemographics (software.amazon.awssdk.services.pinpoint.model.SegmentDemographics)1 SegmentDimensions (software.amazon.awssdk.services.pinpoint.model.SegmentDimensions)1 SegmentLocation (software.amazon.awssdk.services.pinpoint.model.SegmentLocation)1 WriteSegmentRequest (software.amazon.awssdk.services.pinpoint.model.WriteSegmentRequest)1