Class: SnsEndpoint::AWS::SNS::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#originObject

Returns the value of attribute origin.



28
29
30
# File 'lib/message.rb', line 28

def origin
  @origin
end

#rawObject

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

Returns:

  • (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

#messageObject



77
78
79
# File 'lib/message.rb', line 77

def message
  @raw['Message']
end

#message_idObject



65
66
67
# File 'lib/message.rb', line 65

def message_id
  @raw['MessageId']
end

#parse_from(json) ⇒ Object



109
110
111
# File 'lib/message.rb', line 109

def parse_from json
  JSON.parse json
end

#signatureObject



85
86
87
# File 'lib/message.rb', line 85

def signature
  @raw['Signature']
end

#signature_versionObject



89
90
91
# File 'lib/message.rb', line 89

def signature_version
  @raw['SignatureVersion']
end

#signing_cert_urlObject



93
94
95
# File 'lib/message.rb', line 93

def signing_cert_url
  @raw['SigningCertURL']
end

#subjectObject



73
74
75
# File 'lib/message.rb', line 73

def subject
  @raw['Subject']
end

#subscribe_urlObject



101
102
103
# File 'lib/message.rb', line 101

def subscribe_url
  @raw['SubscribeURL']
end

#timestampObject



81
82
83
# File 'lib/message.rb', line 81

def timestamp
  @raw['Timestamp']
end

#tokenObject



105
106
107
# File 'lib/message.rb', line 105

def token
  @raw['Token']
end

#topic_arnObject



69
70
71
# File 'lib/message.rb', line 69

def topic_arn
  @raw['TopicArn']
end

#typeObject



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_urlObject



97
98
99
# File 'lib/message.rb', line 97

def unsubscribe_url
  @raw['UnsubscribeURL']
end