Module: SnsHelper

Defined in:
app/helpers/sns_helper.rb

Instance Method Summary collapse

Instance Method Details

#sns_dataObject



24
25
26
# File 'app/helpers/sns_helper.rb', line 24

def sns_data
  @sns_data ||= ActiveSupport::JSON.decode(request.body).symbolize_keys!
end

#sns_duplicate_submission?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/helpers/sns_helper.rb', line 36

def sns_duplicate_submission?
  Rails.cache.read(sns_message_id)
end

#sns_messageObject



7
8
9
# File 'app/helpers/sns_helper.rb', line 7

def sns_message
  @sns_message ||= ActiveSupport::JSON.decode(sns_data[:Message]).symbolize_keys!
end

#sns_message_idObject



28
29
30
# File 'app/helpers/sns_helper.rb', line 28

def sns_message_id
  sns_data[:MessageId]
end

#sns_notification_idObject



20
21
22
# File 'app/helpers/sns_helper.rb', line 20

def sns_notification_id
  request.headers['x-amz-sns-message-id']
end

#sns_set_as_received!Object



32
33
34
# File 'app/helpers/sns_helper.rb', line 32

def sns_set_as_received!
  Rails.cache.write(sns_message_id, true, expires_in: 2.minutes)
end

#sns_topicObject

topic, without all the ARN



12
13
14
# File 'app/helpers/sns_helper.rb', line 12

def sns_topic
  sns_data[:TopicArn].match(/([^:]*)$/)[0]
end

#sns_typeObject



16
17
18
# File 'app/helpers/sns_helper.rb', line 16

def sns_type
  request.headers['x-amz-sns-message-type']
end

#sns_verified?Boolean

Returns:

  • (Boolean)


2
3
4
5
# File 'app/helpers/sns_helper.rb', line 2

def sns_verified?
  # TODO https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.verify.signature.html
  return true 
end