Class: Communicator::OutboundMessage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/communicator/outbound_message.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delivery_collection(from_id = nil) ⇒ Object

Returns an array of all undelivered messages. If the optional id is given will instead start from that id, not taking care whether the messages have already been marked as delivered.



11
12
13
# File 'lib/communicator/outbound_message.rb', line 11

def self.delivery_collection(from_id=nil)
  (from_id ? all(:conditions => ["id >= ?", from_id]) : undelivered)
end

Instance Method Details

#delivered!Object

Set the delivered_at flag to NOW and save!



26
27
28
29
# File 'lib/communicator/outbound_message.rb', line 26

def delivered!
  self.delivered_at = Time.now
  self.save!
end

#message_contentObject

Will return the JSON-parsed content of this message’s body



21
22
23
# File 'lib/communicator/outbound_message.rb', line 21

def message_content
  JSON.parse(body).with_indifferent_access
end

#payloadObject

Stripped down content hash for json delivery



16
17
18
# File 'lib/communicator/outbound_message.rb', line 16

def payload
  {:id => id, :body => body}
end