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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +10 -30
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +118 -68
- 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/doc/RAILS2.md +54 -0
- data/doc/RAILS3.md +15 -0
- data/exe/postageapp +37 -0
- data/generators/postageapp/templates/postageapp_tasks.rake +25 -8
- data/lib/generators/postageapp/postageapp_generator.rb +9 -6
- data/lib/postageapp.rb +59 -30
- 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 +267 -63
- data/lib/postageapp/diagnostics.rb +30 -0
- data/lib/postageapp/engine.rb +9 -0
- data/lib/postageapp/env.rb +9 -0
- data/lib/postageapp/failed_request.rb +2 -0
- data/lib/postageapp/http.rb +32 -0
- data/lib/postageapp/logger.rb +2 -0
- data/lib/postageapp/mail.rb +1 -1
- data/lib/postageapp/mailer.rb +2 -11
- data/lib/postageapp/mailer/mailer_4.rb +29 -15
- data/lib/postageapp/rails/railtie.rb +1 -3
- data/lib/postageapp/request.rb +27 -11
- data/lib/postageapp/response.rb +22 -8
- data/lib/postageapp/utils.rb +0 -11
- data/log/.gitignore +1 -0
- data/postageapp.gemspec +16 -17
- data/script/with +3 -3
- 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 +12 -0
- 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 +6 -17
- data/test/log/.gitignore +1 -0
- data/test/mailer/action_mailer_3/notifier.rb +10 -10
- data/test/tmp/.gitignore +1 -0
- data/test/travis_test.rb +58 -40
- data/test/{configuration_test.rb → unit/configuration_test.rb} +35 -22
- data/test/{failed_request_test.rb → unit/failed_request_test.rb} +6 -6
- data/test/{live_test.rb → unit/live_test.rb} +33 -43
- 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} +10 -1
- data/test/{rails_initialization_test.rb → unit/rails_initialization_test.rb} +2 -2
- data/test/{request_test.rb → unit/request_test.rb} +24 -23
- data/test/{response_test.rb → unit/response_test.rb} +4 -4
- data/test/unit/tmp/.gitignore +1 -0
- data/tmp/.gitignore +1 -0
- metadata +60 -68
- 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 -76
- 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/doc/RAILS2.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Rails 2.x
|
2
|
+
|
3
|
+
These notes describe behavior specific to the Rails 2.x environment. Unless
|
4
|
+
otherwise specified the approach in the main documentation applies.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
In `config/environment.rb` add the following:
|
9
|
+
|
10
|
+
config.gem 'postageapp'
|
11
|
+
|
12
|
+
Then from the Rails project's root run:
|
13
|
+
|
14
|
+
rake gems:install
|
15
|
+
rake gems:unpack GEM=postageapp
|
16
|
+
script/generate postageapp --api-key PROJECT_API_KEY
|
17
|
+
|
18
|
+
## Mailer Creation
|
19
|
+
|
20
|
+
Here's an example of a mailer you'd set in in a Rails 2 environment:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'postageapp/mailer'
|
24
|
+
|
25
|
+
class Notifier < PostageApp::Mailer
|
26
|
+
def signup_notification
|
27
|
+
from 'system@example.com'
|
28
|
+
subject 'New Account Information'
|
29
|
+
|
30
|
+
# Recipients can be in any format API allows.
|
31
|
+
# Here's an example of a hash format
|
32
|
+
recipients(
|
33
|
+
'recipient_1@example.com' => {
|
34
|
+
'variable_name_1' => 'value',
|
35
|
+
'variable_name_2' => 'value'
|
36
|
+
},
|
37
|
+
'recipient_2@example.com' => {
|
38
|
+
'variable_name_1' => 'value',
|
39
|
+
'variable_name_2' => 'value'
|
40
|
+
},
|
41
|
+
)
|
42
|
+
|
43
|
+
attachment(
|
44
|
+
:content_type => 'application/zip',
|
45
|
+
:filename => 'example.zip',
|
46
|
+
:body => File.read('/path/to/example.zip'
|
47
|
+
)
|
48
|
+
|
49
|
+
# PostageApp specific elements:
|
50
|
+
postageapp_template 'example_template'
|
51
|
+
postageapp_variables 'global_variable' => 'value'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
data/doc/RAILS3.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Rails 3.x
|
2
|
+
|
3
|
+
These notes describe behavior specific to the Rails 2.x environment. Unless
|
4
|
+
otherwise specified the approach in the main documentation applies.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add the `postageapp` gem to your Gemfile:
|
9
|
+
|
10
|
+
gem 'postageapp'
|
11
|
+
|
12
|
+
Then from the Rails project's root run:
|
13
|
+
|
14
|
+
bundle install
|
15
|
+
script/rails generate postageapp --api-key PROJECT_API_KEY
|
data/exe/postageapp
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path('../lib', __dir__)
|
4
|
+
|
5
|
+
require 'postageapp'
|
6
|
+
require 'postageapp/cli'
|
7
|
+
|
8
|
+
exit_code = -1
|
9
|
+
|
10
|
+
begin
|
11
|
+
if (ARGV.length > 0)
|
12
|
+
PostageApp::CLI.parse!(*ARGV)
|
13
|
+
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue PostageApp::CLI::Command::MissingArguments
|
18
|
+
exit(-20)
|
19
|
+
rescue PostageApp::CLI::Command::APICallError
|
20
|
+
exit(-30)
|
21
|
+
rescue PostageApp::CLI::UnknownCommand => e
|
22
|
+
$stderr.puts("Error: #{e}")
|
23
|
+
exit_code = -11
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "usage: postageapp command [options]"
|
27
|
+
puts
|
28
|
+
puts "commands:"
|
29
|
+
|
30
|
+
PostageApp::CLI::Command.defined.each do |command, _|
|
31
|
+
puts " #{command}"
|
32
|
+
end
|
33
|
+
|
34
|
+
puts
|
35
|
+
puts "* Documentation: https://dev.postageapp.com/api/"
|
36
|
+
|
37
|
+
exit(exit_code)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :postageapp do
|
2
2
|
desc 'Show the current PostageApp configuration'
|
3
|
-
task :
|
3
|
+
task config: :environment do
|
4
4
|
puts "PostageApp Configuration"
|
5
5
|
puts "------------------------"
|
6
6
|
puts
|
@@ -30,12 +30,29 @@ namespace :postageapp do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
desc 'Verify the PostageApp gem installation by requesting project info from the API'
|
33
|
-
task :
|
34
|
-
|
35
|
-
|
33
|
+
task test: :environment do
|
34
|
+
diag = PostageApp::Diagnostics.new(PostageApp.config)
|
35
|
+
|
36
|
+
puts "Resolving #{PostageApp.config.host.inspect}"
|
37
|
+
if (resolved = diag.host_resolved)
|
38
|
+
puts "\t#{resolved.join(',')}"
|
39
|
+
else
|
40
|
+
puts "\tCouldn't be resolved. [ERROR]"
|
41
|
+
end
|
42
|
+
|
43
|
+
if (PostageApp.config.proxy?)
|
44
|
+
puts "Resolving #{PostageApp.config.proxy_host.inspect}"
|
45
|
+
if (resolved = diag.proxy_host_resolved)
|
46
|
+
puts "\t#{resolved.join(',')}"
|
47
|
+
else
|
48
|
+
puts "\tCouldn't be resolved. [ERROR]"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
puts "Trying to contact #{PostageApp.configuration.url}..."
|
36
53
|
response = PostageApp::Request.new(:get_project_info).send
|
37
54
|
|
38
|
-
if response.ok?
|
55
|
+
if (response.ok?)
|
39
56
|
project_name = response.data['project']['name']
|
40
57
|
project_url = response.data['project']['url']
|
41
58
|
user_emails = response.data['project']['users']
|
@@ -52,7 +69,8 @@ END
|
|
52
69
|
# Most likely a single user if it's a new project
|
53
70
|
puts 'Sending test message to users in the project...'
|
54
71
|
r = send_test_message(user_emails)
|
55
|
-
|
72
|
+
|
73
|
+
if (r.ok?)
|
56
74
|
puts "Message was successfully sent!\n\n"
|
57
75
|
puts 'Your application is ready to use PostageApp!'
|
58
76
|
else
|
@@ -60,7 +78,6 @@ END
|
|
60
78
|
puts 'This was the response:'
|
61
79
|
puts r.to_yaml
|
62
80
|
end
|
63
|
-
|
64
81
|
else
|
65
82
|
puts 'Failed to fetch information about your project. This was the response:'
|
66
83
|
puts response.to_yaml
|
@@ -68,7 +85,7 @@ END
|
|
68
85
|
end
|
69
86
|
|
70
87
|
desc 'Manually trigger resend of all failed emails'
|
71
|
-
task :
|
88
|
+
task resend_failed_emails: :environment do
|
72
89
|
puts 'Attempting to resend failed emails...'
|
73
90
|
PostageApp::FailedRequest.resend_all
|
74
91
|
puts 'Done!'
|
@@ -10,18 +10,21 @@ class PostageappGenerator < Rails::Generators::Base
|
|
10
10
|
def self.source_root
|
11
11
|
@__source_root ||= File.expand_path(
|
12
12
|
'../../../generators/postageapp/templates',
|
13
|
-
|
13
|
+
__dir__
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
17
|
def install
|
18
|
-
unless (
|
19
|
-
|
18
|
+
unless (PostageApp::Env.rails_with_encrypted_credentials?)
|
19
|
+
unless (options[:api_key])
|
20
|
+
puts 'Must pass --api-key with API key of your PostageApp.com project'
|
20
21
|
|
21
|
-
|
22
|
+
exit(-1)
|
23
|
+
end
|
24
|
+
|
25
|
+
template('initializer.rb', 'config/initializers/postageapp.rb')
|
22
26
|
end
|
23
|
-
|
24
|
-
template('initializer.rb', 'config/initializers/postageapp.rb')
|
27
|
+
|
25
28
|
copy_file('postageapp_tasks.rake', 'lib/tasks/postageapp_tasks.rake')
|
26
29
|
|
27
30
|
puts run('rake postageapp:test')
|
data/lib/postageapp.rb
CHANGED
@@ -2,66 +2,95 @@ require 'net/http'
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'digest'
|
4
4
|
require 'logger'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
7
|
require 'json'
|
7
8
|
require 'base64'
|
8
9
|
|
9
|
-
require 'postageapp/utils'
|
10
|
-
require 'postageapp/version'
|
11
|
-
require 'postageapp/configuration'
|
12
|
-
require 'postageapp/logger'
|
13
|
-
require 'postageapp/request'
|
14
|
-
require 'postageapp/failed_request'
|
15
|
-
require 'postageapp/response'
|
16
|
-
require 'postageapp/mail'
|
17
|
-
require 'postageapp/mail/delivery_method'
|
18
|
-
|
19
|
-
require 'postageapp/rails/railtie' if (defined?(Rails::Railtie))
|
20
|
-
|
21
10
|
module PostageApp
|
22
11
|
class Error < StandardError ; end
|
23
|
-
|
12
|
+
|
24
13
|
# Call this method to modify your configuration
|
25
14
|
# Example:
|
26
15
|
# PostageApp.configure do |config|
|
27
|
-
# config.api_key
|
28
|
-
#
|
16
|
+
# config.api_key = '1234567890abcdef'
|
17
|
+
#
|
18
|
+
# if Rails.env.staging?
|
19
|
+
# config.recipient_override = 'test@test.test'
|
20
|
+
# end
|
29
21
|
# end
|
30
|
-
#
|
22
|
+
#
|
31
23
|
# If you do not want/need to initialize the gem in this way, you can use the environment
|
32
24
|
# variable POSTAGEAPP_API_KEY to set up your key.
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
|
26
|
+
VERSION = File.read(File.expand_path('../VERSION', __dir__)).gsub(/\s/, '')
|
27
|
+
|
28
|
+
def self.version
|
29
|
+
VERSION
|
36
30
|
end
|
37
|
-
|
31
|
+
|
32
|
+
def self.configure(reset: false)
|
33
|
+
if (reset)
|
34
|
+
self.config_reset!
|
35
|
+
end
|
36
|
+
|
37
|
+
yield(self.config)
|
38
|
+
end
|
39
|
+
|
38
40
|
# Accessor for the PostageApp::Configuration object
|
39
41
|
# Example use:
|
40
42
|
# PostageApp.configuration.api_key = '1234567890abcdef'
|
41
|
-
def self.
|
42
|
-
@
|
43
|
+
def self.config
|
44
|
+
@config ||= Configuration.new
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.config_reset!
|
48
|
+
@config = nil
|
43
49
|
end
|
44
50
|
|
45
51
|
class << self
|
46
|
-
|
52
|
+
alias_method :configuration_reset!, :config_reset!
|
53
|
+
alias_method :configuration, :config
|
47
54
|
end
|
48
|
-
|
55
|
+
|
49
56
|
# Logger for the plugin
|
50
57
|
def self.logger
|
51
58
|
@logger ||= begin
|
52
|
-
|
53
|
-
if (
|
54
|
-
FileUtils.mkdir_p(File.join(File.expand_path(
|
55
|
-
File.join(
|
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")
|
56
63
|
else
|
57
|
-
|
64
|
+
$stdout
|
58
65
|
end
|
59
66
|
)
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
64
|
-
|
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'
|
65
94
|
|
66
95
|
if (defined?(::Mail))
|
67
96
|
PostageApp::Mail::Extensions.install!
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PostageApp::CLI
|
2
|
+
class UnknownCommand < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
def self.parse!(command_name, *args)
|
6
|
+
if (command = PostageApp::CLI::Command.defined[command_name.to_sym])
|
7
|
+
command.parse!(*args)
|
8
|
+
else
|
9
|
+
raise UnknownCommand, "The command #{command_name.inspect} is not known."
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative './cli/command'
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class PostageApp::CLI::Command
|
4
|
+
class APICallError < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class MissingArguments < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.defined
|
11
|
+
@defined ||= { }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.define(command_name = nil, &block)
|
15
|
+
command_name ||= $command_name
|
16
|
+
command = self.defined[command_name] = new(command_name)
|
17
|
+
|
18
|
+
command.instance_eval(&block) if (block_given?)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(command_name)
|
22
|
+
@command_name = command_name
|
23
|
+
@api_key_context = :project
|
24
|
+
@argument = { }
|
25
|
+
end
|
26
|
+
|
27
|
+
def api_key(context)
|
28
|
+
@api_key_context = context
|
29
|
+
end
|
30
|
+
|
31
|
+
def argument(name, optional: false, type: String, desc: nil, boolean: false)
|
32
|
+
@argument[name] = {
|
33
|
+
optional: optional,
|
34
|
+
type: String,
|
35
|
+
desc: desc,
|
36
|
+
boolean: boolean
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def perform(&block)
|
41
|
+
@perform = block
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse!(*args)
|
45
|
+
arguments = { }
|
46
|
+
|
47
|
+
op = OptionParser.new do |parser|
|
48
|
+
parser.banner = "Usage: postageapp #{@command_name} [options]"
|
49
|
+
|
50
|
+
@argument.each do |name, attributes|
|
51
|
+
if (attributes[:boolean])
|
52
|
+
parser.on("--#{name}", attributes[:desc]) do
|
53
|
+
arguments[name] = true
|
54
|
+
end
|
55
|
+
else
|
56
|
+
parser.on("--#{name} VALUE", "#{attributes[:desc]} (#{attributes[:optional] ? 'optional' : 'required'})") do |v|
|
57
|
+
arguments[name] = v
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
op.parse!(args)
|
64
|
+
|
65
|
+
missing = @argument.select do |name, attributes|
|
66
|
+
!attributes[:optional] && arguments[name].nil?
|
67
|
+
end.keys
|
68
|
+
|
69
|
+
if (missing.any?)
|
70
|
+
$stderr.puts("Error: missing options #{missing.join(', ')}")
|
71
|
+
|
72
|
+
puts op.help
|
73
|
+
|
74
|
+
raise MissingArguments
|
75
|
+
end
|
76
|
+
|
77
|
+
case (@api_key_context)
|
78
|
+
when :account
|
79
|
+
arguments['api_key'] = PostageApp.configuration.account_api_key
|
80
|
+
end
|
81
|
+
|
82
|
+
case (@perform&.arity)
|
83
|
+
when 1
|
84
|
+
return @perform.call(arguments)
|
85
|
+
when 0
|
86
|
+
return @perform.call
|
87
|
+
end
|
88
|
+
|
89
|
+
response = PostageApp::Request.new(@command_name, arguments).send
|
90
|
+
|
91
|
+
case (response.status)
|
92
|
+
when "ok"
|
93
|
+
puts JSON.pretty_generate(response.data)
|
94
|
+
else
|
95
|
+
$stderr.puts("Received error: #{response.status}")
|
96
|
+
|
97
|
+
if (response.message)
|
98
|
+
$stderr.puts(' ' + response.message)
|
99
|
+
end
|
100
|
+
|
101
|
+
raise APICallError
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
Dir.glob(File.expand_path('./command/*.rb', __dir__)) do |command|
|
107
|
+
$command_name = File.basename(command, '.rb').to_sym
|
108
|
+
|
109
|
+
require command
|
110
|
+
end
|