Class: AWS::SQS::ReceivedSNSMessage

Inherits:
Object
  • Object
show all
Includes:
Core::Model
Defined in:
lib/aws/sqs/received_sns_message.rb

Overview

Represents message published from an AWS::SNS::Topic to an Queue.

Instance Attribute Summary

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(body, options = {}) ⇒ ReceivedSNSMessage

Returns a new instance of ReceivedSNSMessage.

Parameters:

  • body (String)

    The SQS message body from a message published by SNS.

  • options (Hash) (defaults to: {})


28
29
30
31
# File 'lib/aws/sqs/received_sns_message.rb', line 28

def initialize body, options = {}
  @body = body
  super
end

Instance Method Details

#bodyObject

@return Returns the decoded message as was published.



41
42
43
# File 'lib/aws/sqs/received_sns_message.rb', line 41

def body
  to_h[:body]
end

#message_idString

Returns the unique id of the SNS message.

Returns:

  • (String)

    Returns the unique id of the SNS message.



78
79
80
# File 'lib/aws/sqs/received_sns_message.rb', line 78

def message_id
  to_h[:message_id]
end

#message_typeString

Returns the message type.

Returns:

  • (String)

    Returns the message type.



57
58
59
# File 'lib/aws/sqs/received_sns_message.rb', line 57

def message_type
  to_h[:message_type]
end

#published_atTime

Returns the time the message was published at by SNS. by SNS.

Returns:

  • (Time)

    Returns the time the message was published at by SNS. by SNS.



73
74
75
# File 'lib/aws/sqs/received_sns_message.rb', line 73

def published_at
  to_h[:published_at]
end

#raw_messageString

Returns the JSON hash (as a string) as was published by SNS. See #body to get the decoded message or #to_h to get the decoded JSON hash as a ruby hash.

Returns:

  • (String)

    Returns the JSON hash (as a string) as was published by SNS. See #body to get the decoded message or #to_h to get the decoded JSON hash as a ruby hash.



36
37
38
# File 'lib/aws/sqs/received_sns_message.rb', line 36

def raw_message
  @body
end

#signatureString

Returns the calculated signature for the message.

Returns:

  • (String)

    Returns the calculated signature for the message.



62
63
64
# File 'lib/aws/sqs/received_sns_message.rb', line 62

def signature
  to_h[:signature]
end

#signature_versionString

Returns the signature version.

Returns:

  • (String)

    Returns the signature version.



67
68
69
# File 'lib/aws/sqs/received_sns_message.rb', line 67

def signature_version
  to_h[:signature_version]
end

#signing_cert_urlString

Returns the url for the signing cert.

Returns:

  • (String)

    Returns the url for the signing cert.



83
84
85
# File 'lib/aws/sqs/received_sns_message.rb', line 83

def signing_cert_url
  to_h[:signing_cert_url]
end

#to_hHash

Returns the decoded message as a hash.

Returns:

  • (Hash)

    Returns the decoded message as a hash.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/aws/sqs/received_sns_message.rb', line 94

def to_h
  data = JSON.parse(@body)
  {
    :body => data['Message'],
    :topic_arn => data['TopicArn'],
    :message_type => data['Type'],
    :signature => data['Signature'],
    :signature_version => data['SignatureVersion'],
    :published_at => Time.parse(data['Timestamp']),
    :message_id => data['MessageId'],
    :signing_cert_url => data['SigningCertURL'],
    :unsubscribe_url => data['UnsubscribeURL'],
  }
end

#topicSNS::Topic

Returns the topic that published this message.

Returns:

  • (SNS::Topic)

    Returns the topic that published this message.



52
53
54
# File 'lib/aws/sqs/received_sns_message.rb', line 52

def topic
  SNS::Topic.new(topic_arn, :config => config)
end

#topic_arnString

Returns the ARN for the topic that published this message.

Returns:

  • (String)

    Returns the ARN for the topic that published this message.



47
48
49
# File 'lib/aws/sqs/received_sns_message.rb', line 47

def topic_arn
  to_h[:topic_arn]
end

#unsubscribe_urlString

Returns the url you can request to unsubscribe message from this queue.

Returns:

  • (String)

    Returns the url you can request to unsubscribe message from this queue.



89
90
91
# File 'lib/aws/sqs/received_sns_message.rb', line 89

def unsubscribe_url
  to_h[:unsubscribe_url]
end