Class: MessagePub::Notification

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

Overview

Represents a MessagePub notification. For more info, visit messagepub.com/documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Notification

Returns a new instance of Notification.



30
31
32
33
34
35
36
37
38
# File 'lib/messagepub/notification.rb', line 30

def initialize(options={})
  @body = options[:body]
  @subject = options[:subject]
  @escalation = options[:escalation]
  @postback_url = options[:postback_url]
  @send_at = options[:send_at]
  @recipients = []
  @id = nil
end

Instance Attribute Details

#bodyObject

The body of the message to send.



8
9
10
# File 'lib/messagepub/notification.rb', line 8

def body
  @body
end

#escalationObject

The amount of time (in minutes) to wait before sending to the next recipient in the list.



14
15
16
# File 'lib/messagepub/notification.rb', line 14

def escalation
  @escalation
end

#idObject

The unique id for the notification.



25
26
27
# File 'lib/messagepub/notification.rb', line 25

def id
  @id
end

#postback_urlObject

If postback_url is set in your account settings, this is the URL where MessagePub will post any replies it gets for this notification. For more info, visit messagepub.com/documentation/replies.



19
20
21
# File 'lib/messagepub/notification.rb', line 19

def postback_url
  @postback_url
end

#recipientsObject (readonly)

The array of recipients to which this notification will go to.



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

def recipients
  @recipients
end

#send_atObject

The time in UTC at which the notification will be sent.



22
23
24
# File 'lib/messagepub/notification.rb', line 22

def send_at
  @send_at
end

#subjectObject

The subject of the message to send (for emails only)



11
12
13
# File 'lib/messagepub/notification.rb', line 11

def subject
  @subject
end

Instance Method Details

#add_recipient(rcpt) ⇒ Object



40
41
42
# File 'lib/messagepub/notification.rb', line 40

def add_recipient(rcpt)
  @recipients << rcpt if rcpt.class == Recipient        
end

#to_xmlObject

Returns an XML representation of the notification that can be POSTed to the REST API.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/messagepub/notification.rb', line 45

def to_xml
  value = '<notification>'
  value += '<body>' + self.body + '</body>'
  value += '<subject>' + self.subject + '</subject>' unless self.subject.blank?
  value += '<escalation>' + self.escalation.to_s + '</escalation>' if self.escalation
  value += '<postback_url>' + self.postback_url + '</postback_url>' if self.postback_url
  value += '<send_at>' + self.send_at + '</send_at>' if self.send_at
  value += '<recipients>'
  self.recipients.each do |rcpt|
    value += rcpt.to_xml
  end
  value += '</recipients></notification>'
  value            
end