Class: SnsEndpoint::AWS::SNS::Message
- Inherits:
-
Object
- Object
- SnsEndpoint::AWS::SNS::Message
- Defined in:
- lib/message.rb
Instance Attribute Summary collapse
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #authentic? ⇒ Boolean
-
#initialize(sns) ⇒ Message
constructor
A new instance of Message.
- #message ⇒ Object
- #message_id ⇒ Object
- #parse_from(json) ⇒ Object
- #signature ⇒ Object
- #signature_version ⇒ Object
- #signing_cert_url ⇒ Object
- #subject ⇒ Object
- #subscribe_url ⇒ Object
- #timestamp ⇒ Object
- #token ⇒ Object
- #topic_arn ⇒ Object
- #type ⇒ Object
- #unsubscribe_url ⇒ Object
Constructor Details
#initialize(sns) ⇒ Message
Returns a new instance of Message.
30 31 32 33 34 35 36 37 |
# File 'lib/message.rb', line 30 def initialize sns if sns.is_a? String @raw = parse_from sns else @raw = sns end @origin = :sns end |
Instance Attribute Details
#origin ⇒ Object
Returns the value of attribute origin.
28 29 30 |
# File 'lib/message.rb', line 28 def origin @origin end |
#raw ⇒ Object
Returns the value of attribute raw.
28 29 30 |
# File 'lib/message.rb', line 28 def raw @raw end |
Instance Method Details
#[](key) ⇒ Object
39 40 41 |
# File 'lib/message.rb', line 39 def [] key @raw[key] end |
#authentic? ⇒ Boolean
43 44 45 46 47 48 49 50 51 |
# File 'lib/message.rb', line 43 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
77 78 79 |
# File 'lib/message.rb', line 77 def @raw['Message'] end |
#message_id ⇒ Object
65 66 67 |
# File 'lib/message.rb', line 65 def @raw['MessageId'] end |
#parse_from(json) ⇒ Object
109 110 111 |
# File 'lib/message.rb', line 109 def parse_from json JSON.parse json end |
#signature ⇒ Object
85 86 87 |
# File 'lib/message.rb', line 85 def signature @raw['Signature'] end |
#signature_version ⇒ Object
89 90 91 |
# File 'lib/message.rb', line 89 def signature_version @raw['SignatureVersion'] end |
#signing_cert_url ⇒ Object
93 94 95 |
# File 'lib/message.rb', line 93 def signing_cert_url @raw['SigningCertURL'] end |
#subject ⇒ Object
73 74 75 |
# File 'lib/message.rb', line 73 def subject @raw['Subject'] end |
#subscribe_url ⇒ Object
101 102 103 |
# File 'lib/message.rb', line 101 def subscribe_url @raw['SubscribeURL'] end |
#timestamp ⇒ Object
81 82 83 |
# File 'lib/message.rb', line 81 def @raw['Timestamp'] end |
#token ⇒ Object
105 106 107 |
# File 'lib/message.rb', line 105 def token @raw['Token'] end |
#topic_arn ⇒ Object
69 70 71 |
# File 'lib/message.rb', line 69 def topic_arn @raw['TopicArn'] end |
#type ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/message.rb', line 53 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
97 98 99 |
# File 'lib/message.rb', line 97 def unsubscribe_url @raw['UnsubscribeURL'] end |