Class: Contactology::Contact
- Extended by:
- API
- Defined in:
- lib/contactology/contact.rb
Overview
Represents a Contact on Contactology. Contacts always must have an email address and then may optionally carry other custom fields.
Class Method Summary collapse
-
.create(attributes, options = {}) ⇒ Object
Public: Create a new contact.
-
.find(email, options = {}) ⇒ Object
Public: Lookup a contact’s information by email address.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Public: Indicates whether or not the contact is active.
-
#bounced? ⇒ Boolean
Public: Indicates whether or not the contact has a bounced address.
-
#change_email(new_email, options = {}) ⇒ Object
Public: Changes the contact’s email address to the new address given.
- #deleted? ⇒ Boolean
-
#destroy(options = {}) ⇒ Object
Public: Removes the contact from Contactology and from your account.
- #lists(options = {}) ⇒ Object
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
-
#suppress(options = {}) ⇒ Object
Public: Suppresses the contact, removing them from receiving campaign mailings.
-
#suppressed? ⇒ Boolean
Public: Indicates whether or not the contact is suppressed.
Methods included from API
Methods inherited from Stash
Class Method Details
.create(attributes, options = {}) ⇒ Object
Public: Create a new contact. The only required attribute is an :email address.
Examples
Contactology::Contact.create(:email => '[email protected]')
# => #<Contactology::Contact:0x000... @email="[email protected]" ...>
Returns a Contactology::Contact instance when successful. Returns false when unsuccessful or a network error occurs.
33 34 35 36 |
# File 'lib/contactology/contact.rb', line 33 def self.create(attributes, = {}) contact = new(attributes) contact.save() ? contact : false end |
.find(email, options = {}) ⇒ Object
Public: Lookup a contact’s information by email address.
Examples
Contactology::Contact.find('[email protected]')
# => #<Contactology::Contact:0x000... @email="[email protected]" ...>
Returns a Contactology::Contact instance when a match is found. Otherise, returns nil.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/contactology/contact.rb', line 49 def self.find(email, = {}) query('Contact_Get', .merge({ 'email' => email, 'optionalParameters' => {'getAllCustomFields' => true}, :on_timeout => nil, :on_error => nil, :on_success => Proc.new { |response| Contact.new(response.values.first) if response.respond_to?(:values) } })) end |
Instance Method Details
#active? ⇒ Boolean
Public: Indicates whether or not the contact is active. Active contacts may receive mailings from your campaigns.
Returns true if active. Returns false if non-active.
69 70 71 |
# File 'lib/contactology/contact.rb', line 69 def active? status == 'active' end |
#bounced? ⇒ Boolean
Public: Indicates whether or not the contact has a bounced address. This means that mail delivery has failed in a way that Contactology is no longer sending mailings to this contact.
Returns true if bounced. Returns false if non-bounced.
81 82 83 |
# File 'lib/contactology/contact.rb', line 81 def bounced? status == 'bounced' end |
#change_email(new_email, options = {}) ⇒ Object
Public: Changes the contact’s email address to the new address given.
Examples
contact = Contactology::Contact.find('[email protected]')
# => #<Contactology::Contact:0x000... @email="[email protected]" ...>
contact.change_email('[email protected]')
# => true
contact.email
# => '[email protected]'
Returns true when successful. Returns false when unsuccessful or for a network failure.
100 101 102 103 104 105 106 107 108 |
# File 'lib/contactology/contact.rb', line 100 def change_email(new_email, = {}) self.class.query('Contact_Change_Email', .merge({ 'email' => email, 'newEmail' => new_email, :on_timeout => false, :on_error => false, :on_success => Proc.new { |response| self.email = new_email; true } })) end |
#deleted? ⇒ Boolean
110 111 112 |
# File 'lib/contactology/contact.rb', line 110 def deleted? status == 'deleted' end |
#destroy(options = {}) ⇒ Object
Public: Removes the contact from Contactology and from your account.
Examples
contact = Contactology::Contact.find('[email protected]')
# => #<Contactology::Contact:0x000... @email="[email protected]" ...>
contact.destroy
# => true
Returns true when successful. Returns false when unsuccessful or for a network failure.
127 128 129 130 131 132 133 134 |
# File 'lib/contactology/contact.rb', line 127 def destroy( = {}) self.class.query('Contact_Delete', .merge({ :email => email, :on_timeout => false, :on_error => false, :on_success => Proc.new { |r| self.status = 'deleted'; true } })) end |
#lists(options = {}) ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/contactology/contact.rb', line 136 def lists( = {}) self.class.query('Contact_Get_Subscriptions', .merge({ 'email' => email, :on_timeout => [], :on_error => [], :on_success => Proc.new { |response| response.collect { |listid| ListProxy.new(listid) } } })) end |
#save(options = {}) ⇒ Object
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/contactology/contact.rb', line 147 def save( = {}) self.class.query('Contact_Add', { 'email' => email, 'customFields' => custom_fields, 'optionalParameters' => {'updateCustomFields' => true}, :on_timeout => false, :on_error => false, :on_success => Proc.new { |response| self.status = 'active'; self } }) end |
#save!(options = {}) ⇒ Object
158 159 160 |
# File 'lib/contactology/contact.rb', line 158 def save!( = {}) save() || raise(InvalidObjectError) end |
#suppress(options = {}) ⇒ Object
Public: Suppresses the contact, removing them from receiving campaign mailings.
Returns true when successful. Returns false when unsuccessful.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/contactology/contact.rb', line 169 def suppress( = {}) response = self.class.query('Contact_Suppress', .merge({ :email => email, :on_timeout => false, :on_error => false, :on_success => Proc.new { |r| r } })) if response self.status = 'suppressed' end response end |
#suppressed? ⇒ Boolean
Public: Indicates whether or not the contact is suppressed. Suppressed contacts may not receive mailings from your campaigns.
Returns true if suppressed. Returns false if non-suppressed.
191 192 193 |
# File 'lib/contactology/contact.rb', line 191 def suppressed? status == 'suppressed' end |