postageapp 1.2.5 → 1.4.0

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.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +10 -30
  4. data/{LICENSE → LICENSE.md} +1 -1
  5. data/README.md +118 -68
  6. data/Rakefile +15 -4
  7. data/VERSION +1 -0
  8. data/app/ingresses/action_mailbox/ingresses/postage_app.rb +2 -0
  9. data/app/ingresses/action_mailbox/ingresses/postage_app/inbound_emails_controller.rb +50 -0
  10. data/config/routes.rb +6 -0
  11. data/doc/RAILS2.md +54 -0
  12. data/doc/RAILS3.md +15 -0
  13. data/exe/postageapp +37 -0
  14. data/generators/postageapp/templates/postageapp_tasks.rake +25 -8
  15. data/lib/generators/postageapp/postageapp_generator.rb +9 -6
  16. data/lib/postageapp.rb +59 -30
  17. data/lib/postageapp/cli.rb +14 -0
  18. data/lib/postageapp/cli/command.rb +110 -0
  19. data/lib/postageapp/cli/command/config.rb +74 -0
  20. data/lib/postageapp/cli/command/create_mailbox.rb +21 -0
  21. data/lib/postageapp/cli/command/env.rb +58 -0
  22. data/lib/postageapp/cli/command/get_project_info.rb +3 -0
  23. data/lib/postageapp/configuration.rb +267 -63
  24. data/lib/postageapp/diagnostics.rb +30 -0
  25. data/lib/postageapp/engine.rb +9 -0
  26. data/lib/postageapp/env.rb +9 -0
  27. data/lib/postageapp/failed_request.rb +2 -0
  28. data/lib/postageapp/http.rb +32 -0
  29. data/lib/postageapp/logger.rb +2 -0
  30. data/lib/postageapp/mail.rb +1 -1
  31. data/lib/postageapp/mailer.rb +2 -11
  32. data/lib/postageapp/mailer/mailer_4.rb +29 -15
  33. data/lib/postageapp/rails/railtie.rb +1 -3
  34. data/lib/postageapp/request.rb +27 -11
  35. data/lib/postageapp/response.rb +22 -8
  36. data/lib/postageapp/utils.rb +0 -11
  37. data/log/.gitignore +1 -0
  38. data/postageapp.gemspec +16 -17
  39. data/script/with +3 -3
  40. data/test/gemfiles/Gemfile.rails-2.3.x +1 -1
  41. data/test/gemfiles/Gemfile.rails-3.0.x +1 -1
  42. data/test/gemfiles/Gemfile.rails-3.1.x +1 -1
  43. data/test/gemfiles/Gemfile.rails-3.2.x +1 -1
  44. data/test/gemfiles/Gemfile.rails-4.0.x +1 -1
  45. data/test/gemfiles/Gemfile.rails-4.1.x +1 -1
  46. data/test/gemfiles/Gemfile.rails-4.2.x +1 -2
  47. data/test/gemfiles/Gemfile.rails-5.0.x +12 -0
  48. data/test/gemfiles/Gemfile.rails-5.2.x +12 -0
  49. data/test/gemfiles/Gemfile.rails-6.0.x +12 -0
  50. data/test/gemfiles/Gemfile.rails-6.1.x +12 -0
  51. data/test/gemfiles/Gemfile.ruby +2 -3
  52. data/test/helper.rb +6 -17
  53. data/test/log/.gitignore +1 -0
  54. data/test/mailer/action_mailer_3/notifier.rb +10 -10
  55. data/test/tmp/.gitignore +1 -0
  56. data/test/travis_test.rb +58 -40
  57. data/test/{configuration_test.rb → unit/configuration_test.rb} +35 -22
  58. data/test/{failed_request_test.rb → unit/failed_request_test.rb} +6 -6
  59. data/test/{live_test.rb → unit/live_test.rb} +33 -43
  60. data/test/{mail_delivery_method_test.rb → unit/mail_delivery_method_test.rb} +1 -1
  61. data/test/{mailer_4_test.rb → unit/mailer_4_test.rb} +2 -2
  62. data/test/{mailer_helper_methods_test.rb → unit/mailer_helper_methods_test.rb} +4 -4
  63. data/test/{postageapp_test.rb → unit/postageapp_test.rb} +10 -1
  64. data/test/{rails_initialization_test.rb → unit/rails_initialization_test.rb} +2 -2
  65. data/test/{request_test.rb → unit/request_test.rb} +24 -23
  66. data/test/{response_test.rb → unit/response_test.rb} +4 -4
  67. data/test/unit/tmp/.gitignore +1 -0
  68. data/tmp/.gitignore +1 -0
  69. metadata +60 -68
  70. data/lib/postageapp/mailer/mailer_2.rb +0 -140
  71. data/lib/postageapp/mailer/mailer_3.rb +0 -190
  72. data/lib/postageapp/version.rb +0 -3
  73. data/test/mailer/action_mailer_2/notifier.rb +0 -76
  74. data/test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb +0 -1
  75. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb +0 -1
  76. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb +0 -1
  77. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb +0 -1
  78. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb +0 -1
  79. data/test/mailer/action_mailer_2/notifier/with_simple_view.erb +0 -1
  80. data/test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb +0 -1
  81. data/test/mailer_2_test.rb +0 -95
  82. data/test/mailer_3_test.rb +0 -118
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 3.1.0'
4
4
  gem 'json'
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 3.2.0'
4
4
 
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 4.0.0'
4
4
 
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 4.1.0'
4
4
 
@@ -1,8 +1,7 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 4.2.0'
4
4
 
5
- gem 'json'
6
5
  gem 'mail'
7
6
 
8
7
  group :test do
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.0.7.2'
4
+
5
+ gem 'mail'
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ gem 'minitest'
10
+ gem 'minitest-reporters'
11
+ gem 'mocha'
12
+ end
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.2'
4
+
5
+ gem 'mail'
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ gem 'minitest'
10
+ gem 'minitest-reporters'
11
+ gem 'mocha'
12
+ end
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 6.0.3.6'
4
+
5
+ gem 'mail'
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ gem 'minitest'
10
+ gem 'minitest-reporters'
11
+ gem 'mocha'
12
+ end
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 6.1'
4
+
5
+ gem 'mail'
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ gem 'minitest'
10
+ gem 'minitest-reporters'
11
+ gem 'mocha'
12
+ end
@@ -1,8 +1,7 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'json'
4
3
  gem 'mail'
5
- gem 'mime-types', '2.99.1' # Locked for 1.9 compatibility
4
+ gem 'mime-types'
6
5
 
7
6
  group :test do
8
7
  gem 'rake'
data/test/helper.rb CHANGED
@@ -10,8 +10,10 @@ Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
10
10
 
11
11
  require 'fileutils'
12
12
 
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(__dir__)
14
+ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
15
+
16
+ ENV['POSTAGEAPP_API_KEY'] ||= '__TEST_API_KEY__'
15
17
 
16
18
  require 'mail'
17
19
 
@@ -45,24 +47,11 @@ class MiniTest::Test
45
47
  def setup
46
48
  # Resetting to default configuration
47
49
 
48
- PostageApp.configure do |config|
49
- config.api_key = '1234567890abcdef'
50
- config.secure = true
51
- config.protocol = 'https'
52
- config.host = 'api.postageapp.com'
53
- config.port = 443
54
- config.proxy_host = nil
55
- config.proxy_port = nil
56
- config.proxy_user = nil
57
- config.proxy_pass = nil
58
- config.http_open_timeout = 5
59
- config.http_read_timeout = 10
60
- config.recipient_override = nil
50
+ PostageApp.configure(reset: true) do |config|
61
51
  config.requests_to_resend = %w( send_message )
62
52
  config.project_root = File.expand_path('../', __FILE__)
63
- config.environment = 'production'
64
53
  config.logger = nil
65
- config.framework = 'undefined framework'
54
+ config.framework = 'Ruby [Test]'
66
55
  end
67
56
 
68
57
  if (defined?(ActionMailer))
@@ -0,0 +1 @@
1
+ *
@@ -1,7 +1,7 @@
1
- # Test mailer for ActionMailer 3 and 4
1
+ # Test mailer for ActionMailer 3.x+
2
2
 
3
3
  class Notifier < PostageApp::Mailer
4
- self.append_view_path(File.dirname(__FILE__))
4
+ self.append_view_path(__dir__)
5
5
 
6
6
  def blank
7
7
  # ... nothing to see here
@@ -66,9 +66,9 @@ class Notifier < PostageApp::Mailer
66
66
  postageapp_uid 'custom_uid'
67
67
 
68
68
  mail(
69
- :from => 'sender@example.com',
70
- :subject => 'Test Message',
71
- :to => {
69
+ from: 'sender@example.com',
70
+ subject: 'Test Message',
71
+ to: {
72
72
  'test1@example.net' => { 'name' => 'Test 1' },
73
73
  'test2@example.net' => { 'name' => 'Test 2' }
74
74
  }
@@ -76,11 +76,11 @@ class Notifier < PostageApp::Mailer
76
76
  end
77
77
 
78
78
  private
79
- def headers_hash(options = { })
79
+ def headers_hash(options = nil)
80
80
  {
81
- :from => 'sender@example.com',
82
- :to => 'recipient@example.net',
83
- :subject => 'Test Message'
84
- }.merge(options)
81
+ from: 'sender@example.com',
82
+ to: 'recipient@example.net',
83
+ subject: 'Test Message'
84
+ }.merge(options || { })
85
85
  end
86
86
  end
@@ -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
- require File.expand_path('with_environment', File.dirname(__FILE__))
7
+ require_relative './with_environment'
6
8
 
7
9
  class TravisTest
8
10
  extend WithEnvironment
9
11
 
10
12
  ENV_VARIABLE = {
11
- :rvm => "RBENV_VERSION",
12
- :gemfile => "BUNDLE_GEMFILE"
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.env_expanded(env)
24
- Hash[
25
- env.collect do |key, value|
26
- [ ENV_VARIABLE[key], value ]
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.shell_command!(args, env)
32
- commands = args.collect do |s|
32
+ def self.shell!(commands, env)
33
+ commands = commands.collect do |s|
33
34
  s % env
34
35
  end
35
36
 
36
- env_expanded(env).each do |key, value|
37
- puts 'export %s=%s' % [ key, value ]
38
- end
39
- puts(commands.join(' && '))
40
-
41
- with_environment(env_expanded(env)) do
42
- result = system(commands.join(' && '))
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(result) if (block_given?)
52
+ yield(status) if (block_given?)
45
53
 
46
- result
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
- :rvm => entry[:rvm]
72
+ rvm: entry[:rvm]
56
73
  }
57
74
  end.uniq.each do |entry|
58
- puts "Ruby %{rvm}" % entry
75
+ puts 'Ruby %{rvm}' % entry
59
76
 
60
- shell_command!(
77
+ shell!(
61
78
  [
62
- "rbenv install %{version}",
63
- "gem install bundler"
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
- shell_command!(
97
+ shell!(
81
98
  [
82
- "ruby -e 'puts RUBY_VERSION'"
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 "RBENV_VERSION=%{rvm} BUNDLE_GEMFILE=%{gemfile}" % entry
123
+ puts 'RBENV_VERSION=%{rvm} BUNDLE_GEMFILE=%{gemfile}' % entry
107
124
 
108
125
  gemfile_lock_remove!(entry[:gemfile])
109
126
 
110
- shell_command!(
127
+ shell!(
111
128
  [
112
- "bundle install --quiet",
113
- "rake test"
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', File.dirname(__FILE__))
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['matrix']['exclude'].collect do |entry|
168
+ travis_config.dig('matrix', 'exclude')&.collect do |entry|
151
169
  {
152
- :rvm => entry['rvm'],
153
- :gemfile => entry['gemfile']
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
- :rvm => version,
163
- :gemfile => gemfile
180
+ rvm: version,
181
+ gemfile: gemfile
164
182
  }
165
183
  end
166
184
  end - matrix_exclusions
@@ -1,35 +1,42 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative '../helper'
2
2
 
3
3
  class ConfigurationTest < MiniTest::Test
4
4
  def test_initialization_defaults
5
5
  config = PostageApp::Configuration.new
6
-
6
+
7
7
  assert_equal true, config.secure
8
- assert_equal nil,config.api_key
9
- assert_equal 'https', config.protocol
10
- assert_equal 'api.postageapp.com', config.host
8
+
9
+ if (ENV['POSTAGEAPP_API_KEY'])
10
+ assert_equal ENV['POSTAGEAPP_API_KEY'], config.api_key
11
+ end
12
+
13
+ assert_equal 'https', config.scheme
14
+ assert_equal ENV['POSTAGEAPP_API_HOST'] || 'api.postageapp.com', config.host
11
15
  assert_equal 443, config.port
12
- assert_equal nil, config.proxy_host
13
- assert_equal nil, config.proxy_port
14
- assert_equal nil, config.proxy_user
15
- assert_equal nil, config.proxy_pass
16
- assert_equal 5, config.http_open_timeout
17
- assert_equal 10, config.http_read_timeout
18
- assert_equal nil, config.recipient_override
16
+
17
+ assert_nil config.proxy_host
18
+ assert_equal 1080, config.proxy_port
19
+ assert_nil config.proxy_user
20
+ assert_nil config.proxy_pass
21
+
22
+ assert_equal 5, config.http_open_timeout
23
+ assert_equal 10, config.http_read_timeout
24
+
25
+ assert_nil config.recipient_override
19
26
  assert_equal %w( send_message ), config.requests_to_resend
20
- assert_equal nil, config.project_root
27
+ refute_nil config.project_root
21
28
  assert_equal 'production', config.environment
22
- assert_equal nil, config.logger
23
- assert_equal 'Ruby', config.framework
29
+ assert_nil config.logger
30
+ assert_match 'Ruby', config.framework
24
31
  end
25
32
 
26
33
  def test_initialization_overrides
27
34
  config = PostageApp::Configuration.new
28
35
 
29
- config.protocol = 'http'
30
- config.port = 999
36
+ config.scheme = 'http'
37
+ config.port = 999
31
38
 
32
- assert_equal 'http', config.protocol
39
+ assert_equal 'http', config.scheme
33
40
  assert_equal 999, config.port
34
41
  end
35
42
 
@@ -37,19 +44,22 @@ class ConfigurationTest < MiniTest::Test
37
44
  config = PostageApp::Configuration.new
38
45
 
39
46
  config.secure = true
47
+
40
48
  assert_equal true, config.secure
41
- assert_equal 'https', config.protocol
49
+ assert_equal 'https', config.scheme
42
50
  assert_equal 443, config.port
43
51
 
44
- assert config.secure?
52
+ assert_equal true, config.secure?
53
+ assert_equal true, config.port_default?
45
54
  end
46
55
 
47
56
  def test_initialization_for_insecure
48
57
  config = PostageApp::Configuration.new
49
58
 
50
59
  config.secure = false
60
+
51
61
  assert_equal false, config.secure
52
- assert_equal 'http', config.protocol
62
+ assert_equal 'http', config.scheme
53
63
  assert_equal 80, config.port
54
64
 
55
65
  assert !config.secure?
@@ -70,6 +80,9 @@ class ConfigurationTest < MiniTest::Test
70
80
  config = PostageApp::Configuration.new
71
81
 
72
82
  config.host = 'api.postageapp.com'
73
- assert_equal 'https://api.postageapp.com:443', config.url
83
+
84
+ assert_equal true, config.port_default?
85
+
86
+ assert_equal 'https://api.postageapp.com', config.url
74
87
  end
75
88
  end