postageapp 1.0.22 → 1.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -31
- data/lib/postageapp/mailer/mailer_3.rb +12 -5
- data/lib/postageapp/mailer/mailer_4.rb +12 -5
- data/lib/postageapp/version.rb +1 -1
- data/test/mailer_3_test.rb +8 -0
- data/test/mailer_4_test.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4ce66fba6cb35602ebc6afe19498db5cdedb98f
|
4
|
+
data.tar.gz: 7bd2753935e216bce6283cf62f5c4bcc5c9a1885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c05d91dc01449f819db82997e123a89140c7d0fa01c8ac2c99a6342a71630cd58d93908b27f48458c3d50596c98c8ed082604173897cf81fd10ae08072d575af
|
7
|
+
data.tar.gz: 6ae7f5cc98f0041bc1c5dde01326fbae16eb5f7e0db836480e061333a7ba8cc44327357387fc41e3f26d0ebf8e5127e9cccc450e1c5bf064ffaee7e7e1c4cb76
|
data/README.md
CHANGED
@@ -10,32 +10,32 @@ Installation
|
|
10
10
|
|
11
11
|
### Rails 3 / 4
|
12
12
|
Add postageapp gem to your Gemfile:
|
13
|
-
|
13
|
+
|
14
14
|
gem 'postageapp'
|
15
|
-
|
15
|
+
|
16
16
|
Then from the Rails project's root run:
|
17
|
-
|
17
|
+
|
18
18
|
bundle install
|
19
19
|
script/rails generate postageapp --api-key PROJECT_API_KEY
|
20
|
-
|
20
|
+
|
21
21
|
### Rails 2
|
22
22
|
In config/environment.rb add the following:
|
23
|
-
|
23
|
+
|
24
24
|
config.gem 'postageapp'
|
25
|
-
|
25
|
+
|
26
26
|
Then from the Rails project's root run:
|
27
|
-
|
27
|
+
|
28
28
|
rake gems:install
|
29
29
|
rake gems:unpack GEM=postageapp
|
30
30
|
script/generate postageapp --api-key PROJECT_API_KEY
|
31
31
|
|
32
32
|
### Sinatra / Rack / Others
|
33
33
|
You'll need to install the gem first:
|
34
|
-
|
34
|
+
|
35
35
|
$ sudo gem install postageapp
|
36
|
-
|
36
|
+
|
37
37
|
And then it's as simple as doing something like this:
|
38
|
-
|
38
|
+
|
39
39
|
```ruby
|
40
40
|
require 'postageapp'
|
41
41
|
|
@@ -47,7 +47,7 @@ end
|
|
47
47
|
Usage
|
48
48
|
-----
|
49
49
|
Here's an example of sending a message ([See full API documentation](http://help.postageapp.com/faqs/api/send_message)):
|
50
|
-
|
50
|
+
|
51
51
|
```ruby
|
52
52
|
request = PostageApp::Request.new(:send_message, {
|
53
53
|
'headers' => { 'from' => 'sender@example.com',
|
@@ -66,24 +66,24 @@ request = PostageApp::Request.new(:send_message, {
|
|
66
66
|
})
|
67
67
|
response = request.send
|
68
68
|
```
|
69
|
-
|
69
|
+
|
70
70
|
`PostageApp::Response` object allows you to check the status:
|
71
|
-
|
71
|
+
|
72
72
|
>> response.status
|
73
73
|
=> 'ok'
|
74
|
-
|
74
|
+
|
75
75
|
Alternatively you may use:
|
76
76
|
|
77
77
|
>> response.fail?
|
78
78
|
=> false
|
79
79
|
>> response.ok?
|
80
80
|
=> true
|
81
|
-
|
81
|
+
|
82
82
|
Response usually comes back with data:
|
83
|
-
|
83
|
+
|
84
84
|
>> response.data
|
85
85
|
=> { 'message' => { 'id' => '12345' }}
|
86
|
-
|
86
|
+
|
87
87
|
### Recipient Override
|
88
88
|
Sometimes you don't want to send emails to real people in your application. For that there's an ability to override to what address all emails will be delivered. All you need to do is modify configuration block like this (in Rails projects it's usually found in `RAILS_ROOT/config/initializers/postageapp.rb`):
|
89
89
|
|
@@ -116,22 +116,22 @@ require 'postageapp/mailer'
|
|
116
116
|
class Notifier < PostageApp::Mailer
|
117
117
|
|
118
118
|
def signup_notification
|
119
|
-
|
119
|
+
|
120
120
|
attachments['example.zip'] = File.read('/path/to/example.zip')
|
121
|
-
|
121
|
+
|
122
122
|
headers['Special-Header'] = 'SpecialValue'
|
123
|
-
|
123
|
+
|
124
124
|
# PostageApp specific elements:
|
125
125
|
postageapp_template 'example_template'
|
126
126
|
postageapp_variables 'global_variable' => 'value'
|
127
|
-
|
127
|
+
|
128
128
|
# You may set api key for a specific mailers
|
129
129
|
postageapp_api_key '123456abcde'
|
130
|
-
|
130
|
+
|
131
131
|
# You can manually specify uid for the message payload.
|
132
132
|
# Make sure it's sufficiently unique.
|
133
133
|
postageapp_uid Digest::SHA1.hexdigest([@user.id, Time.now].to_s)
|
134
|
-
|
134
|
+
|
135
135
|
mail(
|
136
136
|
:from => 'test@test.test',
|
137
137
|
:subject => 'Test Message',
|
@@ -142,7 +142,7 @@ class Notifier < PostageApp::Mailer
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
```
|
145
|
-
|
145
|
+
|
146
146
|
API of previous ActionMailer is partially supported under Rails 3 environment. Please note that it's not 100% integrated, some methods/syntax will not work. You may still define you mailers in this way (but really shouldn't):
|
147
147
|
|
148
148
|
```ruby
|
@@ -167,10 +167,10 @@ require 'postageapp/mailer'
|
|
167
167
|
|
168
168
|
class Notifier < PostageApp::Mailer
|
169
169
|
def signup_notification
|
170
|
-
|
170
|
+
|
171
171
|
from 'system@example.com'
|
172
172
|
subject 'New Account Information'
|
173
|
-
|
173
|
+
|
174
174
|
# Recipients can be in any format API allows.
|
175
175
|
# Here's an example of a hash format
|
176
176
|
recipients ({
|
@@ -179,25 +179,25 @@ class Notifier < PostageApp::Mailer
|
|
179
179
|
'recipient_2@example.com' => { 'variable_name_1' => 'value',
|
180
180
|
'variable_name_2' => 'value' },
|
181
181
|
})
|
182
|
-
|
182
|
+
|
183
183
|
attachment :content_type => 'application/zip',
|
184
184
|
:filename => 'example.zip',
|
185
185
|
:body => File.read('/path/to/example.zip')
|
186
|
-
|
186
|
+
|
187
187
|
# PostageApp specific elements:
|
188
188
|
postageapp_template 'example_template'
|
189
189
|
postageapp_variables 'global_variable' => 'value'
|
190
|
-
|
190
|
+
|
191
191
|
end
|
192
192
|
end
|
193
193
|
```
|
194
|
-
|
194
|
+
|
195
195
|
Automatic resending in case of failure
|
196
196
|
--------------------------------------
|
197
197
|
For those ultra rare occasions when api.postageapp.com is not reachable this gem will temporarily store requests and then will attempt to resend them with the next successful connection. In Rails environment it will create a folder: `RAILS_ROOT/tmp/postageapp_failed_requests` and save all failed requests there. On successful resend file for that request will be deleted.
|
198
198
|
|
199
199
|
For projects other than Rails you'll need to tell where there project_root is at:
|
200
|
-
|
200
|
+
|
201
201
|
```ruby
|
202
202
|
PostageApp.configure do |config|
|
203
203
|
config.api_key = 'PROJECT_API_KEY'
|
@@ -205,6 +205,20 @@ PostageApp.configure do |config|
|
|
205
205
|
end
|
206
206
|
```
|
207
207
|
|
208
|
+
Interceptors (Rails 3)
|
209
|
+
----------------------
|
210
|
+
Here's an example of using an interceptor
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
class DevelopmentPostageappInterceptor
|
214
|
+
def self.delivering_email(postageapp_msg)
|
215
|
+
postageapp_msg.arguments["headers"][:subject] = "[#{postageapp_msg.arguments["recipients"]}] #{postageapp_msg.arguments["headers"][:subject]}"
|
216
|
+
postageapp_msg.arguments["recipients"] = "test@example.com"
|
217
|
+
# postageapp_msg.perform_deliveries = false
|
218
|
+
end
|
219
|
+
end
|
220
|
+
```
|
221
|
+
|
208
222
|
Copyright
|
209
223
|
---------
|
210
224
|
(C) 2011-13 Oleg Khabarov, [The Working Group, Inc](http://www.twg.ca/)
|
@@ -148,13 +148,20 @@ class PostageApp::Request
|
|
148
148
|
:perform_deliveries,
|
149
149
|
:raise_delivery_errors
|
150
150
|
|
151
|
+
def inform_interceptors
|
152
|
+
Mail.inform_interceptors(self)
|
153
|
+
end
|
154
|
+
|
151
155
|
# Either doing an actual send, or passing it along to Mail::TestMailer
|
152
156
|
# Probably not the best way as we're skipping way too many intermediate methods
|
153
157
|
def deliver
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
+
inform_interceptors
|
159
|
+
if perform_deliveries
|
160
|
+
if @delivery_method == Mail::TestMailer
|
161
|
+
@delivery_method.deliveries << self
|
162
|
+
else
|
163
|
+
self.send
|
164
|
+
end
|
158
165
|
end
|
159
166
|
end
|
160
167
|
|
@@ -163,4 +170,4 @@ class PostageApp::Request
|
|
163
170
|
@delivery_method = method
|
164
171
|
end
|
165
172
|
|
166
|
-
end
|
173
|
+
end
|
@@ -141,7 +141,7 @@ protected
|
|
141
141
|
templates.uniq { |t| t.formats }.each(&block)
|
142
142
|
end
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
def create_parts_from_responses(m, responses) #:nodoc:
|
146
146
|
map = {
|
147
147
|
'html' => 'text/html',
|
@@ -163,13 +163,20 @@ class PostageApp::Request
|
|
163
163
|
:perform_deliveries,
|
164
164
|
:raise_delivery_errors
|
165
165
|
|
166
|
+
def inform_interceptors
|
167
|
+
Mail.inform_interceptors(self)
|
168
|
+
end
|
169
|
+
|
166
170
|
# Either doing an actual send, or passing it along to Mail::TestMailer
|
167
171
|
# Probably not the best way as we're skipping way too many intermediate methods
|
168
172
|
def deliver
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
+
inform_interceptors
|
174
|
+
if perform_deliveries
|
175
|
+
if @delivery_method == Mail::TestMailer
|
176
|
+
@delivery_method.deliveries << self
|
177
|
+
else
|
178
|
+
self.send
|
179
|
+
end
|
173
180
|
end
|
174
181
|
end
|
175
182
|
|
data/lib/postageapp/version.rb
CHANGED
data/test/mailer_3_test.rb
CHANGED
@@ -92,6 +92,14 @@ class Mailer3Test < Test::Unit::TestCase
|
|
92
92
|
assert_equal [mail], ActionMailer::Base.deliveries
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_deliver_for_not_performing_deliveries_with_test_mailer
|
96
|
+
mail = Notifier.with_simple_view
|
97
|
+
mail.perform_deliveries = false
|
98
|
+
mail.delivery_method(Mail::TestMailer)
|
99
|
+
mail.deliver
|
100
|
+
assert_equal [], ActionMailer::Base.deliveries
|
101
|
+
end
|
102
|
+
|
95
103
|
else
|
96
104
|
puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
|
97
105
|
def test_nothing ; end
|
data/test/mailer_4_test.rb
CHANGED
@@ -7,12 +7,12 @@ class Mailer4Test < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
require File.expand_path('../mailer/action_mailer_3/notifier', __FILE__)
|
9
9
|
puts "\e[0m\e[32mRunning #{File.basename(__FILE__)} for action_mailer #{ActionMailer::VERSION::STRING}\e[0m"
|
10
|
-
|
10
|
+
|
11
11
|
def test_create_with_no_content
|
12
12
|
mail = Notifier.with_no_content
|
13
13
|
assert_equal ({}), mail.arguments['content']
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_create_with_no_subject
|
17
17
|
mail = Notifier.with_no_subject
|
18
18
|
assert mail.arguments['headers'][:subject].nil?
|
@@ -92,6 +92,14 @@ class Mailer4Test < Test::Unit::TestCase
|
|
92
92
|
assert_equal [mail], ActionMailer::Base.deliveries
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_deliver_for_not_performing_deliveries_with_test_mailer
|
96
|
+
mail = Notifier.with_simple_view
|
97
|
+
mail.perform_deliveries = false
|
98
|
+
mail.delivery_method(Mail::TestMailer)
|
99
|
+
mail.deliver
|
100
|
+
assert_equal [], ActionMailer::Base.deliveries
|
101
|
+
end
|
102
|
+
|
95
103
|
else
|
96
104
|
puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
|
97
105
|
def test_nothing ; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postageapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Khabarov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|