class Maropost::Contact
Constants
- ATTRIBUTES
- LISTS
Public Class Methods
new(opts = {})
click to toggle source
# File lib/maropost/contact.rb, line 34 def initialize(opts = {}) data = opts.with_indifferent_access self.id = data[:id] self.email = data[:email] self.phone_number = data[:phone] self.first_name = data[:first_name] self.last_name = data[:last_name] self.cell_phone_number = data[:cell_phone_number] self.allow_emails = data.fetch(:allow_emails) { !DoNotMailList.exists?(self) } self.errors = [] self.lists = {} initialize_lists(data) end
Public Instance Methods
allow_emails?()
click to toggle source
# File lib/maropost/contact.rb, line 48 def allow_emails? allow_emails end
list_parameters()
click to toggle source
# File lib/maropost/contact.rb, line 56 def list_parameters { cell_phone_number: cell_phone_number }.merge(lists) end
merge_settings(old_contact)
click to toggle source
# File lib/maropost/contact.rb, line 60 def merge_settings(old_contact) self.phone_number = old_contact.phone_number self.cell_phone_number = old_contact.cell_phone_number self.allow_emails = old_contact.allow_emails lists.each do |list| lists[list] == '1' ? list : old_contact.lists[list] end self end
subscribed_to_any_lists?()
click to toggle source
# File lib/maropost/contact.rb, line 52 def subscribed_to_any_lists? lists.values.any? { |v| v == '1' } end
Private Instance Methods
initialize_lists(opts = {})
click to toggle source
# File lib/maropost/contact.rb, line 74 def initialize_lists(opts = {}) LISTS.each do |list| lists[list] = opts.fetch(list, 0).to_s end end