Class: ActsAsIcontact::Message

Inherits:
Resource
  • Object
show all
Defined in:
lib/acts_as_icontact/resources/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, all, #connection, #error, #errors, find, find_by_id, first, #id, #inspect, #method_missing, #new_record?, #property_names, #save, #save!

Constructor Details

#initialize(properties = {}) ⇒ Message

Has a default messageType of “normal” if another isn’t passed as an option.



4
5
6
# File 'lib/acts_as_icontact/resources/message.rb', line 4

def initialize(properties={})
  super({:messageType => "normal"}.merge(properties))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActsAsIcontact::Resource

Class Method Details

.required_on_createObject

Requires messageType and subject



9
10
11
# File 'lib/acts_as_icontact/resources/message.rb', line 9

def self.required_on_create
  super << "messageType" << "subject"
end

Instance Method Details

#bounces(options = {}) ⇒ Object

Returns a collection of MessageBounces resources for this message. The usual iContact search options (limit, offset, search terms, etc.) can be passed.



29
30
31
# File 'lib/acts_as_icontact/resources/message.rb', line 29

def bounces(options={})
  @bounces ||= ActsAsIcontact::MessageBounces.scoped_find(self, options)
end

#campaignObject

Returns the Campaign resource associated with this message, if campaignId is set. Otherwise returns nil. Returns an exception if the campaignId is set but the campaign cannot be found.



20
21
22
23
24
25
26
# File 'lib/acts_as_icontact/resources/message.rb', line 20

def campaign
  if (c = campaignId.to_i) > 0
    Campaign.find(c)
  else
    nil
  end
end

#clicks(options = {}) ⇒ Object

Returns a collection of MessageClicks resources for this message. The usual iContact search options (limit, offset, search terms, etc.) can be passed.



34
35
36
# File 'lib/acts_as_icontact/resources/message.rb', line 34

def clicks(options={})
  @clicks ||= ActsAsIcontact::MessageClicks.scoped_find(self, options)
end

#opens(options = {}) ⇒ Object

Returns a collection of MessageOpens resources for this message. The usual iContact search options (limit, offset, search terms, etc.) can be passed.



39
40
41
# File 'lib/acts_as_icontact/resources/message.rb', line 39

def opens(options={})
  @opens ||= ActsAsIcontact::MessageOpens.scoped_find(self, options)
end

#statistics(options = {}) ⇒ Object

Returns the Statistics record for this contact. This is a singleton resource and does not accept find, etc.



44
45
46
# File 'lib/acts_as_icontact/resources/message.rb', line 44

def statistics(options={})
  @statistics ||= ActsAsIcontact::MessageStatistics.scoped_first(self)
end

#validate_on_save(fields) ⇒ Object

messageType must be one of four values: normal, autoresponder, welcome, or confirmation



14
15
16
17
# File 'lib/acts_as_icontact/resources/message.rb', line 14

def validate_on_save(fields)
  messageType = %w(normal autoresponder welcome confirmation)
  raise ActsAsIcontact::ValidationError, "messageType must be one of: " + messageType.join(', ') unless messageType.include?(fields["messageType"])
end