Class: Bronto::Message

Inherits:
Base show all
Defined in:
lib/bronto/message.rb

Defined Under Namespace

Classes: Content

Instance Attribute Summary collapse

Attributes inherited from Base

#api_key, #errors, #id

Instance Method Summary collapse

Methods inherited from Base

api, api_key, api_key=, #create, create, destroy, #destroy, find, plural_class_name, #reload, request, #request, save, #save, session_expired, update, #update

Constructor Details

#initialize(options = {}) ⇒ Message

Returns a new instance of Message.



5
6
7
8
# File 'lib/bronto/message.rb', line 5

def initialize(options = {})
  super(options)
  self.content = { }
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/bronto/message.rb', line 3

def content
  @content
end

#message_folder_idObject

Returns the value of attribute message_folder_id.



3
4
5
# File 'lib/bronto/message.rb', line 3

def message_folder_id
  @message_folder_id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/bronto/message.rb', line 3

def name
  @name
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/bronto/message.rb', line 3

def status
  @status
end

Instance Method Details

#add_content(type, subject, content) ⇒ Object



18
19
20
# File 'lib/bronto/message.rb', line 18

def add_content(type, subject, content)
  self.content[type] = Content.new(type, subject, content)
end

#to_hashObject



10
11
12
13
14
15
16
# File 'lib/bronto/message.rb', line 10

def to_hash
  hash = { id: id, name: name, status: status, message_folder_id: message_folder_id, content: content.values.map(&:to_hash) }
  [ :status, :id, :message_folder_id ].each do |f|
    hash.delete(f) if send(f).blank?
  end
  hash
end