Class: ActsAsIcontact::Message
- Defined in:
- lib/acts_as_icontact/resources/message.rb
Class Method Summary collapse
-
.required_on_create ⇒ Object
Requires messageType and subject.
Instance Method Summary collapse
-
#bounces(options = {}) ⇒ Object
Returns a collection of MessageBounces resources for this message.
-
#campaign ⇒ Object
Returns the Campaign resource associated with this message, if campaignId is set.
-
#clicks(options = {}) ⇒ Object
Returns a collection of MessageClicks resources for this message.
-
#initialize(properties = {}) ⇒ Message
constructor
Has a default messageType of “normal” if another isn’t passed as an option.
-
#opens(options = {}) ⇒ Object
Returns a collection of MessageOpens resources for this message.
-
#statistics(options = {}) ⇒ Object
Returns the Statistics record for this contact.
-
#validate_on_save(fields) ⇒ Object
messageType must be one of four values: normal, autoresponder, welcome, or confirmation.
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_create ⇒ Object
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(={}) @bounces ||= ActsAsIcontact::MessageBounces.scoped_find(self, ) end |
#campaign ⇒ Object
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(={}) @clicks ||= ActsAsIcontact::MessageClicks.scoped_find(self, ) 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(={}) @opens ||= ActsAsIcontact::MessageOpens.scoped_find(self, ) 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(={}) @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) = %w(normal autoresponder welcome confirmation) raise ActsAsIcontact::ValidationError, "messageType must be one of: " + .join(', ') unless .include?(fields["messageType"]) end |