postageapp 1.0.24 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +13 -12
  3. data/Gemfile +6 -1
  4. data/LICENSE +1 -1
  5. data/README.md +122 -70
  6. data/Rakefile +19 -4
  7. data/generators/postageapp/postageapp_generator.rb +5 -7
  8. data/lib/generators/postageapp/postageapp_generator.rb +15 -9
  9. data/lib/postageapp.rb +42 -36
  10. data/lib/postageapp/configuration.rb +34 -21
  11. data/lib/postageapp/failed_request.rb +60 -36
  12. data/lib/postageapp/logger.rb +6 -7
  13. data/lib/postageapp/mail.rb +3 -0
  14. data/lib/postageapp/mail/arguments.rb +75 -0
  15. data/lib/postageapp/mail/delivery_method.rb +32 -0
  16. data/lib/postageapp/mail/extensions.rb +21 -0
  17. data/lib/postageapp/mailer.rb +72 -20
  18. data/lib/postageapp/mailer/mailer_2.rb +65 -22
  19. data/lib/postageapp/mailer/mailer_3.rb +45 -28
  20. data/lib/postageapp/mailer/mailer_4.rb +72 -40
  21. data/lib/postageapp/rails/rails.rb +17 -7
  22. data/lib/postageapp/rails/railtie.rb +22 -7
  23. data/lib/postageapp/request.rb +67 -43
  24. data/lib/postageapp/response.rb +11 -8
  25. data/lib/postageapp/utils.rb +11 -3
  26. data/lib/postageapp/version.rb +2 -2
  27. data/postageapp.gemspec +13 -11
  28. data/rails/init.rb +1 -1
  29. data/test/configuration_test.rb +35 -38
  30. data/test/failed_request_test.rb +33 -18
  31. data/test/gemfiles/Gemfile.rails-2.3.x +4 -1
  32. data/test/gemfiles/Gemfile.rails-3.0.x +4 -1
  33. data/test/gemfiles/Gemfile.rails-3.1.x +4 -1
  34. data/test/gemfiles/Gemfile.rails-3.2.x +4 -1
  35. data/test/gemfiles/Gemfile.rails-4.0.x +4 -1
  36. data/test/gemfiles/Gemfile.rails-4.1.x +12 -0
  37. data/test/gemfiles/Gemfile.rails-4.2.x +12 -0
  38. data/test/gemfiles/Gemfile.ruby +11 -0
  39. data/test/helper.rb +52 -33
  40. data/test/live_test.rb +11 -8
  41. data/test/mail_delivery_method_test.rb +161 -0
  42. data/test/mailer/action_mailer_2/notifier.rb +37 -28
  43. data/test/mailer/action_mailer_3/notifier.rb +28 -22
  44. data/test/mailer_2_test.rb +20 -16
  45. data/test/mailer_3_test.rb +16 -22
  46. data/test/mailer_4_test.rb +28 -28
  47. data/test/mailer_helper_methods_test.rb +17 -14
  48. data/test/postageapp_test.rb +8 -9
  49. data/test/rails_initialization_test.rb +14 -14
  50. data/test/request_test.rb +35 -35
  51. data/test/response_test.rb +20 -19
  52. data/test/travis_test.rb +168 -0
  53. data/test/with_environment.rb +27 -0
  54. metadata +23 -17
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 137d68c70e3e36a0ffa2d4701477ff1e264b4550
4
+ data.tar.gz: 847c08f7a96c8eb75f4decd3ab54b0bf1beedc65
5
+ SHA512:
6
+ metadata.gz: f5130b3ceddd00f85e15e1823adf766c2727415aff2d77673a2dceaa2bc770bb08abe34da1cdb9a0ee18af1a811d96018c25945eabad95f1001ee61b2ad22343
7
+ data.tar.gz: 2b44293bf9bf5eee65de1855c18645bd4992c3c7420175540da99c50209844cf0bba498986d0b7681ce08337db881a7497e0065880cb31535419e37fdc307d7e
@@ -1,23 +1,24 @@
1
1
  language: ruby
2
+ before_install: gem install bundler
2
3
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - ree
7
- - 2.0.0
4
+ - 1.9.3-p551
5
+ - 2.0.0-p598
6
+ - 2.1.5
7
+ - 2.2.0
8
8
  gemfile:
9
+ - test/gemfiles/Gemfile.ruby
9
10
  - test/gemfiles/Gemfile.rails-2.3.x
10
11
  - test/gemfiles/Gemfile.rails-3.0.x
11
12
  - test/gemfiles/Gemfile.rails-3.1.x
12
13
  - test/gemfiles/Gemfile.rails-3.2.x
13
14
  - test/gemfiles/Gemfile.rails-4.0.x
15
+ - test/gemfiles/Gemfile.rails-4.1.x
16
+ - test/gemfiles/Gemfile.rails-4.2.x
14
17
  matrix:
15
18
  exclude:
16
- - rvm: 2.0.0
19
+ - rvm: 2.0.0-p598
20
+ gemfile: test/gemfiles/Gemfile.rails-2.3.x
21
+ - rvm: 2.1.5
22
+ gemfile: test/gemfiles/Gemfile.rails-2.3.x
23
+ - rvm: 2.2.0
17
24
  gemfile: test/gemfiles/Gemfile.rails-2.3.x
18
- - rvm: 1.8.7
19
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
20
- - rvm: ree
21
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
22
- - rvm: 1.9.2
23
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
data/Gemfile CHANGED
@@ -2,8 +2,13 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :test do
5
+ gem 'mail', '>= 2.4.0'
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ gem 'jeweler'
6
10
  gem 'minitest'
11
+ gem 'minitest-reporters'
7
12
  gem 'rails'
8
13
  gem 'mocha'
9
14
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2014 Oleg Khabarov, The Working Group, Inc
1
+ Copyright (c) 2011-2015 Scott Tadman, Oleg Khabarov, The Working Group, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,15 +1,27 @@
1
1
  # [PostageApp](http://postageapp.com) Ruby Gem [![Build Status](https://secure.travis-ci.org/postageapp/postageapp-ruby.png)](http://travis-ci.org/postageapp/postageapp-ruby)
2
2
 
3
- This is the gem used to integrate Ruby apps with PostageApp service.
4
- Personalized, mass email sending can be offloaded to PostageApp via JSON based API.
3
+ This gem is used to integrate Ruby apps with [PostageApp](http://postageapp.com/)
4
+ service. Personalized high-volume email sending can be offloaded to PostageApp
5
+ via a simple [JSON-based API](http://dev.postageapp.com/api.html).
5
6
 
6
- ### [API Documentation](http://help.postageapp.com/kb/api/api-overview) • [Knowledge Base](http://help.postageapp.com/kb) • [Help Portal](http://help.postageapp.com)
7
+ ### [API Documentation](http://help.postageapp.com/kb/api/api-overview) • [Knowledge Base](http://help.postageapp.com/kb) • [Help Portal](http://help.postageapp.com/)
7
8
 
8
- Installation
9
- ------------
9
+ # Installation
10
10
 
11
- ### Rails 3 / 4
12
- Add postageapp gem to your Gemfile:
11
+ ### Rails 4.x
12
+
13
+ Add the `postageapp` gem to your Gemfile:
14
+
15
+ gem 'postageapp'
16
+
17
+ Then from the Rails project's root run:
18
+
19
+ bundle install
20
+ bin/rails generate postageapp --api-key PROJECT_API_KEY
21
+
22
+ ### Rails 3.x
23
+
24
+ Add the `postageapp` gem to your Gemfile:
13
25
 
14
26
  gem 'postageapp'
15
27
 
@@ -18,8 +30,9 @@ Then from the Rails project's root run:
18
30
  bundle install
19
31
  script/rails generate postageapp --api-key PROJECT_API_KEY
20
32
 
21
- ### Rails 2
22
- In config/environment.rb add the following:
33
+ ### Rails 2.x
34
+
35
+ In `config/environment.rb` add the following:
23
36
 
24
37
  config.gem 'postageapp'
25
38
 
@@ -30,11 +43,12 @@ Then from the Rails project's root run:
30
43
  script/generate postageapp --api-key PROJECT_API_KEY
31
44
 
32
45
  ### Sinatra / Rack / Others
46
+
33
47
  You'll need to install the gem first:
34
48
 
35
49
  $ sudo gem install postageapp
36
50
 
37
- And then it's as simple as doing something like this:
51
+ The configuration will need to be loaded before executing any API calls:
38
52
 
39
53
  ```ruby
40
54
  require 'postageapp'
@@ -44,26 +58,35 @@ PostageApp.configure do |config|
44
58
  end
45
59
  ```
46
60
 
47
- Usage
48
- -----
61
+ If it's more convenient, setting the `POSTAGEAPP_API_KEY` environment variable
62
+ with the appropriate API key will also work.
63
+
64
+ # Usage
65
+
49
66
  Here's an example of sending a message ([See full API documentation](http://help.postageapp.com/faqs/api/send_message)):
50
67
 
51
68
  ```ruby
52
- request = PostageApp::Request.new(:send_message, {
53
- 'headers' => { 'from' => 'sender@example.com',
54
- 'subject' => 'Email Subject' },
55
- 'recipients' => 'recipient@example.com',
56
- 'content' => {
57
- 'text/plain' => 'text email content',
58
- 'text/html' => 'html email content'
59
- },
60
- 'attachments' => {
61
- 'document.pdf' => {
62
- 'content_type' => 'application/pdf',
63
- 'content' => Base64.encode64(File.open('/path/to/document.pdf', 'rb').read)
69
+ request = PostageApp::Request.new(
70
+ :send_message,
71
+ {
72
+ headers: {
73
+ from: 'sender@example.com',
74
+ subject: 'Email Subject'
75
+ },
76
+ recipients: 'recipient@example.com',
77
+ content: {
78
+ 'text/plain' => 'text email content',
79
+ 'text/html' => 'html email content'
80
+ },
81
+ attachments: {
82
+ 'document.pdf' => {
83
+ content_type: application/pdf',
84
+ content: Base64.encode64(File.open('/path/to/document.pdf', 'rb').read)
85
+ }
64
86
  }
65
87
  }
66
- })
88
+ )
89
+
67
90
  response = request.send
68
91
  ```
69
92
 
@@ -85,26 +108,44 @@ Response usually comes back with data:
85
108
  => { 'message' => { 'id' => '12345' }}
86
109
 
87
110
  ### Recipient Override
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`):
111
+
112
+ Sometimes you don't want to send emails to real people in your application. For
113
+ that there's an ability to override to what address all emails will be
114
+ delivered. All you need to do is modify configuration block like this (in Rails
115
+ projects it's usually found in `RAILS_ROOT/config/initializers/postageapp.rb`):
89
116
 
90
117
  ```ruby
91
118
  PostageApp.configure do |config|
92
- config.api_key = 'PROJECT_API_KEY'
93
- config.recipient_override = 'you@example.com' unless Rails.env.production?
119
+ config.api_key = 'PROJECT_API_KEY'
120
+
121
+ unless (Rails.env.production?)
122
+ config.recipient_override = 'you@example.com'
123
+ end
94
124
  end
95
125
  ```
96
126
 
97
- ActionMailer Integration
98
- ------------------------
99
- You can quickly convert your existing mailers to use PostageApp service by simply changing `class MyMailer < ActionMailer::Base` to `class MyMailer < PostageApp::Mailer`. If you using ActionMailer from outside of Rails make sure you have this line somewhere: `require 'postageapp/mailer'`
127
+ # ActionMailer Integration
100
128
 
101
- There are custom methods that allow setting of `template` and `variables` parts of the API call. They are `postageapp_template` and `postageapp_variables`. Examples how they are used are below. For details what they do please see [documentation](http://help.postageapp.com/faqs)
129
+ You can quickly convert your existing mailers to use PostageApp service by
130
+ simply changing `class MyMailer < ActionMailer::Base` to
131
+ `class MyMailer < PostageApp::Mailer`. When using ActionMailer from outside
132
+ of Rails, this will have to be loaded manually:
102
133
 
103
- Please note that `deliver` method will return `PostageApp::Response` object. This way you can immediately check the status of the delivery. For example:
134
+ ```ruby
135
+ require 'postageapp/mailer'
136
+ ```
104
137
 
105
- >> response = UserMailer.welcome_email(@user).deliver
106
- >> response.ok?
107
- => true
138
+ There are custom methods that allow setting of `template` and `variables` parts
139
+ of the API call. They are `postageapp_template` and `postageapp_variables`.
140
+ Examples how they are used are below. For details what they do please see
141
+ [documentation](http://help.postageapp.com/faqs)
142
+
143
+ Please note that `deliver` method will return `PostageApp::Response` object.
144
+ This way you can immediately check the status of the delivery. For example:
145
+
146
+ response = UserMailer.welcome_email(@user).deliver
147
+ response.ok?
148
+ # => true
108
149
 
109
150
  ### Rails 3 / 4
110
151
 
@@ -114,9 +155,7 @@ Here's an example of a mailer in Rails 3 environment:
114
155
  require 'postageapp/mailer'
115
156
 
116
157
  class Notifier < PostageApp::Mailer
117
-
118
158
  def signup_notification
119
-
120
159
  attachments['example.zip'] = File.read('/path/to/example.zip')
121
160
 
122
161
  headers['Special-Header'] = 'SpecialValue'
@@ -130,44 +169,49 @@ class Notifier < PostageApp::Mailer
130
169
 
131
170
  # You can manually specify uid for the message payload.
132
171
  # Make sure it's sufficiently unique.
133
- postageapp_uid Digest::SHA1.hexdigest([@user.id, Time.now].to_s)
172
+ postageapp_uid Digest::SHA1.hexdigest([ @user.id, Time.now ].to_s)
134
173
 
135
174
  mail(
136
- :from => 'test@test.test',
137
- :subject => 'Test Message',
138
- :to => {
175
+ from: 'test@test.test',
176
+ subject: 'Test Message',
177
+ to: {
139
178
  'recipient_1@example.com' => { 'variable' => 'value' },
140
179
  'recipient_2@example.com' => { 'variable' => 'value' }
141
- })
180
+ }
181
+ )
142
182
  end
143
183
  end
144
184
  ```
145
185
 
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):
186
+ API of previous ActionMailer is partially supported under Rails 3 environment.
187
+ Please note that it's not 100% integrated, some methods/syntax will not work.
188
+ You may still define you mailers in this way (but really shouldn't):
147
189
 
148
190
  ```ruby
149
191
  require 'postageapp/mailer'
150
192
 
151
193
  class Notifier < PostageApp::Mailer
152
-
153
194
  def signup_notification
154
- from 'sender@example.com'
155
- subject 'Test Email'
156
- recipients 'recipient@example.com'
195
+ from 'sender@example.com'
196
+ subject 'Test Email'
197
+ recipients 'recipient@example.com'
157
198
  end
158
199
  end
159
200
  ```
160
201
 
161
202
  #### Interceptors
162
203
 
163
- Here's an example of using an interceptor
204
+ Here's an example of using an interceptor:
164
205
 
165
206
  ```ruby
166
207
  class DevelopmentPostageappInterceptor
167
208
  def self.delivering_email(postageapp_msg)
168
209
  postageapp_msg.arguments["headers"][:subject] =
169
210
  "[#{postageapp_msg.arguments["recipients"]}] #{postageapp_msg.arguments["headers"][:subject]}"
211
+
170
212
  postageapp_msg.arguments["recipients"] = "test@example.com"
213
+
214
+ # Deliveries can be disabled if required
171
215
  # postageapp_msg.perform_deliveries = false
172
216
  end
173
217
  end
@@ -182,36 +226,44 @@ require 'postageapp/mailer'
182
226
 
183
227
  class Notifier < PostageApp::Mailer
184
228
  def signup_notification
185
-
186
- from 'system@example.com'
187
- subject 'New Account Information'
229
+ from 'system@example.com'
230
+ subject 'New Account Information'
188
231
 
189
232
  # Recipients can be in any format API allows.
190
233
  # Here's an example of a hash format
191
- recipients ({
192
- 'recipient_1@example.com' => { 'variable_name_1' => 'value',
193
- 'variable_name_2' => 'value' },
194
- 'recipient_2@example.com' => { 'variable_name_1' => 'value',
195
- 'variable_name_2' => 'value' },
196
- })
197
-
198
- attachment :content_type => 'application/zip',
199
- :filename => 'example.zip',
200
- :body => File.read('/path/to/example.zip')
234
+ recipients(
235
+ 'recipient_1@example.com' => {
236
+ 'variable_name_1' => 'value',
237
+ 'variable_name_2' => 'value'
238
+ },
239
+ 'recipient_2@example.com' => {
240
+ 'variable_name_1' => 'value',
241
+ 'variable_name_2' => 'value'
242
+ },
243
+ )
244
+
245
+ attachment(
246
+ :content_type => 'application/zip',
247
+ :filename => 'example.zip',
248
+ :body => File.read('/path/to/example.zip'
249
+ )
201
250
 
202
251
  # PostageApp specific elements:
203
252
  postageapp_template 'example_template'
204
253
  postageapp_variables 'global_variable' => 'value'
205
-
206
254
  end
207
255
  end
208
256
  ```
209
257
 
210
- Automatic resending in case of failure
211
- --------------------------------------
212
- 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.
258
+ # Automatic resending in case of failure
213
259
 
214
- For projects other than Rails you'll need to tell where there project_root is at:
260
+ For those rare occasions when the API is not reachable or unresponsive,
261
+ this gem will temporarily store requests and then will attempt to resend them
262
+ with the next successful connection. In Rails environment it will create a
263
+ folder: `RAILS_ROOT/tmp/postageapp_failed_requests` and save all failed
264
+ requests there. On successful resend file for that request will be deleted.
265
+
266
+ For projects other than Rails you'll need to tell where the `project_root` is:
215
267
 
216
268
  ```ruby
217
269
  PostageApp.configure do |config|
@@ -220,6 +272,6 @@ PostageApp.configure do |config|
220
272
  end
221
273
  ```
222
274
 
223
- Copyright
224
- ---------
225
- (C) 2011-2014 Oleg Khabarov, [The Working Group, Inc](http://www.twg.ca/)
275
+ # Copyright
276
+
277
+ (C) 2011-2015 Scott Tadman, Oleg Khabarov, [The Working Group, Inc](http://www.twg.ca/)
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
- require 'bundler'
2
- require 'rake/testtask'
1
+ require 'bundler/setup'
3
2
 
4
- Bundler.require
3
+ require 'rake/testtask'
5
4
 
6
5
  Rake::TestTask.new(:test) do |test|
7
6
  test.libs << 'lib' << 'test'
@@ -9,4 +8,20 @@ Rake::TestTask.new(:test) do |test|
9
8
  test.verbose = true
10
9
  end
11
10
 
12
- task :default => :test
11
+ namespace :travis do
12
+ desc "Run tests across different environments, simulating Travis"
13
+ task :test do
14
+ require File.expand_path('test/travis_test', File.dirname(__FILE__))
15
+
16
+ TravisTest.run!
17
+ end
18
+
19
+ desc "Report on which versions of Ruby are installed"
20
+ task :versions do
21
+ require File.expand_path('test/travis_test', File.dirname(__FILE__))
22
+
23
+ TravisTest.validate_ruby_versions!
24
+ end
25
+ end
26
+
27
+ task :default => :test
@@ -7,7 +7,6 @@ end
7
7
 
8
8
  # Rails 2 Generator
9
9
  class PostageappGenerator < Rails::Generator::Base
10
-
11
10
  def add_options!(opt)
12
11
  opt.on('-k=key', '--api-key=key') do |value|
13
12
  options[:api_key] = value
@@ -15,20 +14,19 @@ class PostageappGenerator < Rails::Generator::Base
15
14
  end
16
15
 
17
16
  def manifest
18
- if !options[:api_key]
17
+ unless (options[:api_key])
19
18
  puts 'Must pass --api-key with API key of your PostageApp.com project'
20
19
  exit
21
20
  end
22
21
 
23
22
  record do |m|
24
23
  m.template 'initializer.rb', 'config/initializers/postageapp.rb',
25
- :assigns => { :api_key => options[:api_key] },
26
- :collision => :force
24
+ :assigns => { :api_key => options[:api_key] },
25
+ :collision => :force
27
26
  m.directory 'lib/tasks'
28
27
  m.file 'postageapp_tasks.rake', 'lib/tasks/postageapp_tasks.rake',
29
- :collision => :force
28
+ :collision => :force
30
29
  m.rake 'postageapp:test'
31
30
  end
32
31
  end
33
-
34
- end
32
+ end
@@ -2,26 +2,32 @@ require 'rails/generators'
2
2
 
3
3
  # Rails 3 Generator
4
4
  class PostageappGenerator < Rails::Generators::Base
5
-
6
- class_option :api_key, :aliases => ['-k=value', '--api-key=value'], :type => :string, :desc => 'Your PostageApp API key'
5
+ class_option :api_key,
6
+ :aliases => [ '-k=value', '--api-key=value' ],
7
+ :type => :string,
8
+ :desc => 'Your PostageApp API key'
7
9
 
8
10
  def self.source_root
9
- @_hoptoad_source_root ||= File.expand_path('../../../../generators/postageapp/templates', __FILE__)
11
+ @_hoptoad_source_root ||= File.expand_path(
12
+ '../../../../generators/postageapp/templates',
13
+ __FILE__
14
+ )
10
15
  end
11
16
 
12
17
  def install
13
- if !options[:api_key]
18
+ unless (options[:api_key])
14
19
  puts 'Must pass --api-key with API key of your PostageApp.com project'
15
- exit
20
+
21
+ exit(-1)
16
22
  end
17
23
 
18
- template 'initializer.rb', 'config/initializers/postageapp.rb'
19
- copy_file 'postageapp_tasks.rake', 'lib/tasks/postageapp_tasks.rake'
24
+ template('initializer.rb', 'config/initializers/postageapp.rb')
25
+ copy_file('postageapp_tasks.rake', 'lib/tasks/postageapp_tasks.rake')
26
+
20
27
  puts run('rake postageapp:test')
21
28
  end
22
29
 
23
30
  def api_key
24
31
  options[:api_key]
25
32
  end
26
-
27
- end
33
+ end