mailee 0.3.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +117 -23
- data/README.markdown.pt +64 -0
- data/VERSION +1 -1
- data/app/Gemfile +1 -1
- data/app/Gemfile.lock +2 -0
- data/app/config/initializers/mailee.rb +1 -1
- data/lib/mailee.rb +5 -277
- data/lib/mailee/action_mailer.rb +52 -0
- data/lib/mailee/active_record.rb +153 -0
- data/lib/mailee/active_resource.rb +102 -0
- data/lib/mailee/railties.rb +36 -0
- data/mailee.gemspec +12 -3
- data/spec/am_spec_helper.rb +23 -0
- data/spec/mailee-api-am.rb +31 -0
- data/spec/mailee-api-ar.rb +6 -1
- data/spec/mailee-api.rb +0 -2
- metadata +15 -5
data/README.markdown
CHANGED
@@ -7,58 +7,152 @@
|
|
7
7
|
|
8
8
|
== A solução
|
9
9
|
|
10
|
-
|
10
|
+
Esta gem tem como objetivo manter os contatos da sua aplicação sincronizados com os contatos do Mailee (www.mailee.me) sem muito esforço. De fato, basta executar o método "sync_with_mailee" no seu modelo (clientes, contatos, pessoas...) que este irá automaticamente realizar as tarefas de inserir, atualizar, excluir e descadastrar via REST. No Mailee, seu cliente poderá então montar as mensagens e enviar para os contatos.
|
11
|
+
|
12
|
+
== O que posso fazer com a gem?
|
13
|
+
|
14
|
+
* Simplesmente utilizar as classes do Mailee para:
|
15
|
+
* Criar, atualizar, buscar e excluir contatos.
|
16
|
+
* Importar contatos com nome e email.
|
17
|
+
* Criar, atualizar, buscar e excluir listas.
|
18
|
+
* Criar, atualizar, buscar e excluir templates.
|
19
|
+
* Criar rascunhos, enviar testes e enviar mensagens agora ou para uma data futura. O envio de mensagens permite enviar para uma lista, para um conjunto de emails, definindo o html na mão ou usando um template do Mailee.me e definindo áreas editáveis e de repetições.
|
20
|
+
* Buscar datos dos relatórios.
|
21
|
+
* Integrar com ActiveRecord (com ou sem Rails) e fazer um modelo sincronizar automaticamente com o Mailee.me.
|
22
|
+
* Integrar com ActionMailer (com ou sem Rails) e fazer os mailers enviarem as mensagens pelo Mailee.me.
|
11
23
|
|
12
24
|
== Instalação
|
13
25
|
|
14
|
-
*
|
15
|
-
>
|
16
|
-
*
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
* Adicione a seguinte linha ao seu Gemfile:
|
27
|
+
> gem 'mailee'
|
28
|
+
* E execute o bundle:
|
29
|
+
> bundle install
|
30
|
+
* Uma vez instalado, para configurar, execute:
|
31
|
+
> rake mailee_rails:setup
|
32
|
+
|
33
|
+
Este comando irá solicitar sua URL da API e criar um initializer com toda a configuração necessária.
|
34
|
+
A URL da API você descobre entrando no Mailee e indo em Configurações > Integração > REST
|
21
35
|
|
36
|
+
Pronto!
|
37
|
+
|
38
|
+
== Compatibilidade
|
39
|
+
|
40
|
+
Rails 3. 'Nuff said. Se você precisa de suporte aoRails 2, baixe a versão 0.1.0, mas ela possui muito menos funcionalidades do que a versão atual.
|
41
|
+
|
22
42
|
== Uso
|
23
43
|
|
24
44
|
* Na mão (console)
|
45
|
+
|
25
46
|
Você pode usar a api do maile "na mão". Basta abrir o console e usar:
|
26
47
|
> ruby script/console
|
48
|
+
>> include Mailee
|
27
49
|
>> Contact.find(:all)
|
28
50
|
>> Contact.find(:first)
|
51
|
+
>> Contact.search('russell')
|
52
|
+
>> Contact.find_by_internal_id(789)
|
53
|
+
>> Contact.find_by_email('russell@cambridge.edu.uk')
|
29
54
|
>> Contact.create(:name => 'Bertrand Russell', :email => 'russell@cambridge.edu.uk')
|
30
|
-
|
55
|
+
>> Contact.create(:email => 'ludwig@wittgenstein.edu.uk', :dynamic_attributes => {:influence => 'Frege'})
|
56
|
+
>> List.find(:all)
|
57
|
+
>> List.find(:first)
|
58
|
+
>> List.create(:name => 'My List')
|
59
|
+
>> Template.find(:all)
|
60
|
+
>> Template.find(:first)
|
61
|
+
>> Template.create(:title => 'My Template', :html => File.read('mytemplate.html'))
|
62
|
+
# Message with HTML and list
|
63
|
+
>> message = Message.create :title => "Title", :subject => "Subject", :from_name => "Rorty", :from_email => "rorty@princeton.us", :html => File.read('myhtml.html'), :list_id => 987
|
64
|
+
# Message with emails and template (with edits & repeats)
|
65
|
+
>> message = Message.create :title => "Title", :subject => "Subject", :from_name => "Rorty", :from_email => "rorty@princeton.us", :template_id => 765, :edits => {:greeting => 'Hi Davidson!'}, :repeats => {:news => ['A good news', 'A bad news'], :emails => 'davidson@some.com davidson@another.com'}
|
66
|
+
>> message.test([44,55,66])
|
67
|
+
>> message.ready # send it now
|
68
|
+
>> message.ready(10.days.from_now)
|
69
|
+
|
31
70
|
* Com modelos (ActiveRecord)
|
32
|
-
|
71
|
+
|
72
|
+
Esta gem é feita para manter um modelo AciveRecord sincronizado com os contatos do Mailee. Para fazer isto, basta colocar o método "sync_with_mailee" em seu modelo. Se o seu modelo se chama "Contact", por exemplo, o código seria este:
|
33
73
|
=code
|
34
74
|
class Contact < ActiveRecord::Base
|
35
75
|
sync_with_mailee
|
36
76
|
end
|
37
|
-
A priori,
|
77
|
+
A priori, a gem espera que você tenha pelo menos os campos de email e optins, e pressupõe que estes campos se chamem "email" e "news". Se os campos da sua tabela não tem estes nomes, você pode fazer o seguinte:
|
38
78
|
=code
|
39
79
|
class Contact < ActiveRecord::Base
|
40
|
-
sync_with_mailee :email => :my_email_column
|
80
|
+
sync_with_mailee :email => :my_email_column, :news => :my_optin_column
|
41
81
|
end
|
42
|
-
Onde "my_email_column" é a coluna que guarda o e-mail na sua tabela.
|
43
|
-
|
82
|
+
Onde "my_email_column" é a coluna que guarda o e-mail na sua tabela e "my_optin_column" o booleano que guarda o optin.
|
83
|
+
A gem também pode manter o nome do seu contato sincronizado, bastando para isto ter um campo "name" que será mapeado por padrão, mas que também pode ser sobrescrito:
|
44
84
|
=code
|
45
85
|
class Contact < ActiveRecord::Base
|
46
|
-
sync_with_mailee :
|
47
|
-
end
|
48
|
-
Por fim, o plugin permite que o cadastro no Mailee seja condicionado a um campo booleano (o padrão é "news"), que corresponde ao "opt-in" (a escolha de receber ou não mensagens) do seu contato. Ou seja, se o valor do campo for false, o plugin não cadastrará o contato no Mailee, e se o contato já estiver cadastrado e o valor deste campo mudar para falso, o contato será descadastrado e _não_ poderá ser mais cadastrado no Mailee (normas de privacidade). Para mudar o campo, basta:
|
49
|
-
=code
|
50
|
-
class Contact < ActiveRecord::Base
|
51
|
-
sync_with_mailee :email => :my_email_column, :name => :my_name_column, :news => :do_you_really_accept_to_receive_our_newsletter
|
86
|
+
sync_with_mailee :name => :my_name_column
|
52
87
|
end
|
88
|
+
Se o valor do campo "news" (ou o que você utilizar para optin) for false, a gem não cadastrará o contato no Mailee. Se o contato já estiver cadastrado e o valor deste campo mudar para falso, o contato será descadastrado e _não_ poderá ser mais cadastrado no Mailee (normas de privacidade). Se ele estiver falso e mudar para verdadeiro, ele irá cadastrá-lo.
|
89
|
+
|
90
|
+
* Com mailers (ActionMailer)
|
91
|
+
|
92
|
+
Esta gem permite que você utilize o Mailee.me como meio de enviar suas mensagens sem precisar configurar um servidor smtp ou algo pareceido.
|
93
|
+
|
94
|
+
Você pode optar por enviar todas as mensagens por ele, ou só as mensagens de determinados mailers. Para a configuração global, adicione a seguinte linha ao seu arquivo de ambiente (config/environments/production.rb ou development.rb):
|
95
|
+
|
96
|
+
= code
|
97
|
+
config.action_mailer.delivery_method = Mailee::Mailer
|
98
|
+
|
99
|
+
Agora, se você quer enviar apenas mensagens de um certo mailer pelo Mailee, basta adicionar o método "send_with_mailee" em cada um:
|
100
|
+
|
101
|
+
= code
|
102
|
+
class Notifications < ActionMailer::Base
|
103
|
+
send_with_mailee
|
104
|
+
...
|
105
|
+
end
|
106
|
+
|
107
|
+
É importante definir o from com o formato completo:
|
108
|
+
|
109
|
+
= code
|
110
|
+
class Notifications < ActionMailer::Base
|
111
|
+
default :from => "Plato <plato@liceum.gr>
|
112
|
+
...
|
113
|
+
end
|
114
|
+
|
115
|
+
Ao enviar uma mensagem, você pode também optar por enviá-la agora ou no futuro:
|
116
|
+
|
117
|
+
= code
|
118
|
+
class Notifications < ActionMailer::Base
|
119
|
+
def signup(client, date=Time.now)
|
120
|
+
mail :date => date, :to => client.email
|
121
|
+
end
|
122
|
+
def feedback(client, date=Time.now)
|
123
|
+
mail :date => date, :to => client.email
|
124
|
+
end
|
125
|
+
end
|
126
|
+
...
|
127
|
+
Notifications.signup(client).deliver
|
128
|
+
Notifications.feedback(client, 3.days.from_now).deliver
|
129
|
+
|
130
|
+
Por fim, ao enviar uma mensagem, a gem adiciona um método que representa a mensagem no Mailee.me, veja:
|
131
|
+
|
132
|
+
= code
|
133
|
+
mail = Notifications.signup(client).deliver
|
134
|
+
mail.mailee_message.id # Retorna o id
|
135
|
+
mail.mailee_message.html # Retorna o html
|
136
|
+
# e assim por diante...
|
137
|
+
|
138
|
+
Isto é útil, pois você já pode monitorar os resultados com este id:
|
139
|
+
|
140
|
+
= code
|
141
|
+
mail = Notifications.signup(client).deliver
|
142
|
+
Mailee::Report.find(mail.mailee_message.id)
|
143
|
+
|
53
144
|
* Tarefas (rake)
|
145
|
+
|
54
146
|
Caso você já tenha itens cadastrados, é necessário adicionar estes contatos ao Mailee antes de mais nada. Para isso execute a tarefa rake:
|
55
147
|
> rake mailee:send CLASS=Contact
|
56
148
|
Onde "Contact" é o nome do seu modelo. Se você quer apenas enviar os contatos a partir de uma determinada data, você pode fazê-lo desta forma:
|
57
149
|
> rake mailee:send CLASS=Contact AFTER=5.days.ago
|
58
150
|
Neste caso, ele vai apenas sincronizar os contatos que foram atualizados (baseado no campo "updated_at") nos últimos 5 dias.
|
59
|
-
|
60
|
-
|
151
|
+
|
152
|
+
== Cuidado!
|
153
|
+
|
154
|
+
A gem utiliza a API REST do Mailee para enviar dados, por isto cuide bem da sua URL - se alguém descobrir isso pode ser ruim. Para saber qual o contato na sua aplicação a gem utiliza um campo disponível no Mailee chamado "internal_id" o qual recebe o "id" da sua tabela na criação. Este id é usado nas atualizações, descadastros e exclusões, então tome (ou avise seu cliente para tomar!) cuidado ao editar este campo na interface do Mailee.
|
61
155
|
|
62
156
|
== Dúvidas?
|
63
157
|
|
64
|
-
Qualquer dúvida, não hesite em falar conosco pelo e-mail suporte@mailee.me.
|
158
|
+
Qualquer dúvida, não hesite em falar conosco pelo e-mail suporte@mailee.me, pelo twitter @maileeme ou pelo IRC #maileeme.
|
data/README.markdown.pt
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
= Mailee - Email marketing para quem entende de tecnologia.
|
2
|
+
==============
|
3
|
+
|
4
|
+
== O problema
|
5
|
+
|
6
|
+
Você está desenvolvendo um sistema (e-commerce, cms, erp...) e o seu cliente solicita a possibilidade de enviar e-mails promocionais, ou notícias, para diversos contatos. Por experiência própria, você sabe que enviar e-mails não é coisa para _scriptkiddies_, e que, de fato, não vale a pena o esforço de desenvolver todo um sistema que faça o envio, garanta a entrega, analise os retornos e também apresente resultados de tudo isso. O problema é que os sistemas que você conhece não permitem uma integração fácil e rápida com seus sistemas em Rails...
|
7
|
+
|
8
|
+
== A solução
|
9
|
+
|
10
|
+
Este plugin tem como objetivo manter os contatos da sua aplicação sincronizados com os contatos do Mailee (www.mailee.me) sem muito esforço. De fato, basta executar o método "sync_with_mailee" no seu modelo (clientes, contatos, pessoas...) que este irá automaticamente realizar as tarefas de inserir, atualizar, excluir e descadastrar via REST. No Mailee, seu cliente poderá então montar as mensagens e enviar para os contatos.
|
11
|
+
|
12
|
+
== Instalação
|
13
|
+
|
14
|
+
* Execute o seguinte comando em sua aplicação Rails:
|
15
|
+
> script/plugin install git@github.com:softa/mailee-api.git
|
16
|
+
* Adicione a seguinte linha de configuração em sua aplicação:
|
17
|
+
Mailee::Config.site = 'http://api.chave.subdominio.wizee.net'
|
18
|
+
O site você descobre entrando no Mailee e indo em Configurações > Integração > REST
|
19
|
+
|
20
|
+
Pronto!
|
21
|
+
|
22
|
+
== Uso
|
23
|
+
|
24
|
+
* Na mão (console)
|
25
|
+
Você pode usar a api do maile "na mão". Basta abrir o console e usar:
|
26
|
+
> ruby script/console
|
27
|
+
>> Contact.find(:all)
|
28
|
+
>> Contact.find(:first)
|
29
|
+
>> Contact.create(:name => 'Bertrand Russell', :email => 'russell@cambridge.edu.uk')
|
30
|
+
Mais exemplos você encontra(rá) na (futura) documentação da API.
|
31
|
+
* Com modelos (ActiveRecord)
|
32
|
+
Este plugin é feito para manter um modelo AciveRecord sincronizado com os contatos do Mailee. Para fazer isto, basta colocar o método "sync_with_mailee" em seu modelo. Se o seu modelo se chama "Contact", por exemplo, o código seria este:
|
33
|
+
=code
|
34
|
+
class Contact < ActiveRecord::Base
|
35
|
+
sync_with_mailee
|
36
|
+
end
|
37
|
+
A priori, o plugin espera que você tenha pelo menos um campo de email e pressupõe que o nome deste campo é "email". Se o campo da sua tabela não tem este nome, você pode fazer o seguinte:
|
38
|
+
=code
|
39
|
+
class Contact < ActiveRecord::Base
|
40
|
+
sync_with_mailee :email => :my_email_column
|
41
|
+
end
|
42
|
+
Onde "my_email_column" é a coluna que guarda o e-mail na sua tabela.
|
43
|
+
O plugin também pode manter o nome do seu contato sincronizado, bastando para isto ter um campo "name" que será mapeado por padrão, mas que também pode ser sobrescrito:
|
44
|
+
=code
|
45
|
+
class Contact < ActiveRecord::Base
|
46
|
+
sync_with_mailee :email => :my_email_column, :name => :my_name_column
|
47
|
+
end
|
48
|
+
Por fim, o plugin permite que o cadastro no Mailee seja condicionado a um campo booleano (o padrão é "news"), que corresponde ao "opt-in" (a escolha de receber ou não mensagens) do seu contato. Ou seja, se o valor do campo for false, o plugin não cadastrará o contato no Mailee, e se o contato já estiver cadastrado e o valor deste campo mudar para falso, o contato será descadastrado e _não_ poderá ser mais cadastrado no Mailee (normas de privacidade). Para mudar o campo, basta:
|
49
|
+
=code
|
50
|
+
class Contact < ActiveRecord::Base
|
51
|
+
sync_with_mailee :email => :my_email_column, :name => :my_name_column, :news => :do_you_really_accept_to_receive_our_newsletter
|
52
|
+
end
|
53
|
+
* Tarefas (rake)
|
54
|
+
Caso você já tenha itens cadastrados, é necessário adicionar estes contatos ao Mailee antes de mais nada. Para isso execute a tarefa rake:
|
55
|
+
> rake mailee:send CLASS=Contact
|
56
|
+
Onde "Contact" é o nome do seu modelo. Se você quer apenas enviar os contatos a partir de uma determinada data, você pode fazê-lo desta forma:
|
57
|
+
> rake mailee:send CLASS=Contact AFTER=5.days.ago
|
58
|
+
Neste caso, ele vai apenas sincronizar os contatos que foram atualizados (baseado no campo "updated_at") nos últimos 5 dias.
|
59
|
+
* Mas... como isso funciona, caso eu precise saber?
|
60
|
+
O plugin utiliza a API REST do Mailee para enviar dados, por isto cuide bem da sua URL - se alguém descobrir isso pode ser ruim. Para saber qual o contato na sua aplicação o plugin utiliza um campo disponível no Mailee chamado "internal_id" o qual recebe o "id" da sua tabela na criação. Este id é usado nas atualizações, descadastros e exclusões, então tome (ou avise seu cliente para tomar!) cuidado ao editar este campo na interface do Mailee.
|
61
|
+
|
62
|
+
== Dúvidas?
|
63
|
+
|
64
|
+
Qualquer dúvida, não hesite em falar conosco pelo e-mail suporte@mailee.me.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.2
|
data/app/Gemfile
CHANGED
data/app/Gemfile.lock
CHANGED
@@ -38,6 +38,7 @@ GEM
|
|
38
38
|
activesupport (>= 2.3.6)
|
39
39
|
mime-types
|
40
40
|
treetop (>= 1.4.5)
|
41
|
+
mailee (0.4.0)
|
41
42
|
mime-types (1.16)
|
42
43
|
polyglot (0.3.1)
|
43
44
|
rack (1.2.1)
|
@@ -69,5 +70,6 @@ PLATFORMS
|
|
69
70
|
ruby
|
70
71
|
|
71
72
|
DEPENDENCIES
|
73
|
+
mailee (= 0.4.0)
|
72
74
|
rails (= 3.0.0)
|
73
75
|
sqlite3-ruby
|
@@ -1 +1 @@
|
|
1
|
-
Mailee::Config.site = '
|
1
|
+
Mailee::Config.site = 'http://api.bdb28c0a0a4a3.softa.mailee.me'
|
data/lib/mailee.rb
CHANGED
@@ -1,280 +1,8 @@
|
|
1
1
|
require 'active_resource'
|
2
|
-
module Mailee
|
3
2
|
|
4
|
-
|
5
|
-
# You can do it in your applications.rb or in a initializar.
|
6
|
-
# It's simple:
|
7
|
-
#
|
8
|
-
# Mailee::Config.site = "http://your.mailee.api.url"
|
9
|
-
class Config < ActiveResource::Base
|
10
|
-
end
|
3
|
+
module Mailee; end
|
11
4
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
# Also, you can subscribe contacts to lists and unsubscribe. In Mailee
|
18
|
-
# unsubscribing a contact is radical: it will be unsubscribed from ALL
|
19
|
-
# lists FOREVER. House rules.
|
20
|
-
#
|
21
|
-
# If you use mailee gem to sync a model, it will always set the internal_id
|
22
|
-
# to your "local" model id and then search based on it to update de remote
|
23
|
-
# record.
|
24
|
-
class Contact < Config
|
25
|
-
def self.find_by_internal_id iid
|
26
|
-
find(:first, :params => {:internal_id => iid})
|
27
|
-
end
|
28
|
-
def self.find_by_email email
|
29
|
-
find(:first, :params => {:email => email})
|
30
|
-
end
|
31
|
-
def self.search keyword, page=1
|
32
|
-
find(:all, :params => {:page => page, :by_keyword => keyword })
|
33
|
-
end
|
34
|
-
def unsubscribe(data={})
|
35
|
-
#E.g. data --> {:reason => 'Trip to nowhere', :spam => false}
|
36
|
-
put(:unsubscribe, :unsubscribe => {:reason => 'Motivo não especificado'}.merge(data))
|
37
|
-
end
|
38
|
-
def subscribe(list)
|
39
|
-
put(:subscribe, :list => {:name => list})
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# The List class gives you default access to your lists (all, first, create, update, destroy)
|
44
|
-
class List < Config
|
45
|
-
end
|
46
|
-
|
47
|
-
# The Template class gives you default access to your templates (all, first, create, update, destroy)
|
48
|
-
class Template < Config
|
49
|
-
end
|
50
|
-
|
51
|
-
# The Quick class allows you to import contacts to mailee just like
|
52
|
-
# in the interface
|
53
|
-
#
|
54
|
-
# USAGE:
|
55
|
-
#
|
56
|
-
# # Emails only
|
57
|
-
# Mailee::Quick.import("witt@cambridge.uk dick@princeton.edu")
|
58
|
-
#
|
59
|
-
# # Names and emails (needs line breaks)
|
60
|
-
# Mailee::Quick.import("witt@cambridge.uk, Wittgenstein\ndick@princeton.edu, Rorty")
|
61
|
-
#
|
62
|
-
# # Signatures (gmail style)
|
63
|
-
# Mailee::Quick.import('"Wittgenstein" <witt@cambridge.uk>,
|
64
|
-
# "Rorty" <dick@princeton.edu.us>')
|
65
|
-
class Quick < Config
|
66
|
-
self.collection_name = "quick"
|
67
|
-
def self.import contacts
|
68
|
-
create :contacts => contacts
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# The Message class is where the fun happens.
|
73
|
-
#
|
74
|
-
# USAGE:
|
75
|
-
#
|
76
|
-
# # Creating a message (still a draft):
|
77
|
-
# message = Mailee::Message.create :title => "TITLE", :subject => "SUBJ", :from_name => "NAME", :from_email => "your@email.com", :html => "<h1>Hello</h1>", :list_id => 666
|
78
|
-
# # Sending tests. 33, 44 and 55 are contact's ids.
|
79
|
-
# message.test([33,44,55]).should_not be nil
|
80
|
-
# # Sending the message now ...
|
81
|
-
# message.ready
|
82
|
-
# # ... or sending the message 10 days from now
|
83
|
-
# message.ready(10.days.from_now)
|
84
|
-
class Message < Config
|
85
|
-
def test contacts
|
86
|
-
put(:test, :contacts => contacts)
|
87
|
-
end
|
88
|
-
def ready date=nil, hour=0
|
89
|
-
if date && date.is_a?(Date) && date > Time.now
|
90
|
-
put(:ready, :when => 'after', :after => {:date => date.strftime("%d/%m/%Y"), :hour => date.strftime('%H')})
|
91
|
-
else
|
92
|
-
put(:ready, :when => 'now')
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# The Report class is still beta. It can return the results of a
|
98
|
-
# message - total deliveries, accesses and returns. There are also
|
99
|
-
# methods for getting accesses, unsubscribes and returns in "real time".
|
100
|
-
class Report < Config
|
101
|
-
end
|
102
|
-
|
103
|
-
# The Mailer class is responsible for making the mailee gem ActionMailer
|
104
|
-
# compatible.
|
105
|
-
#
|
106
|
-
# USAGE:
|
107
|
-
#
|
108
|
-
# If you want to use Mailee to send all your systems emails, simply
|
109
|
-
# configure the environment (dev or prod) like this:
|
110
|
-
#
|
111
|
-
# config.action_mailer.delivery_method = Mailee::Mailer
|
112
|
-
#
|
113
|
-
# But if you wanna send just a certain mailer with Mailee, add
|
114
|
-
# "send_with_mailee" on a per mailer basis
|
115
|
-
#
|
116
|
-
# class Notifications < ActionMailer::Base
|
117
|
-
# send_with_mailee
|
118
|
-
# end
|
119
|
-
#
|
120
|
-
# One important thing, is to add the sender's name to the default "from" in
|
121
|
-
# your mailer, this way:
|
122
|
-
#
|
123
|
-
# default :from => "Your name <your@email.com.br>"
|
124
|
-
#
|
125
|
-
# And don't forget to config your domain SPF!
|
126
|
-
class Mailer
|
127
|
-
|
128
|
-
def initialize config
|
129
|
-
end
|
130
|
-
def deliver! mail
|
131
|
-
from_name = mail.header['from'].to_s.scan(/(.+?) <.+?>$/).to_s
|
132
|
-
message = Mailee::Message.create :title => mail.subject, :subject => mail.subject, :from_name => from_name, :from_email => mail.from.first, :emails => mail.to.join(' '), :html => mail.body.to_s
|
133
|
-
message.ready(mail.date)
|
134
|
-
self
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
module Send
|
139
|
-
|
140
|
-
def self.included(base) # :nodoc:
|
141
|
-
base.extend ClassMethods
|
142
|
-
end
|
143
|
-
|
144
|
-
module ClassMethods
|
145
|
-
def send_with_mailee
|
146
|
-
puts "1"
|
147
|
-
self.delivery_method = Mailee::Mailer
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
module Sync
|
154
|
-
|
155
|
-
def self.included(base) # :nodoc:
|
156
|
-
base.extend ClassMethods
|
157
|
-
end
|
158
|
-
|
159
|
-
module ClassMethods
|
160
|
-
def sync_with_mailee(options = {})
|
161
|
-
unless syncd? # don't let AR call this twice
|
162
|
-
cattr_accessor :sync_options
|
163
|
-
after_create :create_in_mailee
|
164
|
-
after_update :update_in_mailee
|
165
|
-
after_destroy :destroy_in_mailee
|
166
|
-
self.sync_options = {:email => :email, :name => :name, :news => :news}.merge(options) #options[:with] || :deleted_at
|
167
|
-
unless self.column_names.include?(self.sync_options[:email].to_s)
|
168
|
-
raise "Campo #{sync_options[:email]} não existe em #{new.class}."
|
169
|
-
end
|
170
|
-
unless self.column_names.include?(self.sync_options[:name].to_s)
|
171
|
-
self.sync_options[:name] = nil
|
172
|
-
end
|
173
|
-
unless self.column_names.include?(self.sync_options[:news].to_s)
|
174
|
-
self.sync_options[:news] = nil
|
175
|
-
end
|
176
|
-
end
|
177
|
-
include InstanceMethods
|
178
|
-
end
|
179
|
-
|
180
|
-
def syncd?
|
181
|
-
self.included_modules.include?(InstanceMethods)
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
|
186
|
-
module InstanceMethods #:nodoc:
|
187
|
-
|
188
|
-
def self.included(base) # :nodoc:
|
189
|
-
base.extend ClassMethods
|
190
|
-
end
|
191
|
-
|
192
|
-
def create_in_mailee
|
193
|
-
return if( sync_options[:news] and ! send(sync_options[:news])) # Não cria se houver o campo booleano e ele for falso
|
194
|
-
self.class.benchmark "Criando contato no Mailee" do
|
195
|
-
contact = Mailee::Contact.new
|
196
|
-
contact.internal_id = id
|
197
|
-
contact.email = send(sync_options[:email])
|
198
|
-
contact.name = send(sync_options[:name]) if sync_options[:name]
|
199
|
-
contact.save
|
200
|
-
end
|
201
|
-
rescue
|
202
|
-
logger.warn "MAILEE-API: Falhou ao criar o contato #{id} no Mailee"
|
203
|
-
end
|
204
|
-
|
205
|
-
def update_in_mailee
|
206
|
-
self.class.benchmark "Atualizando contato no Mailee" do
|
207
|
-
contact = Mailee::Contact.find_by_internal_id id
|
208
|
-
if contact
|
209
|
-
#Se o contato existe e o booleano foi desmarcado, realiza um UNSUBSCRIBE
|
210
|
-
if sync_options[:news] and (! send(sync_options[:news]))
|
211
|
-
unsubscribe_in_mailee(contact)
|
212
|
-
else
|
213
|
-
contact.email = send(sync_options[:email])
|
214
|
-
contact.name = send(sync_options[:name]) if sync_options[:name]
|
215
|
-
contact.save
|
216
|
-
end
|
217
|
-
else
|
218
|
-
create_in_mailee # Se não achou o contato tem q inserir.
|
219
|
-
end
|
220
|
-
end
|
221
|
-
rescue
|
222
|
-
logger.warn "MAILEE-API: Falhou ao atualizar o contato #{id} no Mailee"
|
223
|
-
end
|
224
|
-
|
225
|
-
def destroy_in_mailee contact=nil
|
226
|
-
self.class.benchmark "Excluindo contato no Mailee" do
|
227
|
-
contact ||= Mailee::Contact.find_by_internal_id id
|
228
|
-
contact.destroy
|
229
|
-
end
|
230
|
-
rescue
|
231
|
-
logger.warn "MAILEE-API: Falhou ao excluir o contato #{id} no Mailee"
|
232
|
-
end
|
233
|
-
|
234
|
-
def unsubscribe_in_mailee contact=nil
|
235
|
-
self.class.benchmark "Descadastrando contato no Mailee" do
|
236
|
-
contact ||= Mailee::Contact.find_by_internal_id id
|
237
|
-
contact.unsubscribe
|
238
|
-
end
|
239
|
-
rescue
|
240
|
-
logger.warn "MAILEE-API: Falhou ao descadastrar o contato #{id} no Mailee"
|
241
|
-
end
|
242
|
-
|
243
|
-
module ClassMethods
|
244
|
-
# Sincroniza todos os itens do modelo com Mailee.
|
245
|
-
# Permite que se passe um datetime para enviar apenas os contatos atualizados depois desta data
|
246
|
-
# Permite o uso de um bloco, que receberá o item do modelo e o item do Mailee associado a este.
|
247
|
-
# Ex: Contact.send_all_to_mailee{|i,im| im.address = i.endereco; im.save }
|
248
|
-
# Importante: este método apenas envia os contatos, mas não recebe.
|
249
|
-
# Para receber contatos, o ideal é fazer uma exportação no Mailee e realizar uma importação deste arquivo CSV no seu sistema.
|
250
|
-
|
251
|
-
def send_all_to_mailee(after=nil)
|
252
|
-
items = after ? all(:conditions => ["updated_at >= ?", after]) : all
|
253
|
-
for item in items
|
254
|
-
begin
|
255
|
-
contact = Mailee::Contact.find_by_internal_id item.id
|
256
|
-
if contact and sync_options[:news] and ! item.send(sync_options[:news])
|
257
|
-
contact.unsubscribe
|
258
|
-
yield item, contact if block_given?
|
259
|
-
next
|
260
|
-
end
|
261
|
-
unless contact
|
262
|
-
next if sync_options[:news] and ! item.send(sync_options[:news])
|
263
|
-
contact = Mailee::Contact.new
|
264
|
-
contact.internal_id = item.id
|
265
|
-
end
|
266
|
-
contact.email = item.send(sync_options[:email])
|
267
|
-
contact.name = item.send(sync_options[:name]) if sync_options[:name]
|
268
|
-
contact.save
|
269
|
-
yield item, contact if block_given?
|
270
|
-
rescue
|
271
|
-
logger.warn "MAILEE-API: Falhou ao enviar o contato #{id} ao Mailee"
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
ActiveRecord::Base.send(:include, Mailee::Sync) if defined?(ActiveRecord)
|
280
|
-
ActionMailer::Base.send(:include, Mailee::Send) if defined?(ActionMailer)
|
5
|
+
require 'mailee/active_resource'
|
6
|
+
require 'mailee/railties' if defined?(Rails)
|
7
|
+
require 'mailee/active_record' if defined?(ActiveRecord)
|
8
|
+
require 'mailee/action_mailer' if defined?(ActionMailer)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Mailee
|
2
|
+
# The Mailer class is responsible for making the mailee gem ActionMailer
|
3
|
+
# compatible.
|
4
|
+
#
|
5
|
+
# USAGE:
|
6
|
+
#
|
7
|
+
# If you want to use Mailee to send all your systems emails, simply
|
8
|
+
# configure the environment (dev or prod) like this:
|
9
|
+
#
|
10
|
+
# config.action_mailer.delivery_method = Mailee::Mailer
|
11
|
+
#
|
12
|
+
# But if you wanna send just a certain mailer with Mailee, add
|
13
|
+
# "send_with_mailee" on a per mailer basis
|
14
|
+
#
|
15
|
+
# class Notifications < ActionMailer::Base
|
16
|
+
# send_with_mailee
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# One important thing, is to add the sender's name to the default "from" in
|
20
|
+
# your mailer, this way:
|
21
|
+
#
|
22
|
+
# default :from => "Your name <your@email.com.br>"
|
23
|
+
#
|
24
|
+
# And don't forget to config your domain SPF!
|
25
|
+
class Mailer
|
26
|
+
|
27
|
+
def initialize config
|
28
|
+
end
|
29
|
+
def deliver! mail
|
30
|
+
from_name = mail.header['from'].to_s.scan(/(.+?) <.+?>$/).to_s
|
31
|
+
message = Mailee::Message.create :title => mail.subject, :subject => mail.subject, :from_name => from_name, :from_email => mail.from.first, :emails => mail.to.join(' '), :html => mail.body.to_s
|
32
|
+
result = message.ready(mail.date)
|
33
|
+
mail.instance_eval{ self.class.send('attr_accessor', :mailee_message); self.mailee_message = result }
|
34
|
+
self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Send
|
39
|
+
|
40
|
+
def self.included(base) # :nodoc:
|
41
|
+
base.extend ClassMethods
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
def send_with_mailee
|
46
|
+
self.delivery_method = Mailee::Mailer
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
ActionMailer::Base.send(:include, Mailee::Send)
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# The Sync module is responsible for keeping a model syncd with Mailee.
|
2
|
+
# It's behaviour is still too rails-twooish. But soon I'll make it more
|
3
|
+
# treeish using Railties and stuff. But it works.
|
4
|
+
#
|
5
|
+
# All you need in your model are two fields, one for the email and one
|
6
|
+
# for the optin, wich is by default called "news". The name field is
|
7
|
+
# optional but encouraged.
|
8
|
+
#
|
9
|
+
# USAGE
|
10
|
+
#
|
11
|
+
# # Simple example
|
12
|
+
# class Client < ActiveRecord::Base
|
13
|
+
# sync_with_mailee
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # Super hyper brainfuck complex example
|
17
|
+
# class Client < ActiveRecord::Base
|
18
|
+
# sync_with_mailee :email => :email_field, :name => :name_field, :news => :news_field
|
19
|
+
# end
|
20
|
+
|
21
|
+
module Mailee
|
22
|
+
module Sync
|
23
|
+
|
24
|
+
def self.included(base) # :nodoc:
|
25
|
+
base.extend ClassMethods
|
26
|
+
end
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
def sync_with_mailee(options = {})
|
30
|
+
unless syncd? # don't let AR call this twice
|
31
|
+
cattr_accessor :sync_options
|
32
|
+
after_create :create_in_mailee
|
33
|
+
after_update :update_in_mailee
|
34
|
+
after_destroy :destroy_in_mailee
|
35
|
+
self.sync_options = {:email => :email, :name => :name, :news => :news}.merge(options)
|
36
|
+
unless self.column_names.include?(self.sync_options[:email].to_s)
|
37
|
+
raise "Campo #{sync_options[:email]} não existe em #{new.class}."
|
38
|
+
end
|
39
|
+
unless self.column_names.include?(self.sync_options[:name].to_s)
|
40
|
+
self.sync_options[:name] = nil
|
41
|
+
end
|
42
|
+
unless self.column_names.include?(self.sync_options[:news].to_s)
|
43
|
+
self.sync_options[:news] = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
include InstanceMethods
|
47
|
+
end
|
48
|
+
|
49
|
+
def syncd?
|
50
|
+
self.included_modules.include?(InstanceMethods)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
module InstanceMethods #:nodoc:
|
56
|
+
|
57
|
+
def self.included(base) # :nodoc:
|
58
|
+
base.extend ClassMethods
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_in_mailee
|
62
|
+
return if( sync_options[:news] and ! send(sync_options[:news])) # Não cria se houver o campo booleano e ele for falso
|
63
|
+
self.class.benchmark "Criando contato no Mailee" do
|
64
|
+
contact = Mailee::Contact.new
|
65
|
+
contact.internal_id = id
|
66
|
+
contact.email = send(sync_options[:email])
|
67
|
+
contact.name = send(sync_options[:name]) if sync_options[:name]
|
68
|
+
contact.save
|
69
|
+
end
|
70
|
+
rescue
|
71
|
+
logger.warn "MAILEE-API: Falhou ao criar o contato #{id} no Mailee"
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_in_mailee
|
75
|
+
self.class.benchmark "Atualizando contato no Mailee" do
|
76
|
+
contact = Mailee::Contact.find_by_internal_id id
|
77
|
+
if contact
|
78
|
+
#Se o contato existe e o booleano foi desmarcado, realiza um UNSUBSCRIBE
|
79
|
+
if sync_options[:news] and (! send(sync_options[:news]))
|
80
|
+
unsubscribe_in_mailee(contact)
|
81
|
+
else
|
82
|
+
contact.email = send(sync_options[:email])
|
83
|
+
contact.name = send(sync_options[:name]) if sync_options[:name]
|
84
|
+
contact.save
|
85
|
+
end
|
86
|
+
else
|
87
|
+
create_in_mailee # Se não achou o contato tem q inserir.
|
88
|
+
end
|
89
|
+
end
|
90
|
+
rescue
|
91
|
+
logger.warn "MAILEE-API: Falhou ao atualizar o contato #{id} no Mailee"
|
92
|
+
end
|
93
|
+
|
94
|
+
def destroy_in_mailee contact=nil
|
95
|
+
self.class.benchmark "Excluindo contato no Mailee" do
|
96
|
+
contact ||= Mailee::Contact.find_by_internal_id id
|
97
|
+
contact.destroy
|
98
|
+
end
|
99
|
+
rescue
|
100
|
+
logger.warn "MAILEE-API: Falhou ao excluir o contato #{id} no Mailee"
|
101
|
+
end
|
102
|
+
|
103
|
+
def unsubscribe_in_mailee contact=nil
|
104
|
+
self.class.benchmark "Descadastrando contato no Mailee" do
|
105
|
+
contact ||= Mailee::Contact.find_by_internal_id id
|
106
|
+
contact.unsubscribe
|
107
|
+
end
|
108
|
+
rescue
|
109
|
+
logger.warn "MAILEE-API: Falhou ao descadastrar o contato #{id} no Mailee"
|
110
|
+
end
|
111
|
+
|
112
|
+
module ClassMethods
|
113
|
+
|
114
|
+
# Sends all items from the model to Mailee.
|
115
|
+
# Allows passing a datetime to send only contacts updated after.
|
116
|
+
# Also allows the use of a block, wich will receive the record of
|
117
|
+
# the model and the record from Mailee:
|
118
|
+
#
|
119
|
+
# Contact.send_all_to_mailee{|i,im| im.address = i.endereco; im.save }
|
120
|
+
#
|
121
|
+
# IMPORTANT:
|
122
|
+
# This method only _sends_ contacts. It does not receives 'em.
|
123
|
+
# If you need to receive contacts, for now the best way is to export in
|
124
|
+
# Mailee's web interface and import in your app.
|
125
|
+
def send_all_to_mailee(after=nil)
|
126
|
+
items = after ? all(:conditions => ["updated_at >= ?", after]) : all
|
127
|
+
for item in items
|
128
|
+
begin
|
129
|
+
contact = Mailee::Contact.find_by_internal_id item.id
|
130
|
+
if contact and sync_options[:news] and ! item.send(sync_options[:news])
|
131
|
+
contact.unsubscribe
|
132
|
+
yield item, contact if block_given?
|
133
|
+
next
|
134
|
+
end
|
135
|
+
unless contact
|
136
|
+
next if sync_options[:news] and ! item.send(sync_options[:news])
|
137
|
+
contact = Mailee::Contact.new
|
138
|
+
contact.internal_id = item.id
|
139
|
+
end
|
140
|
+
contact.email = item.send(sync_options[:email])
|
141
|
+
contact.name = item.send(sync_options[:name]) if sync_options[:name]
|
142
|
+
contact.save
|
143
|
+
yield item, contact if block_given?
|
144
|
+
rescue
|
145
|
+
logger.warn "MAILEE-API: Falhou ao enviar o contato #{id} ao Mailee"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
ActiveRecord::Base.send(:include, Mailee::Sync) if defined?(ActiveRecord)
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Mailee
|
2
|
+
|
3
|
+
# The Config class is used to set your api url.
|
4
|
+
# You can do it in your applications.rb or in a initializer.
|
5
|
+
# It's simple:
|
6
|
+
#
|
7
|
+
# Mailee::Config.site = "http://your.mailee.api.url"
|
8
|
+
class Config < ActiveResource::Base
|
9
|
+
end
|
10
|
+
|
11
|
+
# The Contact class gives you default access to your contacts (all,
|
12
|
+
# first, create, update, destroy) plus some facilities, like searching
|
13
|
+
# contacts by email, keyword (a smart search), signature (name & email)
|
14
|
+
# and internal id.
|
15
|
+
#
|
16
|
+
# Also, you can subscribe contacts to lists and unsubscribe. In Mailee
|
17
|
+
# unsubscribing a contact is radical: it will be unsubscribed from ALL
|
18
|
+
# lists FOREVER. House rules.
|
19
|
+
#
|
20
|
+
# If you use mailee gem to sync a model, it will always set the internal_id
|
21
|
+
# to your "local" model id and then search based on it to update de remote
|
22
|
+
# record.
|
23
|
+
class Contact < Config
|
24
|
+
def self.find_by_internal_id iid
|
25
|
+
find(:first, :params => {:internal_id => iid})
|
26
|
+
end
|
27
|
+
def self.find_by_email email
|
28
|
+
find(:first, :params => {:email => email})
|
29
|
+
end
|
30
|
+
def self.search keyword, page=1
|
31
|
+
find(:all, :params => {:page => page, :by_keyword => keyword })
|
32
|
+
end
|
33
|
+
def unsubscribe(data={})
|
34
|
+
#E.g. data --> {:reason => 'Trip to nowhere', :spam => false}
|
35
|
+
put(:unsubscribe, :unsubscribe => {:reason => 'Motivo não especificado'}.merge(data))
|
36
|
+
end
|
37
|
+
def subscribe(list)
|
38
|
+
put(:subscribe, :list => {:name => list})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# The List class gives you default access to your lists (all, first, create, update, destroy)
|
43
|
+
class List < Config
|
44
|
+
end
|
45
|
+
|
46
|
+
# The Template class gives you default access to your templates (all, first, create, update, destroy)
|
47
|
+
class Template < Config
|
48
|
+
end
|
49
|
+
|
50
|
+
# The Quick class allows you to import contacts to mailee just like
|
51
|
+
# in the interface
|
52
|
+
#
|
53
|
+
# USAGE:
|
54
|
+
#
|
55
|
+
# # Emails only
|
56
|
+
# Mailee::Quick.import("witt@cambridge.uk dick@princeton.edu")
|
57
|
+
#
|
58
|
+
# # Names and emails (needs line breaks)
|
59
|
+
# Mailee::Quick.import("witt@cambridge.uk, Wittgenstein\ndick@princeton.edu, Rorty")
|
60
|
+
#
|
61
|
+
# # Signatures (gmail style)
|
62
|
+
# Mailee::Quick.import('"Wittgenstein" <witt@cambridge.uk>,
|
63
|
+
# "Rorty" <dick@princeton.edu.us>')
|
64
|
+
class Quick < Config
|
65
|
+
self.collection_name = "quick"
|
66
|
+
def self.import contacts
|
67
|
+
create :contacts => contacts
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# The Message class is where the fun happens.
|
72
|
+
#
|
73
|
+
# USAGE:
|
74
|
+
#
|
75
|
+
# # Creating a message (still a draft):
|
76
|
+
# message = Mailee::Message.create :title => "TITLE", :subject => "SUBJ", :from_name => "NAME", :from_email => "your@email.com", :html => "<h1>Hello</h1>", :list_id => 666
|
77
|
+
# # Sending tests. 33, 44 and 55 are contact's ids.
|
78
|
+
# message.test([33,44,55]).should_not be nil
|
79
|
+
# # Sending the message now ...
|
80
|
+
# message.ready
|
81
|
+
# # ... or sending the message 10 days from now
|
82
|
+
# message.ready(10.days.from_now)
|
83
|
+
class Message < Config
|
84
|
+
def test contacts
|
85
|
+
put(:test, :contacts => contacts)
|
86
|
+
end
|
87
|
+
def ready date=nil, hour=0
|
88
|
+
if date && date.is_a?(Date) && date > Time.now
|
89
|
+
put(:ready, :when => 'after', :after => {:date => date.strftime("%d/%m/%Y"), :hour => date.strftime('%H')})
|
90
|
+
else
|
91
|
+
put(:ready, :when => 'now')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# The Report class is still beta. It can return the results of a
|
97
|
+
# message - total deliveries, accesses and returns. There are also
|
98
|
+
# methods for getting accesses, unsubscribes and returns in "real time".
|
99
|
+
class Report < Config
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/actions'
|
3
|
+
|
4
|
+
# = Mailee Railtie
|
5
|
+
#
|
6
|
+
# Creates a new railtie in order to add the mailee_rails:setup generator.
|
7
|
+
class MaileeRails < Rails::Railtie
|
8
|
+
|
9
|
+
# Creates the mailee:rails:setup generator. This generator creates an initializer
|
10
|
+
# called "mailee.rb" by asking the user his api URL, and defining it to
|
11
|
+
# Mailee::Config.site attribute wich makes all that ActiveResource stuff works.
|
12
|
+
class Setup < Rails::Generators::Base
|
13
|
+
include Rails::Generators::Actions
|
14
|
+
def create
|
15
|
+
puts "Please enter your api URL:"
|
16
|
+
attempts = 0
|
17
|
+
url = readline.gsub(/\n/,'').gsub(/\s+/, '')
|
18
|
+
while url !~ /^http:\/\/api\.[a-f0-9]{13}\.[a-z\-]+?\.mailee\.me$/
|
19
|
+
attempts += 1
|
20
|
+
if attempts < 3
|
21
|
+
puts "Invalid URL. Please try again:"
|
22
|
+
url = readline.gsub(/\n/,'').gsub(/\s+/, '')
|
23
|
+
else
|
24
|
+
puts "I think need support. Please talk to us on IRC (#maileeme) or send an email to suporte@mailee.me"
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
end
|
28
|
+
initializer("mailee.rb") do
|
29
|
+
"Mailee::Config.site = '#{url}'"
|
30
|
+
end
|
31
|
+
puts "*** Keep your key top secret, ok?"
|
32
|
+
puts "*** If anything goes wrong, reach us on IRC (#mailee) or by email on suporte@mailee.me"
|
33
|
+
puts "*** Thanks for using Mailee.me"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/mailee.gemspec
CHANGED
@@ -5,16 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mailee}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Juan Maiz"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-08}
|
13
13
|
s.description = %q{Permite sincronizar automaticamente seus modelos com o Mailee.me, inclusive com gerenciamento de optin.}
|
14
14
|
s.email = %q{suporte@mailee.me}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.markdown",
|
18
|
+
"README.markdown.pt",
|
18
19
|
"README.rdoc"
|
19
20
|
]
|
20
21
|
s.files = [
|
@@ -77,11 +78,17 @@ Gem::Specification.new do |s|
|
|
77
78
|
"init.rb",
|
78
79
|
"install.rb",
|
79
80
|
"lib/mailee.rb",
|
81
|
+
"lib/mailee/action_mailer.rb",
|
82
|
+
"lib/mailee/active_record.rb",
|
83
|
+
"lib/mailee/active_resource.rb",
|
84
|
+
"lib/mailee/railties.rb",
|
80
85
|
"mailee.gemspec",
|
81
86
|
"pkg/mailee-0.1.0.gem",
|
82
87
|
"pkg/mailee-0.1.1.gem",
|
83
88
|
"pkg/mailee-0.1.2.gem",
|
89
|
+
"spec/am_spec_helper.rb",
|
84
90
|
"spec/ar_spec_helper.rb",
|
91
|
+
"spec/mailee-api-am.rb",
|
85
92
|
"spec/mailee-api-ar.rb",
|
86
93
|
"spec/mailee-api.rb",
|
87
94
|
"spec/spec.opts",
|
@@ -94,7 +101,9 @@ Gem::Specification.new do |s|
|
|
94
101
|
s.rubygems_version = %q{1.3.7}
|
95
102
|
s.summary = %q{Gem de integração do Mailee.me}
|
96
103
|
s.test_files = [
|
97
|
-
"spec/
|
104
|
+
"spec/am_spec_helper.rb",
|
105
|
+
"spec/ar_spec_helper.rb",
|
106
|
+
"spec/mailee-api-am.rb",
|
98
107
|
"spec/mailee-api-ar.rb",
|
99
108
|
"spec/mailee-api.rb",
|
100
109
|
"spec/spec_helper.rb"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'action_mailer'
|
5
|
+
require 'mailee'
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/autorun'
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
end
|
11
|
+
|
12
|
+
class Foo < ActionMailer::Base
|
13
|
+
|
14
|
+
send_with_mailee
|
15
|
+
|
16
|
+
default :from => "Maiz <maiz@softa.com.br>"
|
17
|
+
|
18
|
+
def bar(date=Time.now)
|
19
|
+
@greeting = "Hi"
|
20
|
+
mail :date => date, :to => ["juanmaiz@gmail.com"]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/am_spec_helper')
|
2
|
+
|
3
|
+
describe "Mailee" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Mailee::Config.site = "http://api.bdb28c0a0a4a3.softa.server:3000"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should respond to send_with_mailee" do
|
10
|
+
ActionMailer::Base.should respond_to(:send_with_mailee)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should use Mailee::Mailer as the delivery method" do
|
14
|
+
Foo.delivery_method.should be(Mailee::Mailer)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should deliver" do
|
18
|
+
result = Foo.bar.deliver
|
19
|
+
result.should_not be(false)
|
20
|
+
result.class.should be(Mail::Message)
|
21
|
+
result.delivery_method.class.should be(Mailee::Mailer)
|
22
|
+
result.mailee_message.class.should be(Mailee::Message)
|
23
|
+
result.mailee_message.id.should_not be(nil)
|
24
|
+
result.mailee_message.status.should_not be(4)
|
25
|
+
result.mailee_message.title.should_not be('Foo')
|
26
|
+
result.mailee_message.subject.should_not be('Foo')
|
27
|
+
result.mailee_message.from_name.should_not be('Maiz')
|
28
|
+
result.mailee_message.from_email.should_not be('maiz@softa.com.br')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/mailee-api-ar.rb
CHANGED
@@ -6,7 +6,12 @@ describe "Mailee" do
|
|
6
6
|
Mailee::Config.site = "http://api.bdb28c0a0a4a3.softa.server:3000"
|
7
7
|
@moment = Time.now.strftime('%Y%m%d%H%M%S')
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
|
+
it "should respond to sync_with_mailee" do
|
11
|
+
ActiveRecord::Base.should respond_to(:sync_with_mailee)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
10
15
|
it "should create if news is checked" do
|
11
16
|
foo = Foo.create :name => "rest_test_foo_#{@moment}", :email => "rest_test_foo_#{@moment}@test.com", :news => true
|
12
17
|
found = Mailee::Contact.find_by_email("rest_test_foo_#{@moment}@test.com")
|
data/spec/mailee-api.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Juan Maiz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-08 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,6 +28,7 @@ extensions: []
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- LICENSE
|
30
30
|
- README.markdown
|
31
|
+
- README.markdown.pt
|
31
32
|
- README.rdoc
|
32
33
|
files:
|
33
34
|
- LICENSE
|
@@ -89,16 +90,23 @@ files:
|
|
89
90
|
- init.rb
|
90
91
|
- install.rb
|
91
92
|
- lib/mailee.rb
|
93
|
+
- lib/mailee/action_mailer.rb
|
94
|
+
- lib/mailee/active_record.rb
|
95
|
+
- lib/mailee/active_resource.rb
|
96
|
+
- lib/mailee/railties.rb
|
92
97
|
- mailee.gemspec
|
93
98
|
- pkg/mailee-0.1.0.gem
|
94
99
|
- pkg/mailee-0.1.1.gem
|
95
100
|
- pkg/mailee-0.1.2.gem
|
101
|
+
- spec/am_spec_helper.rb
|
96
102
|
- spec/ar_spec_helper.rb
|
103
|
+
- spec/mailee-api-am.rb
|
97
104
|
- spec/mailee-api-ar.rb
|
98
105
|
- spec/mailee-api.rb
|
99
106
|
- spec/spec.opts
|
100
107
|
- spec/spec_helper.rb
|
101
108
|
- tasks/mailee_tasks.rake
|
109
|
+
- README.markdown.pt
|
102
110
|
has_rdoc: true
|
103
111
|
homepage: http://help.mailee.me/integration_rails.html
|
104
112
|
licenses: []
|
@@ -134,7 +142,9 @@ signing_key:
|
|
134
142
|
specification_version: 3
|
135
143
|
summary: "Gem de integra\xC3\xA7\xC3\xA3o do Mailee.me"
|
136
144
|
test_files:
|
145
|
+
- spec/am_spec_helper.rb
|
137
146
|
- spec/ar_spec_helper.rb
|
147
|
+
- spec/mailee-api-am.rb
|
138
148
|
- spec/mailee-api-ar.rb
|
139
149
|
- spec/mailee-api.rb
|
140
150
|
- spec/spec_helper.rb
|