Class: Pheme::TopicPublisher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic_arn:) ⇒ TopicPublisher

Returns a new instance of TopicPublisher.

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/pheme/topic_publisher.rb', line 5

def initialize(topic_arn:)
  raise ArgumentError, "must specify non-nil topic_arn" unless topic_arn.present?
  @topic_arn = topic_arn
end

Instance Attribute Details

#topic_arnObject

Returns the value of attribute topic_arn.



3
4
5
# File 'lib/pheme/topic_publisher.rb', line 3

def topic_arn
  @topic_arn
end

Instance Method Details

#publish(message) ⇒ Object



14
15
16
17
# File 'lib/pheme/topic_publisher.rb', line 14

def publish(message)
  Pheme.log(:info, "Publishing to #{topic_arn}: #{message}")
  Pheme.configuration.sns_client.publish(topic_arn: topic_arn, message: serialize(message))
end

#publish_eventsObject

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/pheme/topic_publisher.rb', line 10

def publish_events
  raise NotImplementedError
end

#serialize(message) ⇒ Object



19
20
21
22
# File 'lib/pheme/topic_publisher.rb', line 19

def serialize(message)
  return message if message.is_a? String
  message.to_json
end