Class: PushToSNS::SendPushNotification

Inherits:
Object
  • Object
show all
Defined in:
lib/push_to_sns/send_push_notification.rb

Instance Method Summary collapse

Constructor Details

#initialize(device, configuration = PushToSNS.configuration) ⇒ SendPushNotification

Returns a new instance of SendPushNotification.



3
4
5
6
# File 'lib/push_to_sns/send_push_notification.rb', line 3

def initialize(device, configuration = PushToSNS.configuration)
  self.device = device
  self.configuration = configuration
end

Instance Method Details

#perform(payload) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/push_to_sns/send_push_notification.rb', line 8

def perform(payload)
  ensure_endpoint_arn_is_enabled
  notification = build_push_notification(payload)

  response = AWS.sns.client.publish(
    message_structure: "json",
    message: notification.message.to_json,
    target_arn: configuration.apply(:read_endpoint_arn, device)
  )

  response[:message_id]
rescue AWS::SNS::Errors::EndpointDisabled => _exception
  perform(payload)
end