Class: FakeSNS::Actions::Publish

Inherits:
FakeSNS::Action show all
Defined in:
lib/fake_sns/actions/publish.rb

Instance Attribute Summary

Attributes inherited from FakeSNS::Action

#db, #params

Instance Method Summary collapse

Methods inherited from FakeSNS::Action

#initialize, param

Constructor Details

This class inherits a constructor from FakeSNS::Action

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fake_sns/actions/publish.rb', line 11

def call
  if (bytes = message.bytesize) > 262144
    raise InvalidParameterValue, "Too much bytes: #{bytes} > 262144."
  end
  @topic = db.topics.fetch(topic_arn) do
    raise InvalidParameterValue, "Unknown topic: #{topic_arn}"
  end
  @message_id = SecureRandom.uuid

  db.messages.create(
    id:          message_id,
    subject:     subject,
    message:     message,
    topic_arn:   topic_arn,
    structure:   message_structure,
    target_arn:  target_arn,
    received_at: Time.now,
  )
end

#message_idObject



31
32
33
# File 'lib/fake_sns/actions/publish.rb', line 31

def message_id
  @message_id || raise(InternalFailure, "no message id yet, this should not happen")
end