Module: Mailee::Sync::InstanceMethods
- Defined in:
- lib/mailee/active_record.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #create_in_mailee ⇒ Object
- #destroy_in_mailee(contact = nil) ⇒ Object
- #unsubscribe_in_mailee(contact = nil) ⇒ Object
- #update_in_mailee ⇒ Object
Class Method Details
.included(base) ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/mailee/active_record.rb', line 58 def self.included(base) # :nodoc: base.extend ClassMethods end |
Instance Method Details
#create_in_mailee ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mailee/active_record.rb', line 62 def create_in_mailee return if( [:news] and ! send([:news])) # Não cria se houver o campo booleano e ele for falso self.class.benchmark "Criando contato no Mailee" do contact = Mailee::Contact.new contact.internal_id = id contact.email = send([:email]) contact.name = send([:name]) if [:name] contact.save contact.put(:list_subscribe, :list => [:list]) if [:list] end rescue logger.warn "MAILEE-API: Falhou ao criar o contato #{id} no Mailee" end |
#destroy_in_mailee(contact = nil) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/mailee/active_record.rb', line 97 def destroy_in_mailee contact=nil self.class.benchmark "Excluindo contato no Mailee" do contact ||= Mailee::Contact.find_by_internal_id id contact.destroy end rescue logger.warn "MAILEE-API: Falhou ao excluir o contato #{id} no Mailee" end |
#unsubscribe_in_mailee(contact = nil) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/mailee/active_record.rb', line 106 def unsubscribe_in_mailee contact=nil self.class.benchmark "Descadastrando contato no Mailee" do contact ||= Mailee::Contact.find_by_internal_id id contact.unsubscribe end rescue logger.warn "MAILEE-API: Falhou ao descadastrar o contato #{id} no Mailee" end |
#update_in_mailee ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mailee/active_record.rb', line 76 def update_in_mailee self.class.benchmark "Atualizando contato no Mailee" do contact = Mailee::Contact.find_by_internal_id id if contact #Se o contato existe e o booleano foi desmarcado, realiza um UNSUBSCRIBE if [:news] and (! send([:news])) unsubscribe_in_mailee(contact) else contact.email = send([:email]) contact.name = send([:name]) if [:name] contact.save contact.put(:list_subscribe, :list => [:list]) if [:list] end else create_in_mailee # Se não achou o contato tem q inserir. end end rescue logger.warn "MAILEE-API: Falhou ao atualizar o contato #{id} no Mailee" end |