postageapp 1.3.1 → 1.4.0

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 -40
  4. data/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.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/exe/postageapp +37 -0
  12. data/lib/generators/postageapp/postageapp_generator.rb +9 -6
  13. data/lib/postageapp.rb +53 -35
  14. data/lib/postageapp/cli.rb +14 -0
  15. data/lib/postageapp/cli/command.rb +110 -0
  16. data/lib/postageapp/cli/command/config.rb +74 -0
  17. data/lib/postageapp/cli/command/create_mailbox.rb +21 -0
  18. data/lib/postageapp/cli/command/env.rb +58 -0
  19. data/lib/postageapp/cli/command/get_project_info.rb +3 -0
  20. data/lib/postageapp/configuration.rb +237 -74
  21. data/lib/postageapp/engine.rb +9 -0
  22. data/lib/postageapp/env.rb +9 -0
  23. data/lib/postageapp/mailer.rb +1 -11
  24. data/lib/postageapp/mailer/mailer_4.rb +30 -14
  25. data/lib/postageapp/rails/railtie.rb +1 -3
  26. data/lib/postageapp/request.rb +6 -1
  27. data/log/.gitignore +1 -0
  28. data/postageapp.gemspec +8 -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 +3 -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} +5 -3
  48. data/test/{failed_request_test.rb → unit/failed_request_test.rb} +6 -6
  49. data/test/{live_test.rb → unit/live_test.rb} +1 -36
  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} +15 -15
  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 +40 -46
  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.rb +0 -77
  64. data/test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb +0 -1
  65. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb +0 -1
  66. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb +0 -1
  67. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb +0 -1
  68. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb +0 -1
  69. data/test/mailer/action_mailer_2/notifier/with_simple_view.erb +0 -1
  70. data/test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb +0 -1
  71. data/test/mailer_2_test.rb +0 -95
  72. data/test/mailer_3_test.rb +0 -118
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: eee8e5a9e9b96751117b5069f54aa8ecb833fdf1
4
- data.tar.gz: 27f7144b8dddb20b7002e83020397b20c2f0bd26
2
+ SHA256:
3
+ metadata.gz: b142c061512b3ef0ff5d1d18d436de9796b772793e6ed10d1267d506c0577d54
4
+ data.tar.gz: 1f028542353d6cb55ca037f431a68ee1f2820833cc7bce8b5b5fd72f46345365
5
5
  SHA512:
6
- metadata.gz: b4595cceffe1fc5f6343757db1aef22fbe8529656bf7f30c5c3c7ed53042228d4174e5d26fd2d88bed85e8f7b63976e272faf0265fbb903183876f4d87e27aac
7
- data.tar.gz: a2491f2ca1da5d85d2a75c2ecf321190449ae1d9f2b6d4faca827c940910cbff06b7cc2f46714af205684f4bec11d7c04114eb016044208c7810822536f7db8c
6
+ metadata.gz: 615475381e51dfbdb59e6966381e9c09f95c76e2d625c3983c5fbe7955765f42e85ecd76e3e4a2249bd55638ab70a3bd5153e7715fcf6ed2b0607e108ead503e
7
+ data.tar.gz: 295a8585e182f43e92447188eed75af8f447083d7c0186076a2f425eed22f86a36d7788974095f49ab0a4807191c4d743113d6c25eaa5efe1b65f70cf1aefa28
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ /.bundle
2
+
1
3
  .DS_Store
2
4
  coverage
3
5
  rdoc
@@ -8,3 +10,7 @@ test/gemfiles/*.lock
8
10
  Gemfile.lock
9
11
  .ruby-version
10
12
  *.gem
13
+
14
+ .env
15
+
16
+ .vscode
data/.travis.yml CHANGED
@@ -3,46 +3,15 @@ before_install: "WITH_VERBOSE=1 script/with current bootstrap"
3
3
  install: "WITH_VERBOSE=1 script/with current bundle install"
4
4
  script: "WITH_VERBOSE=1 script/with current bundle exec rake test"
5
5
  rvm:
6
- - 1.9.3-p551
7
- - 2.0.0-p648
8
- - 2.1.10
9
- - 2.2.5
10
- - 2.3.1
11
- - 2.4.1
12
- - jruby-9.1.2.0
6
+ - 2.5.9
7
+ - 2.6.7
8
+ - 2.7.3
9
+ - 3.0.1
10
+ - jruby-9.1.17.0
11
+ - jruby-9.2.17.0
13
12
  gemfile:
14
13
  - test/gemfiles/Gemfile.ruby
15
- - test/gemfiles/Gemfile.rails-2.3.x
16
- - test/gemfiles/Gemfile.rails-3.0.x
17
- - test/gemfiles/Gemfile.rails-3.1.x
18
- - test/gemfiles/Gemfile.rails-3.2.x
19
- - test/gemfiles/Gemfile.rails-4.0.x
20
- - test/gemfiles/Gemfile.rails-4.1.x
21
- - test/gemfiles/Gemfile.rails-4.2.x
22
14
  - test/gemfiles/Gemfile.rails-5.0.x
23
- matrix:
24
- exclude:
25
- - rvm: 1.9.3-p551
26
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
27
- - rvm: 2.0.0-p648
28
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
29
- - rvm: 2.1.10
30
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
31
- - rvm: 2.2.5
32
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
33
- - rvm: 2.3.1
34
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
35
- - rvm: jruby-9.1.2.0
36
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
37
- - rvm: 1.9.3-p551
38
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
39
- - rvm: 1.9.3-p551
40
- gemfile: test/gemfiles/Gemfile.rails-4.1.x
41
- - rvm: 1.9.3-p551
42
- gemfile: test/gemfiles/Gemfile.rails-4.2.x
43
- - rvm: 1.9.3-p551
44
- gemfile: test/gemfiles/Gemfile.rails-5.0.x
45
- - rvm: 2.0.0-p648
46
- gemfile: test/gemfiles/Gemfile.rails-5.0.x
47
- - rvm: 2.1.10
48
- gemfile: test/gemfiles/Gemfile.rails-5.0.x
15
+ - test/gemfiles/Gemfile.rails-5.2.x
16
+ - test/gemfiles/Gemfile.rails-6.0.x
17
+ - test/gemfiles/Gemfile.rails-6.1.x
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2016 Scott Tadman, Oleg Khabarov, PostageApp
1
+ Copyright (c) 2011-2019 Scott Tadman, Oleg Khabarov, PostageApp Ltd.
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,13 +1,35 @@
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)
1
+ # [PostageApp](https://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 gem is used to integrate Ruby apps with [PostageApp](http://postageapp.com/)
3
+ This gem is used to integrate Ruby apps with [PostageApp](https://postageapp.com/)
4
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
+ via a simple [JSON-based API](https://dev.postageapp.com/api).
6
6
 
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
+ ### [API Documentation](https://dev.postageapp.com/api/)
8
8
 
9
9
  # Installation
10
10
 
11
+ ## Rails 5.2 and newer
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
+
21
+ For authentication, add your project's PostageApp credentials to the
22
+ Rails Encrypted Credentials:
23
+
24
+ rails credentials:edit
25
+
26
+ The format of this entry should be:
27
+
28
+ postageapp:
29
+ api_key: __PROJECT_API_KEY__
30
+
31
+ Where that will be picked up by the plugin when Rails starts.
32
+
11
33
  ## Rails 4.x and newer
12
34
 
13
35
  Add the `postageapp` gem to your Gemfile:
@@ -26,9 +48,13 @@ Then from the Rails project's root run:
26
48
 
27
49
  ## Sinatra / Rack / Others
28
50
 
29
- You'll need to install the gem first:
51
+ Add the `postageapp` gem to your Gemfile:
52
+
53
+ gem 'postageapp'
54
+
55
+ Then from the project's root run:
30
56
 
31
- $ sudo gem install postageapp
57
+ bundle install
32
58
 
33
59
  The configuration will need to be loaded before executing any API calls:
34
60
 
@@ -46,7 +72,7 @@ with the appropriate API key will also work.
46
72
  # Usage
47
73
 
48
74
  Here's an example of sending a message using the
49
- [`send_message`](http://help.postageapp.com/faqs/api/send_message) API call:
75
+ [`send_message`](https://dev.postageapp.com/api/send_message) API call:
50
76
 
51
77
  ```ruby
52
78
  request = PostageApp::Request.new(
@@ -63,7 +89,7 @@ request = PostageApp::Request.new(
63
89
  },
64
90
  attachments: {
65
91
  'document.pdf' => {
66
- content_type: application/pdf',
92
+ content_type: 'application/pdf',
67
93
  content: Base64.encode64(File.open('/path/to/document.pdf', 'rb').read)
68
94
  }
69
95
  }
@@ -121,7 +147,7 @@ require 'postageapp/mailer'
121
147
  There are custom methods that allow setting of `template` and `variables` parts
122
148
  of the API call. They are `postageapp_template` and `postageapp_variables`.
123
149
  Examples how they are used are below. For details what they do please see
124
- [documentation](http://help.postageapp.com/faqs)
150
+ [documentation](https://dev.postageapp.com/api/)
125
151
 
126
152
  Please note that `deliver` method will return `PostageApp::Response` object.
127
153
  This way you can immediately check the status of the delivery. For example:
@@ -213,11 +239,89 @@ For projects other than Rails you'll need to tell where the `project_root` is:
213
239
 
214
240
  ```ruby
215
241
  PostageApp.configure do |config|
216
- config.api_key = 'PROJECT_API_KEY'
242
+ config.api_key = 'PROJECT_API_KEY'
217
243
  config.project_root = "/path/to/your/project"
218
244
  end
219
245
  ```
220
246
 
221
- # Copyright
222
-
223
- (C) 2011-2017 Scott Tadman, Oleg Khabarov, [PostageApp](http://www.postageapp.com/)
247
+ # Configuration Details
248
+
249
+ Configuration can be done either via Ruby code directly, by environment
250
+ variables, or by a combination of both. Where both are supplied, the
251
+ Ruby setting will take precedence.
252
+
253
+ ## Configuration Arguments
254
+
255
+ These can all be set with `PostageApp.config`:
256
+
257
+ * `api_key`: Project API key to use (required for project API functions)
258
+ * `account_api_key`: Account API key to use (required for account API functions)
259
+ * `postback_secret`: Secret to use for validating ActionMailbox requests (optional)
260
+ * `project_root`: Project root for logging purposes (default: current working directory)
261
+ * `recipient_override`: Override sender on `send_message` calls (optional)
262
+ * `logger`: Logger instance to use (optional)
263
+ * `secure`: Enable verifying TLS connections (default: `true`)
264
+ * `verify_tls`: Enable TLS certificate verification (default: `true`)
265
+ * `verify_certificate`: Alias for `verify_tls`
266
+ * `host`: API host to contact (default: `api.postageapp.com`)
267
+ * `port`: API port to contact (default: `443`)
268
+ * `scheme`: HTTP scheme to use (default: `https`)
269
+ * `protocol`: Alias for `scheme`
270
+ * `proxy_username`: SOCKS5 proxy username (optional)
271
+ * `proxy_user`: Alias for `proxy_username`
272
+ * `proxy_password`: SOCKS5 proxy password (optional)
273
+ * `proxy_pass`: Alias for `proxy_password`
274
+ * `proxy_host`: SOCKS5 proxy host (optional)
275
+ * `proxy_port`: SOCKS5 proxy port (default: `1080`)
276
+ * `open_timeout`: Timeout in seconds when initiating requests (default: `5`)
277
+ * `http_open_timeout`: Alias for `open_timeout`
278
+ * `read_timeout`: Timeout in seconds when awaiting responses (default: `10`)
279
+ * `http_read_timeout`: Alias for `read_timeout`
280
+ * `retry_methods`: Which API calls to retry, comma and/or space separated (default: `send_message`)
281
+ * `requests_to_resend`: Alias for `retry_methods`
282
+ * `framework`: Framework used (default: `Ruby`)
283
+ * `environment`: Environment to use (default: `production`)
284
+
285
+ A typical configuration involves setting the project API key:
286
+
287
+ PostageApp.config do |config|
288
+ config.api_key = 'PROJECT_API_KEY'
289
+ end
290
+
291
+ Where additional settings can be applied as necessary.
292
+
293
+ ## Environment Variables
294
+
295
+ Most configuration parameters can be set via the environment:
296
+
297
+ * `POSTAGEAPP_API_KEY`: Project API key to use (required for project API functions)
298
+ * `POSTAGEAPP_ACCOUNT_API_KEY`: Account API key to use (required for account API functions)
299
+ * `POSTAGEAPP_POSTBACK_SECRET`: Secret to use for validating ActionMailbox requests (optional)
300
+ * `POSTAGEAPP_PROJECT_ROOT`: Project root for logging purposes (default: current working directory)
301
+ * `POSTAGEAPP_RECIPIENT_OVERRIDE`: Override sender on `send_message` calls (optional)
302
+ * `POSTAGEAPP_VERIFY_TLS`: (default: `true`)
303
+ * `POSTAGEAPP_VERIFY_CERTIFICATE`: Alias for `POSTAGEAPP_VERIFY_TLS`
304
+ * `POSTAGEAPP_HOST`: API host to contact (default: `api.postageapp.com`)
305
+ * `POSTAGEAPP_PORT`: API port to contact (default: `443`)
306
+ * `POSTAGEAPP_SCHEME`: HTTP scheme to use (default: `https`)
307
+ * `POSTAGEAPP_PROTOCOL`: Alias for `POSTAGEAPP_SCHEME`
308
+ * `POSTAGEAPP_PROXY_USERNAME`: SOCKS5 proxy username (optional)
309
+ * `POSTAGEAPP_PROXY_USER`: Alias for `POSTAGEAPP_PROXY_USERNAME`
310
+ * `POSTAGEAPP_PROXY_PASSWORD`: SOCKS5 proxy password (optional)
311
+ * `POSTAGEAPP_PROXY_PASS`: Alias for `POSTAGEAPP_PROXY_PASSWORD`
312
+ * `POSTAGEAPP_PROXY_HOST`: SOCKS5 proxy host (optional)
313
+ * `POSTAGEAPP_PROXY_PORT`: SOCKS5 proxy port (default: `1080`)
314
+ * `POSTAGEAPP_OPEN_TIMEOUT`: Timeout in seconds when initiating requests (default: `5`)
315
+ * `POSTAGEAPP_HTTP_OPEN_TIMEOUT`: Alias for `POSTAGEAPP_OPEN_TIMEOUT`
316
+ * `POSTAGEAPP_READ_TIMEOUT`: Timeout in seconds when awaiting responses (default: `10`)
317
+ * `POSTAGEAPP_HTTP_READ_TIMEOUT`: Alias for `POSTAGEAPP_READ_TIMEOUT`
318
+ * `POSTAGEAPP_RETRY_METHODS`: Which API calls to retry, comma and/or space separated (default: `send_message`)
319
+ * `POSTAGEAPP_REQUESTS_TO_RESEND`: Alias for `POSTAGEAPP_RETRY_METHODS`
320
+ * `POSTAGEAPP_FRAMEWORK`: Framework used (default: `Ruby`)
321
+ * `POSTAGEAPP_ENVIRONMENT`: Environment to use (default: `production`)
322
+
323
+ # Copyright and Licensing
324
+
325
+ (C) 2011-2019 Scott Tadman, Oleg Khabarov, [PostageApp](https://postageapp.com/)
326
+
327
+ This is released under the [MIT License](LICENSE.md).
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
- require 'bundler/setup'
1
+ # Avoid contaminating ENV with lots of BUNDLER_ variables
2
+ # require 'bundler/setup'
2
3
 
3
4
  require 'rake/testtask'
4
5
 
@@ -11,17 +12,27 @@ end
11
12
  namespace :travis do
12
13
  desc "Run tests across different environments, simulating Travis"
13
14
  task :test do
14
- require File.expand_path('test/travis_test', File.dirname(__FILE__))
15
+ require_relative './test/travis_test'
15
16
 
16
17
  TravisTest.run!
17
18
  end
18
19
 
19
20
  desc "Report on which versions of Ruby are installed"
20
21
  task :versions do
21
- require File.expand_path('test/travis_test', File.dirname(__FILE__))
22
+ require_relative './test/travis_test'
22
23
 
23
24
  TravisTest.validate_ruby_versions!
24
25
  end
25
26
  end
26
27
 
27
- task :default => :test
28
+ task default: :test
29
+
30
+ namespace :test do
31
+ task :rails do
32
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('./test/gemfiles/Gemfile.rails-6.1.x', __dir__)
33
+
34
+ require 'bundler/setup'
35
+
36
+ p Rails
37
+ end
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.4.0
@@ -0,0 +1,2 @@
1
+ module ActionMailbox::Ingresses::PostageApp
2
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ActionMailbox::Ingresses::PostageApp::InboundEmailsController < ActionMailbox::BaseController
4
+ before_action :hmac_authenticate
5
+
6
+ def create
7
+ ActionMailbox::InboundEmail.create_and_extract_message_id!(message_param)
8
+
9
+ head(:ok)
10
+
11
+ rescue JSON::ParserError => e
12
+ logger.error(e.message)
13
+
14
+ head(:unprocessable_entity)
15
+ end
16
+
17
+ private
18
+ def message_param
19
+ params.require(:inbound_email).require(:message)
20
+ end
21
+
22
+ def hmac_authenticate
23
+ return if (hmac_authenticated?)
24
+
25
+ head(:unauthorized)
26
+ end
27
+
28
+ def hmac_authenticated?
29
+ if (PostageApp.config.postback_secret.present?)
30
+ ActiveSupport::SecurityUtils.secure_compare(
31
+ request.headers["X-PostageApp-Signature"],
32
+ hmac_signature(message_param, PostageApp.config.postback_secret)
33
+ )
34
+ else
35
+ raise ArgumentError, <<~END.squish
36
+ Missing required PostageApp "postback secret" which can be set as
37
+ in the Rails Encypted Credentials, as POSTAGEAPP_API_POSTBACK_SECRET
38
+ in the environment, or via a config/initializer script using the
39
+ PostageApp.config method.
40
+ END
41
+ end
42
+ end
43
+
44
+ private
45
+ def hmac_signature(*content)
46
+ Base64.strict_encode64(
47
+ OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, *content)
48
+ )
49
+ end
50
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ PostageApp::Engine.routes.draw do
2
+ scope "/rails/action_mailbox", module: "action_mailbox/ingresses" do
3
+ post "/postageapp/inbound_emails" => "postage_app/inbound_emails#create",
4
+ as: :rails_postageapp_inbound_emails
5
+ end
6
+ end
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)
@@ -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
- File.dirname(__FILE__)
13
+ __dir__
14
14
  )
15
15
  end
16
16
 
17
17
  def install
18
- unless (options[:api_key])
19
- puts 'Must pass --api-key with API key of your PostageApp.com project'
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
- exit(-1)
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
@@ -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!