Module: Mailee::Sync::InstanceMethods::ClassMethods
- Defined in:
- lib/mailee/active_record.rb
Instance Method Summary collapse
-
#send_all_to_mailee(after = nil) ⇒ Object
Sends all items from the model to Mailee.
Instance Method Details
#send_all_to_mailee(after = nil) ⇒ Object
Sends all items from the model to Mailee. Allows passing a datetime to send only contacts updated after. Also allows the use of a block, wich will receive the record of the model and the record from Mailee:
Contact.send_all_to_mailee{|i,im| im.address = i.endereco; im.save }
IMPORTANT: This method only sends contacts. It does not receives ‘em. If you need to receive contacts, for now the best way is to export in Mailee’s web interface and import in your app.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/mailee/active_record.rb', line 128 def send_all_to_mailee(after=nil) items = after ? all(:conditions => ["updated_at >= ?", after]) : all for item in items begin contact = Mailee::Contact.find_by_internal_id item.id if contact and [:news] and ! item.send([:news]) contact.unsubscribe yield item, contact if block_given? next end unless contact next if [:news] and ! item.send([:news]) contact = Mailee::Contact.new contact.internal_id = item.id end contact.email = item.send([:email]) contact.name = item.send([:name]) if [:name] contact.save yield item, contact if block_given? rescue logger.warn "MAILEE-API: Falhou ao enviar o contato #{id} ao Mailee" end end end |