postageapp 1.3.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +6 -0
  3. data/.travis.yml +9 -39
  4. data/{LICENSE → LICENSE.md} +1 -1
  5. data/README.md +117 -13
  6. data/Rakefile +15 -4
  7. data/VERSION +1 -0
  8. data/app/ingresses/action_mailbox/ingresses/postage_app/inbound_emails_controller.rb +52 -0
  9. data/app/ingresses/action_mailbox/ingresses/postage_app.rb +4 -0
  10. data/config/routes.rb +8 -0
  11. data/exe/postageapp +37 -0
  12. data/lib/generators/postageapp/postageapp_generator.rb +9 -6
  13. data/lib/postageapp/cli/command/config.rb +74 -0
  14. data/lib/postageapp/cli/command/create_mailbox.rb +21 -0
  15. data/lib/postageapp/cli/command/env.rb +58 -0
  16. data/lib/postageapp/cli/command/get_project_info.rb +3 -0
  17. data/lib/postageapp/cli/command.rb +110 -0
  18. data/lib/postageapp/cli.rb +14 -0
  19. data/lib/postageapp/configuration.rb +237 -74
  20. data/lib/postageapp/engine.rb +11 -0
  21. data/lib/postageapp/env.rb +9 -0
  22. data/lib/postageapp/mailer/mailer_4.rb +30 -14
  23. data/lib/postageapp/mailer.rb +1 -11
  24. data/lib/postageapp/rails/railtie.rb +1 -3
  25. data/lib/postageapp/request.rb +6 -1
  26. data/lib/postageapp.rb +53 -35
  27. data/log/.gitignore +1 -0
  28. data/postageapp.gemspec +7 -10
  29. data/script/with +2 -2
  30. data/test/gemfiles/Gemfile.rails-2.3.x +1 -1
  31. data/test/gemfiles/Gemfile.rails-3.0.x +1 -1
  32. data/test/gemfiles/Gemfile.rails-3.1.x +1 -1
  33. data/test/gemfiles/Gemfile.rails-3.2.x +1 -1
  34. data/test/gemfiles/Gemfile.rails-4.0.x +1 -1
  35. data/test/gemfiles/Gemfile.rails-4.1.x +1 -1
  36. data/test/gemfiles/Gemfile.rails-4.2.x +1 -2
  37. data/test/gemfiles/Gemfile.rails-5.0.x +2 -3
  38. data/test/gemfiles/Gemfile.rails-5.2.x +12 -0
  39. data/test/gemfiles/Gemfile.rails-6.0.x +12 -0
  40. data/test/gemfiles/Gemfile.rails-6.1.x +12 -0
  41. data/test/gemfiles/Gemfile.ruby +2 -3
  42. data/test/helper.rb +5 -3
  43. data/test/log/.gitignore +1 -0
  44. data/test/mailer/action_mailer_3/notifier.rb +1 -1
  45. data/test/tmp/.gitignore +1 -0
  46. data/test/travis_test.rb +58 -40
  47. data/test/{configuration_test.rb → unit/configuration_test.rb} +18 -12
  48. data/test/{failed_request_test.rb → unit/failed_request_test.rb} +6 -6
  49. data/test/{live_test.rb → unit/live_test.rb} +4 -39
  50. data/test/{mail_delivery_method_test.rb → unit/mail_delivery_method_test.rb} +1 -1
  51. data/test/{mailer_4_test.rb → unit/mailer_4_test.rb} +2 -2
  52. data/test/{mailer_helper_methods_test.rb → unit/mailer_helper_methods_test.rb} +4 -4
  53. data/test/{postageapp_test.rb → unit/postageapp_test.rb} +7 -1
  54. data/test/{rails_initialization_test.rb → unit/rails_initialization_test.rb} +2 -2
  55. data/test/{request_test.rb → unit/request_test.rb} +18 -17
  56. data/test/{response_test.rb → unit/response_test.rb} +4 -4
  57. data/test/unit/tmp/.gitignore +1 -0
  58. data/tmp/.gitignore +1 -0
  59. metadata +41 -48
  60. data/lib/postageapp/mailer/mailer_2.rb +0 -140
  61. data/lib/postageapp/mailer/mailer_3.rb +0 -190
  62. data/lib/postageapp/version.rb +0 -3
  63. data/test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb +0 -1
  64. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb +0 -1
  65. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb +0 -1
  66. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb +0 -1
  67. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb +0 -1
  68. data/test/mailer/action_mailer_2/notifier/with_simple_view.erb +0 -1
  69. data/test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb +0 -1
  70. data/test/mailer/action_mailer_2/notifier.rb +0 -77
  71. data/test/mailer_2_test.rb +0 -95
  72. data/test/mailer_3_test.rb +0 -118
@@ -0,0 +1,11 @@
1
+ module PostageApp
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace PostageApp
4
+
5
+ initializer 'postageapp' do |app|
6
+ if (app.config.respond_to?(:action_mailbox))
7
+ app.config.action_mailbox.ingress = :postage_app
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module PostageApp::Env
2
+ def self.rails?
3
+ defined?(Rails)
4
+ end
5
+
6
+ def self.rails_with_encrypted_credentials?
7
+ defined?(Rails) and Rails.respond_to?(:application) and Rails.application.respond_to?(:credentials)
8
+ end
9
+ 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
- protected
170
- def each_template(paths, name, &block) #:nodoc:
171
- (lookup_context.find_all(name, paths) || [ ]).uniq do |t|
172
- t.formats
173
- end.each(&block)
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
- if (perform_deliveries)
202
- if (@delivery_method == Mail::TestMailer)
203
- @delivery_method.deliveries << self
204
- else
205
- self.send
206
- end
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
- # Not 100% on this, but I need to assign this so I can properly handle deliver method
227
+ # Allows overriding the delivery method setting
212
228
  def delivery_method(method = nil, settings = nil)
213
229
  @delivery_method = method
214
230
  end
@@ -8,15 +8,5 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  if (defined?(ActionMailer))
11
- # Loading PostageApp::Mailer class depending on what action_mailer is
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
@@ -1,7 +1,5 @@
1
- require 'postageapp'
2
-
3
1
  if (defined?(ActionMailer))
4
- require 'postageapp/mailer'
2
+ require_relative '../mailer'
5
3
 
6
4
  # Register as a delivery method with ActionMailer
7
5
  ActionMailer::Base.add_delivery_method(
@@ -1,7 +1,7 @@
1
1
  class PostageApp::Request
2
2
  # == Constants ============================================================
3
3
 
4
- API_VERSION = '1.0'
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/lib/postageapp.rb CHANGED
@@ -9,70 +9,88 @@ require 'base64'
9
9
 
10
10
  module PostageApp
11
11
  class Error < StandardError ; end
12
-
12
+
13
13
  # Call this method to modify your configuration
14
14
  # Example:
15
15
  # PostageApp.configure do |config|
16
- # config.api_key = '1234567890abcdef'
17
- # config.recipient_override = 'test@test.test' if Rails.env.staging?
16
+ # config.api_key = '1234567890abcdef'
17
+ #
18
+ # if Rails.env.staging?
19
+ # config.recipient_override = 'test@test.test'
20
+ # end
18
21
  # end
19
- #
22
+ #
20
23
  # If you do not want/need to initialize the gem in this way, you can use the environment
21
24
  # variable POSTAGEAPP_API_KEY to set up your key.
22
-
23
- def self.configure(reset = false)
25
+
26
+ VERSION = File.read(File.expand_path('../VERSION', __dir__)).gsub(/\s/, '')
27
+
28
+ def self.version
29
+ VERSION
30
+ end
31
+
32
+ def self.configure(reset: false)
24
33
  if (reset)
25
- self.configuration_reset!
34
+ self.config_reset!
26
35
  end
27
36
 
28
- yield(self.configuration)
37
+ yield(self.config)
29
38
  end
30
-
39
+
31
40
  # Accessor for the PostageApp::Configuration object
32
41
  # Example use:
33
42
  # PostageApp.configuration.api_key = '1234567890abcdef'
34
- def self.configuration
35
- @configuration ||= Configuration.new
43
+ def self.config
44
+ @config ||= Configuration.new
36
45
  end
37
46
 
38
- def self.configuration_reset!
39
- @configuration = nil
47
+ def self.config_reset!
48
+ @config = nil
40
49
  end
41
50
 
42
51
  class << self
43
- alias :config :configuration
52
+ alias_method :configuration_reset!, :config_reset!
53
+ alias_method :configuration, :config
44
54
  end
45
-
55
+
46
56
  # Logger for the plugin
47
57
  def self.logger
48
58
  @logger ||= begin
49
- configuration.logger || PostageApp::Logger.new(
50
- if (configuration.project_root)
51
- FileUtils.mkdir_p(File.join(File.expand_path(configuration.project_root), 'log'))
52
- File.join(configuration.project_root, "log/postageapp_#{configuration.environment}.log")
59
+ config.logger || PostageApp::Logger.new(
60
+ if (config.project_root)
61
+ FileUtils.mkdir_p(File.join(File.expand_path(config.project_root), 'log'))
62
+ File.join(config.project_root, "log/postageapp_#{config.environment}.log")
53
63
  else
54
- STDOUT
64
+ $stdout
55
65
  end
56
66
  )
57
67
  end
58
68
  end
59
69
  end
60
70
 
61
- require 'postageapp/configuration'
62
- require 'postageapp/diagnostics'
63
- require 'postageapp/failed_request'
64
- require 'postageapp/http'
65
- require 'postageapp/logger'
66
- require 'postageapp/request'
67
- require 'postageapp/response'
68
- require 'postageapp/mail'
69
- require 'postageapp/mail/delivery_method'
70
- require 'postageapp/utils'
71
- require 'postageapp/version'
72
-
73
- require 'postageapp/rails/railtie' if (defined?(Rails::Railtie))
74
-
75
- require 'postageapp/mail/extensions'
71
+ require_relative './postageapp/env'
72
+
73
+ if (PostageApp::Env.rails?)
74
+ require_relative './postageapp/engine'
75
+ # require 'postageapp/ingresses/postage_app'
76
+ end
77
+
78
+ require_relative './postageapp/configuration'
79
+ require_relative './postageapp/diagnostics'
80
+ require_relative './postageapp/failed_request'
81
+ require_relative './postageapp/http'
82
+ require_relative './postageapp/logger'
83
+ require_relative './postageapp/request'
84
+ require_relative './postageapp/response'
85
+ require_relative './postageapp/mail'
86
+ require_relative './postageapp/mail/delivery_method'
87
+ require_relative './postageapp/utils'
88
+
89
+ if (defined?(Rails::Railtie))
90
+ require_relative './postageapp/rails/railtie'
91
+ end
92
+
93
+ require_relative './postageapp/mail/extensions'
76
94
 
77
95
  if (defined?(::Mail))
78
96
  PostageApp::Mail::Extensions.install!
data/log/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *
data/postageapp.gemspec CHANGED
@@ -1,34 +1,31 @@
1
1
  # encoding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
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 = PostageApp::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
- 'The Working Group Inc.'
11
+ 'PostageApp Ltd.'
14
12
  ]
15
13
  s.email = [
16
14
  'tadman@postageapp.com',
17
15
  'oleg@khabarov.ca'
18
16
  ]
19
17
 
20
- s.homepage = 'http://github.com/postageapp/postageapp-ruby'
18
+ s.homepage = 'https://github.com/postageapp/postageapp-ruby'
21
19
 
22
20
  s.summary = 'Client library for PostageApp Email API'
23
21
  s.description = 'PostageApp Library for Ruby and Ruby on Rails applications'
24
22
  s.license = 'MIT'
25
-
23
+
26
24
  s.files = `git ls-files`.split("\n")
27
25
  s.platform = Gem::Platform::RUBY
28
26
  s.require_paths = [ 'lib' ]
29
27
 
30
- s.required_ruby_version = '>= 1.9.3'
31
-
32
- s.add_dependency 'json', '~> 1.8'
28
+ s.required_ruby_version = '>= 2.5.0'
29
+
33
30
  s.add_dependency 'mail', '~> 2.4'
34
31
  end
data/script/with CHANGED
@@ -20,8 +20,8 @@
20
20
 
21
21
  # == Constants ==============================================================
22
22
 
23
- GEMFILE_DIR = File.expand_path('../test/gemfiles', File.dirname(__FILE__))
24
- GEMFILE_ROOT = File.expand_path('../Gemfile', File.dirname(__FILE__))
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
 
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # rubygems 1.8.30
4
4
 
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # rubygems 1.8.30
4
4
 
@@ -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
@@ -1,8 +1,7 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 5.0'
3
+ gem 'rails', '~> 5.0.7.2'
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.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', '~> 1.8.3'
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'