lettr 1.0.2 → 1.0.3
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 +9 -9
- data/lib/lettr.rb +1 -0
- data/lib/lettr/base.rb +12 -4
- data/lib/lettr/collection.rb +5 -1
- data/lib/lettr/deliverable.rb +1 -0
- data/lib/lettr/recipient.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -45,13 +45,13 @@ Just set the Delivery Method of ActionMailer to :lettr, and all Mailings from Ac
|
|
45
45
|
### Lettr::Mailer
|
46
46
|
Let your mailer class inherit from Lettr::Mailer instead of ActionMailer::Base.
|
47
47
|
|
48
|
-
class
|
49
|
-
FROM = '
|
50
|
-
def
|
51
|
-
recipients
|
48
|
+
class ExampleMailer < Lettr::Mailer
|
49
|
+
FROM = 'example <info@example.com>'
|
50
|
+
def example_mail(example)
|
51
|
+
recipients example.email
|
52
52
|
from FROM
|
53
|
-
subject I18n.t('
|
54
|
-
body :
|
53
|
+
subject I18n.t('example_mailer.example')
|
54
|
+
body :example => example
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -66,7 +66,7 @@ Let your mailer class inherit from Lettr::Mailer instead of ActionMailer::Base.
|
|
66
66
|
#### and a hash
|
67
67
|
Provide a hash containing the variables, that you used in your template.
|
68
68
|
|
69
|
-
Lettr.test_mail(:test => { :variable_1 => 'foo', :variable_2 => 'bar' }).deliver
|
69
|
+
Lettr.test_mail(:recipient => 'tg@digineo.de', :test => { :variable_1 => 'foo', :variable_2 => 'bar' }).deliver
|
70
70
|
|
71
71
|
#### OR
|
72
72
|
#### and an object, which responds to :to_nb_hash
|
@@ -79,7 +79,7 @@ Provide a hash containing the variables, that you used in your template.
|
|
79
79
|
|
80
80
|
test_object = TestClass.new
|
81
81
|
|
82
|
-
Lettr.test_mail(:test => test_object
|
82
|
+
Lettr.test_mail(:recipient => 'tg@digineo.de', :test => test_object).deliver
|
83
83
|
|
84
84
|
#### OR
|
85
85
|
#### automagic
|
@@ -102,7 +102,7 @@ And the following Template:
|
|
102
102
|
When you do a request to the Lettr Api
|
103
103
|
|
104
104
|
test_object = TestClass.new
|
105
|
-
Lettr.test_mail(:test => test_object ).deliver
|
105
|
+
Lettr.test_mail(:recipient => 'tg@digineo.de', :test => test_object ).deliver
|
106
106
|
|
107
107
|
Lettr will invoke the methods :variable_1 and :variable_2 on test_object and serialize their return values for the request.
|
108
108
|
So the request will result in the following Mailing:
|
data/lib/lettr.rb
CHANGED
data/lib/lettr/base.rb
CHANGED
@@ -5,7 +5,9 @@ class Lettr::Base
|
|
5
5
|
attr_reader :client
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
|
8
|
+
resource_args = [ self.class.site_url ]
|
9
|
+
resource_args += [self.class.user, self.class.pass] unless Lettr.api_key
|
10
|
+
@client = RestClient::Resource.new *resource_args
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.site_url
|
@@ -16,19 +18,25 @@ class Lettr::Base
|
|
16
18
|
path = object.collection_path
|
17
19
|
payload = object.to_payload
|
18
20
|
payload.merge! :files => object.files if object.respond_to?(:files) && object.files
|
19
|
-
client[path].post(payload,
|
21
|
+
client[path].post(payload, headers)
|
20
22
|
end
|
21
23
|
|
22
24
|
def destroy object
|
23
|
-
client[object.path].delete
|
25
|
+
client[object.path].delete headers
|
24
26
|
end
|
25
27
|
|
26
28
|
def find path
|
27
|
-
ActiveSupport::JSON.decode(client[path].get
|
29
|
+
ActiveSupport::JSON.decode(client[path].get headers)
|
28
30
|
end
|
29
31
|
|
30
32
|
def [] path
|
31
33
|
client[path]
|
32
34
|
end
|
33
35
|
|
36
|
+
def headers
|
37
|
+
headers = DEFAULT_HEADERS
|
38
|
+
headers.merge! 'X-Lettr-API-key' => Lettr.api_key if Lettr.api_key
|
39
|
+
headers
|
40
|
+
end
|
41
|
+
|
34
42
|
end
|
data/lib/lettr/collection.rb
CHANGED
@@ -17,7 +17,11 @@ class Lettr::Collection
|
|
17
17
|
if element.class.respond_to? :is_whitelisted?
|
18
18
|
raise SecurityError, "method #{var} in class #{element.class} not whitelisted" unless element.class.is_whitelisted?(var)
|
19
19
|
end
|
20
|
-
|
20
|
+
if element.is_a?( String )
|
21
|
+
hash = element
|
22
|
+
else
|
23
|
+
hash[var] = element.send(var)
|
24
|
+
end
|
21
25
|
end
|
22
26
|
@context << hash
|
23
27
|
end
|
data/lib/lettr/deliverable.rb
CHANGED
@@ -30,6 +30,7 @@ module Lettr::Deliverable
|
|
30
30
|
group_variables if respond_to? :group_variables
|
31
31
|
handle_options
|
32
32
|
append_used_variables if respond_to? :append_used_variables
|
33
|
+
Rails.logger.debug @hash.inspect
|
33
34
|
|
34
35
|
# perform delivery request
|
35
36
|
rec = Lettr::Delivery.new @hash, @files
|
data/lib/lettr/recipient.rb
CHANGED
@@ -16,7 +16,7 @@ Lettr::Recipient = Struct.new( :email, :id, :gender, :firstname, :lastname, :str
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.delete_by_email email
|
19
|
-
client["#{path}/destroy_by_email"].delete :email => email
|
19
|
+
client["#{path}/destroy_by_email"].delete :email => email #, 'X-Lettr-API-Key' => Lettr.api_key
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
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: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
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-
|
18
|
+
date: 2010-12-20 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|