public class NotificationTools extends Object
Constructor and Description |
---|
NotificationTools(com.amazonaws.services.sns.AmazonSNS snsClient,
PlatformDetails platformDetails) |
Modifier and Type | Method and Description |
---|---|
com.amazonaws.services.sns.model.CreatePlatformApplicationResult |
createPlatformApplication()
Creates a platform application object for one of the supported push notification services,
such as APNS and GCM, to which devices and mobile apps may register.
|
com.amazonaws.services.sns.model.CreatePlatformEndpointResult |
createPlatformEndpoint(String customData,
String applicationArn,
String instanceId)
Create a Platform Endpoint
|
com.amazonaws.services.sns.model.CreateTopicResult |
createTopic(String topicName)
Creates a topic to which notifications can be published.
|
void |
deletePlatformApplication(String applicationArn)
Delete a Platform Application
|
void |
deleteTopic(String topicArn) |
Map<String,Object> |
generateAndroidPayload(String message)
Generates Payload for Android Platform
|
Map<String,Object> |
generateIOSPayload(String message)
Generates Payload for IOS Platform
|
PlatformDetails |
getPlatformDetails()
Details generated from Platform to which the Push Notification is to be published
|
com.amazonaws.services.sns.AmazonSNS |
getSnsClient()
Client for accessing Amazon SNS.
|
static String |
jsonify(Object message)
Convert Message Map to a JSON
|
com.amazonaws.services.sns.model.PublishResult |
publish(String targetArn,
String message)
Publish a Notification
Since we will be sending platform-specific payloads in messages using the Amazon SNS
the data must be key-value pair strings and formatted as JSON with quotation marks escaped.
|
void |
setPlatformDetails(PlatformDetails platformDetails)
Details generated from Platform to which the Push Notification is to be published
|
void |
setSnsClient(com.amazonaws.services.sns.AmazonSNS snsClient)
Client for accessing Amazon SNS.
|
List<com.amazonaws.services.sns.model.SubscribeResult> |
subscribeToTopic(String topicArn,
String protocol,
List<String> endpointArns)
Subscribe Endpoints to the topic
|
public NotificationTools(com.amazonaws.services.sns.AmazonSNS snsClient, PlatformDetails platformDetails)
public com.amazonaws.services.sns.model.CreatePlatformApplicationResult createPlatformApplication()
public com.amazonaws.services.sns.model.CreateTopicResult createTopic(String topicName)
topicName
- : The name of the topic you want to create.
Constraints: Topic names must be made up of only uppercase and lowercase ASCII letters,
numbers, underscores, and hyphens, and must be between 1 and 256 characters long.public com.amazonaws.services.sns.model.CreatePlatformEndpointResult createPlatformEndpoint(String customData, String applicationArn, String instanceId)
customData
- : Arbitrary user data to associate with the endpoint. Amazon SNS does not use this data.
The data must be in UTF-8 format and less than 2KB.applicationArn
- : Arn of application for which Endpoint is to be createdinstanceId
- : Unique identifier created by the notification service for an app on a device.
The specific name for Token will vary, depending on which notification service is being used.
For example, when using APNS as the notification service, you need the device token.
Alternatively, when using GCM or ADM, the device token equivalent is called the registration ID.public List<com.amazonaws.services.sns.model.SubscribeResult> subscribeToTopic(String topicArn, String protocol, List<String> endpointArns) throws PartialTransactionException
topicArn
- : The ARN of the topic you want to subscribe to.protocol
- : The protocol you want to use.
Supported protocols include:
endpointArns
- : The endpoint that you want to receive notifications.
Endpoints vary by protocol:
PartialTransactionException
public void deleteTopic(String topicArn)
topicArn
- : The ARN of the topic you want to delete.public void deletePlatformApplication(String applicationArn)
applicationArn
- : PlatformApplicationArn of platform application object to delete.public com.amazonaws.services.sns.model.PublishResult publish(String targetArn, String message)
targetArn
- : Topic or Endpoint Arn to which the Push Notification is to be publishedmessage
- : Notification to be publishedpublic Map<String,Object> generateAndroidPayload(String message)
message
- : notification to be sent to android devicepublic Map<String,Object> generateIOSPayload(String message)
message
- : notification to be sent to android device
TODO : Write Logic to create IOS Message Mappublic com.amazonaws.services.sns.AmazonSNS getSnsClient()
public void setSnsClient(com.amazonaws.services.sns.AmazonSNS snsClient)
public PlatformDetails getPlatformDetails()
public void setPlatformDetails(PlatformDetails platformDetails)
Copyright © 2018. All rights reserved.