Class: AWS::SNS::Message
- Inherits:
-
Object
- Object
- AWS::SNS::Message
- Defined in:
- lib/aws/sns/message.rb
Overview
Represents a single SNS message.
See also http://docs.amazonwebservices.com/sns/latest/gsg/json-formats.html
= Originators
Originators are sources of SNS messages. FromAutoScaling is one. Message
can be extended by originators if their #applicable? method returns true when
passed the raw message.
Originator modules must implement applicable? sns
module function.
If an originator is applicable, it should set the @origin
accessor to denote
itself.
Instance Attribute Summary collapse
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#[](key) ⇒ String
The value of the SNS' field.
- #authentic? ⇒ Boolean
-
#initialize(sns) ⇒ Message
constructor
Constructs a new Message from the raw SNS, sets origin.
- #message ⇒ Object
- #message_id ⇒ Object
- #parse_from(json) ⇒ Object
- #signature ⇒ Object
- #signature_version ⇒ Object
- #signing_cert_url ⇒ Object
- #subject ⇒ Object
- #timestamp ⇒ Object
- #topic_arn ⇒ Object
-
#type ⇒ Object
@return[Symbol] the message type.
- #unsubscribe_url ⇒ Object
Constructor Details
#initialize(sns) ⇒ Message
Returns Constructs a new AWS::SNS::Message from the raw SNS, sets origin.
42 43 44 45 46 47 48 49 50 |
# File 'lib/aws/sns/message.rb', line 42 def initialize sns if sns.is_a? String @raw = parse_from sns else @raw = sns end @origin = :sns self.extend FromAutoScaling if FromAutoScaling.applicable? @raw end |
Instance Attribute Details
#origin ⇒ Object
Returns the value of attribute origin.
39 40 41 |
# File 'lib/aws/sns/message.rb', line 39 def origin @origin end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
38 39 40 |
# File 'lib/aws/sns/message.rb', line 38 def raw @raw end |
Instance Method Details
#[](key) ⇒ String
Returns the value of the SNS' field.
54 55 56 |
# File 'lib/aws/sns/message.rb', line 54 def [] key @raw[key] end |
#authentic? ⇒ Boolean
64 65 66 67 68 69 70 71 72 |
# File 'lib/aws/sns/message.rb', line 64 def authentic? begin decoded_from_base64 = decode signature public_key = get_public_key_from signing_cert_url public_key.verify OpenSSL::Digest::SHA1.new, decoded_from_base64, canonical_string rescue MessageWasNotAuthenticError false end end |
#message ⇒ Object
99 100 101 |
# File 'lib/aws/sns/message.rb', line 99 def @raw['Message'] end |
#message_id ⇒ Object
87 88 89 |
# File 'lib/aws/sns/message.rb', line 87 def @raw['MessageId'] end |
#parse_from(json) ⇒ Object
123 124 125 |
# File 'lib/aws/sns/message.rb', line 123 def parse_from json JSON.parse json end |
#signature ⇒ Object
107 108 109 |
# File 'lib/aws/sns/message.rb', line 107 def signature @raw['Signature'] end |
#signature_version ⇒ Object
111 112 113 |
# File 'lib/aws/sns/message.rb', line 111 def signature_version @raw['SignatureVersion'] end |
#signing_cert_url ⇒ Object
115 116 117 |
# File 'lib/aws/sns/message.rb', line 115 def signing_cert_url @raw['SigningCertURL'] end |
#subject ⇒ Object
95 96 97 |
# File 'lib/aws/sns/message.rb', line 95 def subject @raw['Subject'] end |
#timestamp ⇒ Object
103 104 105 |
# File 'lib/aws/sns/message.rb', line 103 def @raw['Timestamp'] end |
#topic_arn ⇒ Object
91 92 93 |
# File 'lib/aws/sns/message.rb', line 91 def topic_arn @raw['TopicArn'] end |
#type ⇒ Object
@return[Symbol] the message type
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/aws/sns/message.rb', line 75 def type case when @raw['Type'] =~ /SubscriptionConfirmation/i then :SubscriptionConfirmation when @raw['Type'] =~ /Notification/i then :Notification when @raw['Type'] =~ /UnsubscribeConfirmation/i then :UnsubscribeConfirmation else :unknown end end |
#unsubscribe_url ⇒ Object
119 120 121 |
# File 'lib/aws/sns/message.rb', line 119 def unsubscribe_url @raw['UnsubscribeURL'] end |