lettr 1.0.1 → 1.0.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.md +74 -3
- data/Rakefile +13 -0
- data/lib/lettr.rb +1 -1
- data/lib/lettr/action_mailer.rb +16 -7
- data/lib/lettr/api_mailing.rb +3 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,14 +1,47 @@
|
|
1
1
|
# Lettr
|
2
2
|
Deliver your Emails inside your application through the lettr.de API.
|
3
3
|
|
4
|
-
##
|
5
|
-
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
$ gem install lettr
|
7
|
+
|
8
|
+
If you want to use lettr inside a Rails 2.x application just drop the following line into you config/environment.rb
|
9
|
+
|
10
|
+
config.gem 'lettr'
|
11
|
+
|
12
|
+
For Rails 3.x or if you use Bundler drop the following line into your Gemfile:
|
13
|
+
|
14
|
+
gem 'lettr'
|
15
|
+
|
16
|
+
NOTE: In a Rails 3 Application you currently cant use Delivery Method nor Lettr::Mailer.
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
There are some configuration options you can provide either inside config/environment.rb or config/environments/$RAILS_ENV.rb or create an initializer in config/initializers.
|
20
|
+
At least you have to provide your lettr login credentials:
|
21
|
+
|
22
|
+
config/environment.rb:
|
23
|
+
config.after_initialize do
|
24
|
+
Lettr.credentials = { :user => 'tea_moe', :pass => 'iwonttellyou' }
|
25
|
+
end
|
26
|
+
|
27
|
+
OR
|
28
|
+
|
29
|
+
config/initializers/lettr.rb
|
30
|
+
Lettr.credentials = { :user => 'tea_moe', :pass => 'iwonttellyou' }
|
31
|
+
|
32
|
+
Additional configuration options include:
|
33
|
+
Lettr.protocol
|
34
|
+
Lettr.host
|
35
|
+
but for most use cases the defaults are fine, so you dont have to provide them.
|
36
|
+
|
37
|
+
## Usage (EMail delivery)
|
38
|
+
There are currently several ways of using this gem.
|
6
39
|
|
7
40
|
### Delivery Method
|
8
41
|
Just set the Delivery Method of ActionMailer to :lettr, and all Mailings from Action Mailer will be delivered through our API.
|
9
42
|
|
10
43
|
config.action_mailer.delivery_method = :lettr
|
11
|
-
|
44
|
+
### OR
|
12
45
|
### Lettr::Mailer
|
13
46
|
Let your mailer class inherit from Lettr::Mailer instead of ActionMailer::Base.
|
14
47
|
|
@@ -22,10 +55,12 @@ Let your mailer class inherit from Lettr::Mailer instead of ActionMailer::Base.
|
|
22
55
|
end
|
23
56
|
end
|
24
57
|
|
58
|
+
### OR
|
25
59
|
### Manual Mailing
|
26
60
|
|
27
61
|
Lettr.test_mail(:recipient => 'tg@digineo.de', :subject => 'hi', :test => 'some text', :html => 'some html').deliver
|
28
62
|
|
63
|
+
### OR
|
29
64
|
### With templates stored at lettr.de
|
30
65
|
|
31
66
|
#### and a hash
|
@@ -33,6 +68,7 @@ Provide a hash containing the variables, that you used in your template.
|
|
33
68
|
|
34
69
|
Lettr.test_mail(:test => { :variable_1 => 'foo', :variable_2 => 'bar' }).deliver
|
35
70
|
|
71
|
+
#### OR
|
36
72
|
#### and an object, which responds to :to_nb_hash
|
37
73
|
|
38
74
|
class TestClass
|
@@ -45,6 +81,7 @@ Provide a hash containing the variables, that you used in your template.
|
|
45
81
|
|
46
82
|
Lettr.test_mail(:test => test_object ).deliver
|
47
83
|
|
84
|
+
#### OR
|
48
85
|
#### automagic
|
49
86
|
If your provided object does not respond to :to_nb_hash, Lettr will try to automatically serialize it based on the variables you used inside your template.
|
50
87
|
Given the following Class Definition:
|
@@ -91,4 +128,38 @@ It provides a class-level helper method to allow any instance method in your tem
|
|
91
128
|
|
92
129
|
In this example the call to :variable_1 will be ok, but the call to :variable_2 will raise an Exception.
|
93
130
|
|
131
|
+
## Usage (Newsletter Administration)
|
132
|
+
|
133
|
+
### Subscribe
|
134
|
+
In addition to the EMail delivery functionality this gem provides an easy way to sign your users up for your Newsletters.
|
135
|
+
To sign a user up, just call Lettr.sign_up and provide an object which at least responds to an :email method.
|
136
|
+
|
137
|
+
class User < ActiveRecord::Base
|
138
|
+
...
|
139
|
+
after_create do |user|
|
140
|
+
if user.wants_spam?
|
141
|
+
Lettr.subscribe(user) # calls user.email internally
|
142
|
+
end
|
143
|
+
end
|
144
|
+
...
|
145
|
+
end
|
146
|
+
|
147
|
+
This will create a Recipient in lettr.de. If the provided object responds to:
|
148
|
+
|
149
|
+
:gender
|
150
|
+
:firstname
|
151
|
+
:lastname
|
152
|
+
:street
|
153
|
+
:ccode
|
154
|
+
:pcode
|
155
|
+
:city
|
156
|
+
|
157
|
+
these attributes will also get transmitted to lettr.de.
|
158
|
+
If your object doesnt respond to these methods, but you want the information in your Recipients database, make the object respond (for example by delegating).
|
159
|
+
|
160
|
+
### Unsubscribe
|
161
|
+
To unsubscribe a Recipient, just call Lettr.unsubscribe and provide an email-address as argument.
|
162
|
+
|
163
|
+
Lettr.unsubscribe('tea_moe@example.com')
|
164
|
+
|
94
165
|
Copyright (c) 2010 Digineo GmbH, released under the MIT license
|
data/Rakefile
CHANGED
@@ -27,3 +27,16 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
27
27
|
rdoc.rdoc_files.include('README')
|
28
28
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
29
|
end
|
30
|
+
|
31
|
+
desc 'Generate HTML Readme'
|
32
|
+
task :readme do
|
33
|
+
begin
|
34
|
+
require 'rdiscount'
|
35
|
+
markdown = RDiscount.new(File.read('README.md'))
|
36
|
+
File.open('readme.html', 'w') do |f|
|
37
|
+
f.write markdown.to_html
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
'You need eht RDiscount gem'
|
41
|
+
end
|
42
|
+
end
|
data/lib/lettr.rb
CHANGED
data/lib/lettr/action_mailer.rb
CHANGED
@@ -8,15 +8,24 @@ module Lettr::ActionMailer
|
|
8
8
|
lettr_request_hash = {}
|
9
9
|
lettr_request_hash[:recipient] = recipient
|
10
10
|
lettr_request_hash[:subject] = mail.subject
|
11
|
-
mail.parts.
|
12
|
-
case
|
11
|
+
if mail.parts.empty?
|
12
|
+
case mail.content_type
|
13
13
|
when 'text/html'
|
14
|
-
lettr_request_hash[:html] =
|
14
|
+
lettr_request_hash[:html] = mail.body
|
15
15
|
when 'text/plain'
|
16
|
-
lettr_request_hash[:text] =
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
lettr_request_hash[:text] = mail.body
|
17
|
+
end
|
18
|
+
else
|
19
|
+
mail.parts.each do |part|
|
20
|
+
case part.content_type
|
21
|
+
when 'text/html'
|
22
|
+
lettr_request_hash[:html] = part.body
|
23
|
+
when 'text/plain'
|
24
|
+
lettr_request_hash[:text] = part.body
|
25
|
+
else
|
26
|
+
lettr_request_hash[:attachments] ||= []
|
27
|
+
lettr_request_hash[:attachments] << part.body
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
22
31
|
lettr_request_hashes << lettr_request_hash
|
data/lib/lettr/api_mailing.rb
CHANGED
@@ -47,6 +47,9 @@ Lettr::ApiMailing = Struct.new(:identifier, :subject, :variables) do
|
|
47
47
|
# object liefert variablen
|
48
48
|
@hash.merge!( name => object.to_nb_hash)
|
49
49
|
when object.is_a?( String )
|
50
|
+
if name.to_s == 'text' || name.to_s == 'html'
|
51
|
+
raise ArgumentError.new 'You cannot use Delivery Method, Lettr::Mailer or Manual Mailing with existing identifiers.'
|
52
|
+
end
|
50
53
|
@files.merge!( name => File.new(object, 'rb'))
|
51
54
|
else
|
52
55
|
# do magic stuff
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lettr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Digineo GmbH
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-04 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|