Class: DotMailer::Contact
- Inherits:
-
Object
- Object
- DotMailer::Contact
- Defined in:
- lib/dot_mailer/contact.rb
Class Method Summary collapse
- .find_by_email(account, email) ⇒ Object
-
.find_by_id(account, id) ⇒ Object
The API makes no distinction between finding by email or id, so we just delegate to Contact.find_by_email.
- .modified_since(account, time) ⇒ Object
Instance Method Summary collapse
-
#[](key) ⇒ Object
A wrapper method for accessing data field values by name, e.g.:.
-
#[]=(key, value) ⇒ Object
A wrapper method for assigning data field values, e.g.:.
- #delete ⇒ Object
- #email ⇒ Object
- #email=(email) ⇒ Object
- #email_type ⇒ Object
- #email_type=(email_type) ⇒ Object
- #id ⇒ Object
-
#initialize(account, attributes) ⇒ Contact
constructor
A new instance of Contact.
- #inspect ⇒ Object
- #opt_in_type ⇒ Object
- #opt_in_type=(opt_in_type) ⇒ Object
- #resubscribe(return_url) ⇒ Object
- #save ⇒ Object
- #status ⇒ Object
- #subscribed? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(account, attributes) ⇒ Contact
Returns a new instance of Contact.
32 33 34 35 |
# File 'lib/dot_mailer/contact.rb', line 32 def initialize(account, attributes) self.account = account self.attributes = attributes end |
Class Method Details
.find_by_email(account, email) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/dot_mailer/contact.rb', line 9 def self.find_by_email(account, email) response = account.client.get("/contacts/#{email}") new(account, response) rescue DotMailer::NotFound nil end |
.find_by_id(account, id) ⇒ Object
The API makes no distinction between finding by email or id, so we just delegate to Contact.find_by_email
20 21 22 |
# File 'lib/dot_mailer/contact.rb', line 20 def self.find_by_id(account, id) find_by_email account, id end |
.modified_since(account, time) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/dot_mailer/contact.rb', line 24 def self.modified_since(account, time) response = account.client.get("/contacts/modified-since/#{time.utc.xmlschema}") response.map do |attributes| new(account, attributes) end end |
Instance Method Details
#[](key) ⇒ Object
A wrapper method for accessing data field values by name, e.g.:
contact['FIRSTNAME']
83 84 85 86 87 88 89 |
# File 'lib/dot_mailer/contact.rb', line 83 def [](key) if data_fields.has_key?(key) data_fields[key] else raise UnknownDataField, key end end |
#[]=(key, value) ⇒ Object
A wrapper method for assigning data field values, e.g.:
contact['FIRSTNAME'] = 'Lewis'
95 96 97 98 99 100 101 |
# File 'lib/dot_mailer/contact.rb', line 95 def []=(key, value) if data_fields.has_key?(key) data_fields[key] = value else raise UnknownDataField, key end end |
#delete ⇒ Object
107 108 109 |
# File 'lib/dot_mailer/contact.rb', line 107 def delete client.delete "/contacts/#{id}" end |
#email ⇒ Object
41 42 43 |
# File 'lib/dot_mailer/contact.rb', line 41 def email attributes['email'] end |
#email=(email) ⇒ Object
45 46 47 |
# File 'lib/dot_mailer/contact.rb', line 45 def email=(email) attributes['email'] = email end |
#email_type ⇒ Object
59 60 61 |
# File 'lib/dot_mailer/contact.rb', line 59 def email_type attributes['emailType'] end |
#email_type=(email_type) ⇒ Object
63 64 65 |
# File 'lib/dot_mailer/contact.rb', line 63 def email_type=(email_type) attributes['emailType'] = email_type end |
#id ⇒ Object
37 38 39 |
# File 'lib/dot_mailer/contact.rb', line 37 def id attributes['id'] end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/dot_mailer/contact.rb', line 75 def inspect to_s end |
#opt_in_type ⇒ Object
49 50 51 |
# File 'lib/dot_mailer/contact.rb', line 49 def opt_in_type attributes['optInType'] end |
#opt_in_type=(opt_in_type) ⇒ Object
53 54 55 56 57 |
# File 'lib/dot_mailer/contact.rb', line 53 def opt_in_type=(opt_in_type) raise UnknownOptInType, opt_in_type unless OptInType.exists?(opt_in_type) attributes['optInType'] = opt_in_type end |
#resubscribe(return_url) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/dot_mailer/contact.rb', line 115 def resubscribe(return_url) return false if subscribed? client.post_json '/contacts/resubscribe', 'UnsubscribedContact' => { 'id' => id, 'Email' => email }, 'ReturnUrlToUseIfChallenged' => return_url end |
#save ⇒ Object
103 104 105 |
# File 'lib/dot_mailer/contact.rb', line 103 def save client.put_json "/contacts/#{id}", attributes.merge('dataFields' => data_fields_for_api) end |
#status ⇒ Object
67 68 69 |
# File 'lib/dot_mailer/contact.rb', line 67 def status attributes['status'] end |
#subscribed? ⇒ Boolean
111 112 113 |
# File 'lib/dot_mailer/contact.rb', line 111 def subscribed? status == SUBSCRIBED_STATUS end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/dot_mailer/contact.rb', line 71 def to_s %{#{self.class.name} id: #{id}, email: #{email}, opt_in_type: #{opt_in_type}, email_type: #{email_type}, status: #{status}, data_fields: #{data_fields.to_s}} end |