2019-01-22 12:49:55 -08:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2024-01-16 10:41:11 -05:00
2019-01-22 12:49:55 -08:00
// snippet-start:[pinpoint.java.pinpoint_create_endpoint.complete]
import com.amazonaws.regions.Regions ;
import com.amazonaws.services.pinpoint.AmazonPinpoint ;
import com.amazonaws.services.pinpoint.AmazonPinpointClientBuilder ;
import com.amazonaws.services.pinpoint.model.* ;
import java.util.Arrays ;
public class AddExampleEndpoint {
2019-02-06 15:23:31 -08:00
public static void main ( String [ ] args ) {
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
final String USAGE = " \ n " +
" AddExampleEndpoint - Adds an example endpoint to an Amazon Pinpoint application. " +
" Usage: AddExampleEndpoint <applicationId> " +
" Where: \ n " +
" applicationId - The ID of the Amazon Pinpoint application to add the example " +
" endpoint to. " ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
if ( args . length < 1 ) {
System . out . println ( USAGE ) ;
System . exit ( 1 ) ;
}
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
String applicationId = args [ 0 ] ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// The device token assigned to the user's device by Apple Push Notification
// service (APNs).
String deviceToken = " 1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f " ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// Initializes an endpoint definition with channel type and address.
EndpointRequest wangXiulansIphoneEndpoint = new EndpointRequest ( )
. withChannelType ( ChannelType . APNS )
. withAddress ( deviceToken ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// Adds custom attributes to the endpoint.
wangXiulansIphoneEndpoint . addAttributesEntry ( " interests " , Arrays . asList (
" technology " ,
" music " ,
" travel " ) ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// Adds custom metrics to the endpoint.
wangXiulansIphoneEndpoint . addMetricsEntry ( " technology_interest_level " , 9 . 0 ) ;
wangXiulansIphoneEndpoint . addMetricsEntry ( " music_interest_level " , 6 . 0 ) ;
wangXiulansIphoneEndpoint . addMetricsEntry ( " travel_interest_level " , 4 . 0 ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// Adds standard demographic attributes.
wangXiulansIphoneEndpoint . setDemographic ( new EndpointDemographic ( )
. withAppVersion ( " 1.0 " )
. withMake ( " apple " )
. withModel ( " iPhone " )
. withModelVersion ( " 8 " )
. withPlatform ( " ios " )
. withPlatformVersion ( " 11.3.1 " )
. withTimezone ( " America/Los_Angeles " ) ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// Adds standard location attributes.
wangXiulansIphoneEndpoint . setLocation ( new EndpointLocation ( )
. withCountry ( " US " )
. withCity ( " Seattle " )
. withPostalCode ( " 98121 " )
. withLatitude ( 47 . 61 )
. withLongitude ( - 122 . 33 ) ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder . standard ( )
. withRegion ( Regions . US_EAST_1 ) . build ( ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
// Updates or creates the endpoint with Amazon Pinpoint.
UpdateEndpointResult result = pinpointClient . updateEndpoint ( new UpdateEndpointRequest ( )
. withApplicationId ( applicationId )
. withEndpointId ( " example_endpoint " )
. withEndpointRequest ( wangXiulansIphoneEndpoint ) ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
System . out . format ( " Update endpoint result: %s \ n " , result . getMessageBody ( ) . getMessage ( ) ) ;
2024-01-16 10:41:11 -05:00
2019-02-06 15:23:31 -08:00
}
2019-01-22 12:49:55 -08:00
}
// snippet-end:[pinpoint.java.pinpoint_create_endpoint.complete]