postageapp 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +6 -0
- data/.travis.yml +9 -40
- data/LICENSE.md +1 -1
- data/README.md +117 -13
- data/Rakefile +15 -4
- data/VERSION +1 -0
- data/app/ingresses/action_mailbox/ingresses/postage_app.rb +2 -0
- data/app/ingresses/action_mailbox/ingresses/postage_app/inbound_emails_controller.rb +50 -0
- data/config/routes.rb +6 -0
- data/exe/postageapp +37 -0
- data/lib/generators/postageapp/postageapp_generator.rb +9 -6
- data/lib/postageapp.rb +53 -35
- data/lib/postageapp/cli.rb +14 -0
- data/lib/postageapp/cli/command.rb +110 -0
- data/lib/postageapp/cli/command/config.rb +74 -0
- data/lib/postageapp/cli/command/create_mailbox.rb +21 -0
- data/lib/postageapp/cli/command/env.rb +58 -0
- data/lib/postageapp/cli/command/get_project_info.rb +3 -0
- data/lib/postageapp/configuration.rb +237 -74
- data/lib/postageapp/engine.rb +9 -0
- data/lib/postageapp/env.rb +9 -0
- data/lib/postageapp/mailer.rb +1 -11
- data/lib/postageapp/mailer/mailer_4.rb +30 -14
- data/lib/postageapp/rails/railtie.rb +1 -3
- data/lib/postageapp/request.rb +6 -1
- data/log/.gitignore +1 -0
- data/postageapp.gemspec +8 -10
- data/script/with +2 -2
- data/test/gemfiles/Gemfile.rails-2.3.x +1 -1
- data/test/gemfiles/Gemfile.rails-3.0.x +1 -1
- data/test/gemfiles/Gemfile.rails-3.1.x +1 -1
- data/test/gemfiles/Gemfile.rails-3.2.x +1 -1
- data/test/gemfiles/Gemfile.rails-4.0.x +1 -1
- data/test/gemfiles/Gemfile.rails-4.1.x +1 -1
- data/test/gemfiles/Gemfile.rails-4.2.x +1 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +2 -3
- data/test/gemfiles/Gemfile.rails-5.2.x +12 -0
- data/test/gemfiles/Gemfile.rails-6.0.x +12 -0
- data/test/gemfiles/Gemfile.rails-6.1.x +12 -0
- data/test/gemfiles/Gemfile.ruby +2 -3
- data/test/helper.rb +3 -3
- data/test/log/.gitignore +1 -0
- data/test/mailer/action_mailer_3/notifier.rb +1 -1
- data/test/tmp/.gitignore +1 -0
- data/test/travis_test.rb +58 -40
- data/test/{configuration_test.rb → unit/configuration_test.rb} +5 -3
- data/test/{failed_request_test.rb → unit/failed_request_test.rb} +6 -6
- data/test/{live_test.rb → unit/live_test.rb} +1 -36
- data/test/{mail_delivery_method_test.rb → unit/mail_delivery_method_test.rb} +1 -1
- data/test/{mailer_4_test.rb → unit/mailer_4_test.rb} +2 -2
- data/test/{mailer_helper_methods_test.rb → unit/mailer_helper_methods_test.rb} +4 -4
- data/test/{postageapp_test.rb → unit/postageapp_test.rb} +7 -1
- data/test/{rails_initialization_test.rb → unit/rails_initialization_test.rb} +2 -2
- data/test/{request_test.rb → unit/request_test.rb} +15 -15
- data/test/{response_test.rb → unit/response_test.rb} +4 -4
- data/test/unit/tmp/.gitignore +1 -0
- data/tmp/.gitignore +1 -0
- metadata +40 -46
- data/lib/postageapp/mailer/mailer_2.rb +0 -140
- data/lib/postageapp/mailer/mailer_3.rb +0 -190
- data/lib/postageapp/version.rb +0 -3
- data/test/mailer/action_mailer_2/notifier.rb +0 -77
- data/test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_simple_view.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb +0 -1
- data/test/mailer_2_test.rb +0 -95
- data/test/mailer_3_test.rb +0 -118
data/lib/postageapp/mailer.rb
CHANGED
@@ -8,15 +8,5 @@ rescue LoadError
|
|
8
8
|
end
|
9
9
|
|
10
10
|
if (defined?(ActionMailer))
|
11
|
-
|
12
|
-
# currently installed on the system. Assuming we're dealing only with
|
13
|
-
# ones that come with Rails 2 and 3
|
14
|
-
case (ActionMailer::VERSION::MAJOR)
|
15
|
-
when 3
|
16
|
-
require File.expand_path('mailer/mailer_3', File.dirname(__FILE__))
|
17
|
-
when 2
|
18
|
-
require File.expand_path('mailer/mailer_2', File.dirname(__FILE__))
|
19
|
-
else
|
20
|
-
require File.expand_path('mailer/mailer_4', File.dirname(__FILE__))
|
21
|
-
end
|
11
|
+
require_relative './mailer/mailer_4'
|
22
12
|
end
|
@@ -24,7 +24,7 @@
|
|
24
24
|
# Sending email
|
25
25
|
#
|
26
26
|
# # Create a PostageApp::Request object
|
27
|
-
# request = Notifier.signup_notification(user)
|
27
|
+
# request = Notifier.signup_notification(user)
|
28
28
|
# # Deliver the message and return a PostageApp::Response
|
29
29
|
# response = request.deliver_now
|
30
30
|
|
@@ -156,7 +156,7 @@ class PostageApp::Mailer < ActionMailer::Base
|
|
156
156
|
:template_name,
|
157
157
|
:template_path
|
158
158
|
)
|
159
|
-
|
159
|
+
|
160
160
|
m.headers.merge!(assignable)
|
161
161
|
|
162
162
|
# Render the templates and blocks
|
@@ -166,13 +166,29 @@ class PostageApp::Mailer < ActionMailer::Base
|
|
166
166
|
m
|
167
167
|
end
|
168
168
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
169
|
+
def find_first_mime_type(mt)
|
170
|
+
part = arguments['content'].detect{ |mime_type, body| mime_type == mt }
|
171
|
+
|
172
|
+
OpenStruct.new(mime_type: part[0], decoded: part[1]) if part
|
173
|
+
end
|
174
|
+
|
175
|
+
def header
|
176
|
+
@_message.arguments['headers']
|
177
|
+
end
|
178
|
+
|
179
|
+
def reply_to
|
180
|
+
@_message.arguments.dig('headers', 'reply_to')
|
181
|
+
end
|
182
|
+
|
183
|
+
def cc
|
184
|
+
@_message.arguments.dig('headers', 'cc')
|
185
|
+
end
|
186
|
+
|
187
|
+
def multipart?
|
188
|
+
%w[ text/plain text/html ].all? { |mt| arguments['content'].key?(mt) }
|
174
189
|
end
|
175
190
|
|
191
|
+
protected
|
176
192
|
def create_parts_from_responses(m, responses) #:nodoc:
|
177
193
|
content = m.arguments['content'] ||= { }
|
178
194
|
|
@@ -198,17 +214,17 @@ class PostageApp::Request
|
|
198
214
|
def deliver_now
|
199
215
|
inform_interceptors
|
200
216
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
217
|
+
return unless (perform_deliveries)
|
218
|
+
|
219
|
+
if (@delivery_method == Mail::TestMailer)
|
220
|
+
@delivery_method.deliveries << self
|
221
|
+
else
|
222
|
+
self.send
|
207
223
|
end
|
208
224
|
end
|
209
225
|
alias_method :deliver, :deliver_now
|
210
226
|
|
211
|
-
#
|
227
|
+
# Allows overriding the delivery method setting
|
212
228
|
def delivery_method(method = nil, settings = nil)
|
213
229
|
@delivery_method = method
|
214
230
|
end
|
data/lib/postageapp/request.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class PostageApp::Request
|
2
2
|
# == Constants ============================================================
|
3
3
|
|
4
|
-
API_VERSION = '1.
|
4
|
+
API_VERSION = '1.1'
|
5
5
|
|
6
6
|
HEADERS_DEFAULT = {
|
7
7
|
'Content-type' => 'application/json',
|
@@ -54,6 +54,11 @@ class PostageApp::Request
|
|
54
54
|
http = PostageApp.configuration.http
|
55
55
|
|
56
56
|
PostageApp.logger.info(self)
|
57
|
+
|
58
|
+
if (ENV['DEBUG'])
|
59
|
+
puts "// #{url}"
|
60
|
+
puts JSON.pretty_generate(self.arguments_to_send)
|
61
|
+
end
|
57
62
|
|
58
63
|
http_response =
|
59
64
|
begin
|
data/log/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*
|
data/postageapp.gemspec
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift(File.expand_path('
|
4
|
-
|
5
|
-
require 'postageapp/version'
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('./lib', __dir__))
|
6
4
|
|
7
5
|
Gem::Specification.new do |s|
|
8
6
|
s.name = 'postageapp'
|
9
|
-
s.version =
|
7
|
+
s.version = File.read(File.expand_path('VERSION', __dir__)).gsub(/\s/, '')
|
10
8
|
s.authors = [
|
11
9
|
'Scott Tadman',
|
12
10
|
'Oleg Khabarov',
|
13
|
-
'
|
11
|
+
'PostageApp Ltd.'
|
14
12
|
]
|
15
13
|
s.email = [
|
16
14
|
'tadman@postageapp.com',
|
17
|
-
'oleg@khabarov.ca'
|
15
|
+
'oleg@khabarov.ca',
|
16
|
+
'info@postageapp.com'
|
18
17
|
]
|
19
18
|
|
20
19
|
s.homepage = 'http://github.com/postageapp/postageapp-ruby'
|
@@ -22,13 +21,12 @@ Gem::Specification.new do |s|
|
|
22
21
|
s.summary = 'Client library for PostageApp Email API'
|
23
22
|
s.description = 'PostageApp Library for Ruby and Ruby on Rails applications'
|
24
23
|
s.license = 'MIT'
|
25
|
-
|
24
|
+
|
26
25
|
s.files = `git ls-files`.split("\n")
|
27
26
|
s.platform = Gem::Platform::RUBY
|
28
27
|
s.require_paths = [ 'lib' ]
|
29
28
|
|
30
|
-
s.required_ruby_version = '>=
|
31
|
-
|
32
|
-
s.add_dependency 'json', '>= 1.8'
|
29
|
+
s.required_ruby_version = '>= 2.5.0'
|
30
|
+
|
33
31
|
s.add_dependency 'mail', '~> 2.4'
|
34
32
|
end
|
data/script/with
CHANGED
@@ -20,8 +20,8 @@
|
|
20
20
|
|
21
21
|
# == Constants ==============================================================
|
22
22
|
|
23
|
-
GEMFILE_DIR = File.expand_path('../test/gemfiles',
|
24
|
-
GEMFILE_ROOT = File.expand_path('../Gemfile',
|
23
|
+
GEMFILE_DIR = File.expand_path('../test/gemfiles', __dir__)
|
24
|
+
GEMFILE_ROOT = File.expand_path('../Gemfile', __dir__)
|
25
25
|
|
26
26
|
# == Support Methods ========================================================
|
27
27
|
|
data/test/gemfiles/Gemfile.ruby
CHANGED
data/test/helper.rb
CHANGED
@@ -10,8 +10,8 @@ Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
|
|
10
10
|
|
11
11
|
require 'fileutils'
|
12
12
|
|
13
|
-
$LOAD_PATH.unshift(
|
14
|
-
$LOAD_PATH.unshift(File.join(
|
13
|
+
$LOAD_PATH.unshift(__dir__)
|
14
|
+
$LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
|
15
15
|
|
16
16
|
ENV['POSTAGEAPP_API_KEY'] ||= '__TEST_API_KEY__'
|
17
17
|
|
@@ -47,7 +47,7 @@ class MiniTest::Test
|
|
47
47
|
def setup
|
48
48
|
# Resetting to default configuration
|
49
49
|
|
50
|
-
PostageApp.configure(:
|
50
|
+
PostageApp.configure(reset: true) do |config|
|
51
51
|
config.requests_to_resend = %w( send_message )
|
52
52
|
config.project_root = File.expand_path('../', __FILE__)
|
53
53
|
config.logger = nil
|
data/test/log/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*
|
data/test/tmp/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*
|
data/test/travis_test.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require 'open3'
|
5
|
+
require 'shellwords'
|
4
6
|
|
5
|
-
|
7
|
+
require_relative './with_environment'
|
6
8
|
|
7
9
|
class TravisTest
|
8
10
|
extend WithEnvironment
|
9
11
|
|
10
12
|
ENV_VARIABLE = {
|
11
|
-
:
|
12
|
-
:
|
13
|
+
rvm: 'RBENV_VERSION',
|
14
|
+
version: 'RBENV_VERSION',
|
15
|
+
gemfile: 'BUNDLE_GEMFILE'
|
13
16
|
}
|
14
17
|
|
15
18
|
def self.bash_env(env)
|
@@ -20,30 +23,44 @@ class TravisTest
|
|
20
23
|
end.compact.join(' ')
|
21
24
|
end
|
22
25
|
|
23
|
-
def self.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
]
|
26
|
+
def self.environment(env)
|
27
|
+
env.map do |key, value|
|
28
|
+
[ ENV_VARIABLE[key], value ]
|
29
|
+
end.to_h
|
29
30
|
end
|
30
31
|
|
31
|
-
def self.
|
32
|
-
commands =
|
32
|
+
def self.shell!(commands, env)
|
33
|
+
commands = commands.collect do |s|
|
33
34
|
s % env
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
shell_cmds = [
|
38
|
+
'eval "$(rbenv init -)"',
|
39
|
+
'set -e',
|
40
|
+
*commands
|
41
|
+
].join('; ')
|
42
|
+
|
43
|
+
# p environment(env)
|
44
|
+
# puts shell_cmds
|
45
|
+
|
46
|
+
Open3.popen3(
|
47
|
+
environment(env),
|
48
|
+
shell_cmds
|
49
|
+
) do |_sin, sout, serr, proc|
|
50
|
+
status = proc.value.exitstatus
|
43
51
|
|
44
|
-
yield(
|
52
|
+
yield(status) if (block_given?)
|
45
53
|
|
46
|
-
|
54
|
+
status.tap do |status|
|
55
|
+
if (status != 0)
|
56
|
+
$stderr.puts 'Error code: %d' % status
|
57
|
+
end
|
58
|
+
|
59
|
+
if (status != 0 or ENV['VERBOSE'])
|
60
|
+
puts sout.read
|
61
|
+
puts serr.read
|
62
|
+
end
|
63
|
+
end
|
47
64
|
end
|
48
65
|
end
|
49
66
|
|
@@ -52,15 +69,15 @@ class TravisTest
|
|
52
69
|
|
53
70
|
travis_test.matrix.collect do |entry|
|
54
71
|
{
|
55
|
-
:
|
72
|
+
rvm: entry[:rvm]
|
56
73
|
}
|
57
74
|
end.uniq.each do |entry|
|
58
|
-
puts
|
75
|
+
puts 'Ruby %{rvm}' % entry
|
59
76
|
|
60
|
-
|
77
|
+
shell!(
|
61
78
|
[
|
62
|
-
|
63
|
-
|
79
|
+
'rbenv install %{version}',
|
80
|
+
'gem install bundler'
|
64
81
|
],
|
65
82
|
entry
|
66
83
|
)
|
@@ -77,9 +94,9 @@ class TravisTest
|
|
77
94
|
|
78
95
|
versions[entry[:rvm]] = true
|
79
96
|
|
80
|
-
|
97
|
+
shell!(
|
81
98
|
[
|
82
|
-
|
99
|
+
%q[ruby -e 'puts RUBY_VERSION']
|
83
100
|
],
|
84
101
|
entry
|
85
102
|
)
|
@@ -103,14 +120,15 @@ class TravisTest
|
|
103
120
|
results = { }
|
104
121
|
|
105
122
|
travis_test.matrix.each do |entry|
|
106
|
-
puts
|
123
|
+
puts 'RBENV_VERSION=%{rvm} BUNDLE_GEMFILE=%{gemfile}' % entry
|
107
124
|
|
108
125
|
gemfile_lock_remove!(entry[:gemfile])
|
109
126
|
|
110
|
-
|
127
|
+
shell!(
|
111
128
|
[
|
112
|
-
|
113
|
-
|
129
|
+
'gem install bundler --no-doc',
|
130
|
+
'bundle install --quiet',
|
131
|
+
'bundle exec rake test'
|
114
132
|
],
|
115
133
|
entry
|
116
134
|
) do |code|
|
@@ -125,13 +143,13 @@ class TravisTest
|
|
125
143
|
puts '%-20s %-24s %-6s' % [
|
126
144
|
entry[:rvm],
|
127
145
|
File.basename(entry[:gemfile]).sub(/\AGemfile\./,''),
|
128
|
-
code
|
146
|
+
code ? 'Pass' : 'Fail'
|
129
147
|
]
|
130
148
|
end
|
131
149
|
end
|
132
150
|
|
133
151
|
def travis_config_path
|
134
|
-
@travis_config_path ||= File.expand_path('../.travis.yml',
|
152
|
+
@travis_config_path ||= File.expand_path('../.travis.yml', __dir__)
|
135
153
|
end
|
136
154
|
|
137
155
|
def travis_config
|
@@ -143,24 +161,24 @@ class TravisTest
|
|
143
161
|
end
|
144
162
|
|
145
163
|
def ruby_versions
|
146
|
-
travis_config['rvm']
|
164
|
+
travis_config['rvm'].sort
|
147
165
|
end
|
148
166
|
|
149
167
|
def matrix_exclusions
|
150
|
-
travis_config
|
168
|
+
travis_config.dig('matrix', 'exclude')&.collect do |entry|
|
151
169
|
{
|
152
|
-
:
|
153
|
-
:
|
170
|
+
rvm: entry['rvm'],
|
171
|
+
gemfile: entry['gemfile']
|
154
172
|
}
|
155
|
-
end
|
173
|
+
end or [ ]
|
156
174
|
end
|
157
175
|
|
158
176
|
def matrix
|
159
177
|
ruby_versions.flat_map do |version|
|
160
178
|
gemfiles.collect do |gemfile|
|
161
179
|
{
|
162
|
-
:
|
163
|
-
:
|
180
|
+
rvm: version,
|
181
|
+
gemfile: gemfile
|
164
182
|
}
|
165
183
|
end
|
166
184
|
end - matrix_exclusions
|