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
@@ -1,12 +1,12 @@
1
- require_relative './helper'
1
+ require_relative '../helper'
2
2
 
3
3
  class ResponseTest < MiniTest::Test
4
4
  def test_initialization
5
5
  object = stub(
6
- :body => {
6
+ body: {
7
7
  'response' => {
8
- 'uid' => 'md5_hash_uid',
9
- 'status' => 'ok',
8
+ 'uid' => 'md5_hash_uid',
9
+ 'status' => 'ok',
10
10
  'message' => 'api reply message'
11
11
  },
12
12
  'data' => {
@@ -0,0 +1 @@
1
+ *
data/tmp/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *
metadata CHANGED
@@ -1,31 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postageapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Tadman
8
8
  - Oleg Khabarov
9
- - The Working Group Inc.
10
- autorequire:
9
+ - PostageApp Ltd.
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-14 00:00:00.000000000 Z
13
+ date: 2021-08-23 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: json
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - "~>"
20
- - !ruby/object:Gem::Version
21
- version: '1.8'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - "~>"
27
- - !ruby/object:Gem::Version
28
- version: '1.8'
29
15
  - !ruby/object:Gem::Dependency
30
16
  name: mail
31
17
  requirement: !ruby/object:Gem::Requirement
@@ -51,18 +37,31 @@ files:
51
37
  - ".gitignore"
52
38
  - ".travis.yml"
53
39
  - Gemfile
54
- - LICENSE
40
+ - LICENSE.md
55
41
  - README.md
56
42
  - Rakefile
43
+ - VERSION
44
+ - app/ingresses/action_mailbox/ingresses/postage_app.rb
45
+ - app/ingresses/action_mailbox/ingresses/postage_app/inbound_emails_controller.rb
46
+ - config/routes.rb
57
47
  - doc/RAILS2.md
58
48
  - doc/RAILS3.md
49
+ - exe/postageapp
59
50
  - generators/postageapp/postageapp_generator.rb
60
51
  - generators/postageapp/templates/initializer.rb
61
52
  - generators/postageapp/templates/postageapp_tasks.rake
62
53
  - lib/generators/postageapp/postageapp_generator.rb
63
54
  - lib/postageapp.rb
55
+ - lib/postageapp/cli.rb
56
+ - lib/postageapp/cli/command.rb
57
+ - lib/postageapp/cli/command/config.rb
58
+ - lib/postageapp/cli/command/create_mailbox.rb
59
+ - lib/postageapp/cli/command/env.rb
60
+ - lib/postageapp/cli/command/get_project_info.rb
64
61
  - lib/postageapp/configuration.rb
65
62
  - lib/postageapp/diagnostics.rb
63
+ - lib/postageapp/engine.rb
64
+ - lib/postageapp/env.rb
66
65
  - lib/postageapp/failed_request.rb
67
66
  - lib/postageapp/http.rb
68
67
  - lib/postageapp/logger.rb
@@ -71,20 +70,16 @@ files:
71
70
  - lib/postageapp/mail/delivery_method.rb
72
71
  - lib/postageapp/mail/extensions.rb
73
72
  - lib/postageapp/mailer.rb
74
- - lib/postageapp/mailer/mailer_2.rb
75
- - lib/postageapp/mailer/mailer_3.rb
76
73
  - lib/postageapp/mailer/mailer_4.rb
77
74
  - lib/postageapp/rails/rails.rb
78
75
  - lib/postageapp/rails/railtie.rb
79
76
  - lib/postageapp/request.rb
80
77
  - lib/postageapp/response.rb
81
78
  - lib/postageapp/utils.rb
82
- - lib/postageapp/version.rb
79
+ - log/.gitignore
83
80
  - postageapp.gemspec
84
81
  - rails/init.rb
85
82
  - script/with
86
- - test/configuration_test.rb
87
- - test/failed_request_test.rb
88
83
  - test/gemfiles/Gemfile.rails-2.3.x
89
84
  - test/gemfiles/Gemfile.rails-3.0.x
90
85
  - test/gemfiles/Gemfile.rails-3.1.x
@@ -93,18 +88,12 @@ files:
93
88
  - test/gemfiles/Gemfile.rails-4.1.x
94
89
  - test/gemfiles/Gemfile.rails-4.2.x
95
90
  - test/gemfiles/Gemfile.rails-5.0.x
91
+ - test/gemfiles/Gemfile.rails-5.2.x
92
+ - test/gemfiles/Gemfile.rails-6.0.x
93
+ - test/gemfiles/Gemfile.rails-6.1.x
96
94
  - test/gemfiles/Gemfile.ruby
97
95
  - test/helper.rb
98
- - test/live_test.rb
99
- - test/mail_delivery_method_test.rb
100
- - test/mailer/action_mailer_2/notifier.rb
101
- - test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb
102
- - test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb
103
- - test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb
104
- - test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb
105
- - test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb
106
- - test/mailer/action_mailer_2/notifier/with_simple_view.erb
107
- - test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb
96
+ - test/log/.gitignore
108
97
  - test/mailer/action_mailer_3/layouts/notifier.html.erb
109
98
  - test/mailer/action_mailer_3/notifier.rb
110
99
  - test/mailer/action_mailer_3/notifier/with_custom_postage_variables.html.erb
@@ -115,21 +104,26 @@ files:
115
104
  - test/mailer/action_mailer_3/notifier/with_old_api.text.erb
116
105
  - test/mailer/action_mailer_3/notifier/with_simple_view.erb
117
106
  - test/mailer/action_mailer_3/notifier/with_text_only_view.text.erb
118
- - test/mailer_2_test.rb
119
- - test/mailer_3_test.rb
120
- - test/mailer_4_test.rb
121
- - test/mailer_helper_methods_test.rb
122
- - test/postageapp_test.rb
123
- - test/rails_initialization_test.rb
124
- - test/request_test.rb
125
- - test/response_test.rb
107
+ - test/tmp/.gitignore
126
108
  - test/travis_test.rb
109
+ - test/unit/configuration_test.rb
110
+ - test/unit/failed_request_test.rb
111
+ - test/unit/live_test.rb
112
+ - test/unit/mail_delivery_method_test.rb
113
+ - test/unit/mailer_4_test.rb
114
+ - test/unit/mailer_helper_methods_test.rb
115
+ - test/unit/postageapp_test.rb
116
+ - test/unit/rails_initialization_test.rb
117
+ - test/unit/request_test.rb
118
+ - test/unit/response_test.rb
119
+ - test/unit/tmp/.gitignore
127
120
  - test/with_environment.rb
128
- homepage: http://github.com/postageapp/postageapp-ruby
121
+ - tmp/.gitignore
122
+ homepage: https://github.com/postageapp/postageapp-ruby
129
123
  licenses:
130
124
  - MIT
131
125
  metadata: {}
132
- post_install_message:
126
+ post_install_message:
133
127
  rdoc_options: []
134
128
  require_paths:
135
129
  - lib
@@ -137,16 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
131
  requirements:
138
132
  - - ">="
139
133
  - !ruby/object:Gem::Version
140
- version: 1.9.3
134
+ version: 2.5.0
141
135
  required_rubygems_version: !ruby/object:Gem::Requirement
142
136
  requirements:
143
137
  - - ">="
144
138
  - !ruby/object:Gem::Version
145
139
  version: '0'
146
140
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.5.1
149
- signing_key:
141
+ rubygems_version: 3.2.15
142
+ signing_key:
150
143
  specification_version: 4
151
144
  summary: Client library for PostageApp Email API
152
145
  test_files: []
@@ -1,140 +0,0 @@
1
- # Postage::Mailer allows you to use/re-use existing mailers set up using
2
- # ActionMailer. The only catch is to change inheritance from ActionMailer::Base
3
- # to PostageApp::Mailer. Also don't forget to require 'postageapp/mailer'
4
- #
5
- # Here's an example of a valid PostageApp::Mailer class
6
- #
7
- # require 'postageapp/mailer'
8
- #
9
- # class Notifier < PostageApp::Mailer
10
- # def signup_notification(recipient)
11
- # recipients recipient.email_address
12
- # from 'system@example.com'
13
- # subject 'New Account Information'
14
- # end
15
- # end
16
- #
17
- # Postage::Mailer introduces a few mailer methods specific to Postage:
18
- #
19
- # * template - template name that is defined in your PostageApp project
20
- # * variables - extra variables you want to send along with the message
21
- #
22
- # Sending email
23
- #
24
- # Notifier.deliver_signup_notification(user) # attempts to deliver to PostageApp (depending on env)
25
- # request = Notifier.create_signup_notification(user) # creates PostageApp::Request object
26
- #
27
- class PostageApp::Mailer < ActionMailer::Base
28
- # Using :test as a delivery method if set somewhere else
29
- unless (self.delivery_method == :test)
30
- self.delivery_method = :postage
31
- end
32
-
33
- adv_attr_accessor :postageapp_uid
34
- adv_attr_accessor :postageapp_api_key
35
- adv_attr_accessor :postageapp_template
36
- adv_attr_accessor :postageapp_variables
37
-
38
- def perform_delivery_postage(mail)
39
- mail.send
40
- end
41
-
42
- def deliver!(mail = @mail)
43
- unless (mail)
44
- raise 'PostageApp::Request object not present, cannot deliver'
45
- end
46
-
47
- if (perform_deliveries)
48
- __send__("perform_delivery_#{delivery_method}", mail)
49
- end
50
- end
51
-
52
- # Creating a Postage::Request object unlike TMail one in ActionMailer::Base
53
- def create_mail
54
- params = { }
55
-
56
- unless (self.recipients.blank?)
57
- params['recipients'] = self.recipients
58
- end
59
-
60
- params['headers'] = { }
61
-
62
- unless (self.subject.blank?)
63
- params['headers']['subject'] = self.subject
64
- end
65
-
66
- unless (self.subject.blank?)
67
- params['headers']['from'] = self.from
68
- end
69
-
70
- unless (self.headers.blank?)
71
- params['headers'].merge!(self.headers)
72
- end
73
-
74
- params['content'] = { }
75
- params['attachments'] = { }
76
-
77
- if (@parts.empty?)
78
- unless (self.body.blank?)
79
- params['content'][self.content_type] = self.body
80
- end
81
- else
82
- self.parts.each do |part|
83
- case (part.content_disposition)
84
- when 'inline'
85
- if (part.content_type.blank? && String === part.body)
86
- part.content_type = 'text/plain'
87
- end
88
-
89
- params['content'][part.content_type] = part.body
90
- when 'attachment'
91
- params['attachments'][part.filename] = {
92
- 'content_type' => part.content_type,
93
- 'content' => Base64.encode64(part.body)
94
- }
95
- end
96
- end
97
- end
98
-
99
- unless (self.postageapp_template.blank?)
100
- params['template'] = self.postageapp_template
101
- end
102
-
103
- unless (self.postageapp_variables.blank?)
104
- params['variables'] = self.postageapp_variables
105
- end
106
-
107
- if (params['headers'].blank?)
108
- params.delete('headers')
109
- end
110
-
111
- if (params['content'].blank?)
112
- params.delete('content')
113
- end
114
-
115
- if (params['attachments'].blank?)
116
- params.delete('attachments')
117
- end
118
-
119
- @mail = PostageApp::Request.new('send_message', params)
120
-
121
- unless (self.postageapp_uid.blank?)
122
- @mail.uid = self.postageapp_uid
123
- end
124
-
125
- unless (self.postageapp_api_key.blank?)
126
- @mail.api_key = self.postageapp_api_key
127
- end
128
-
129
- @mail
130
- end
131
-
132
- # Not insisting rendering a view if it's not there. PostageApp gem can send blank content
133
- # provided that the template is defined.
134
- def render(opts)
135
- super(opts)
136
-
137
- rescue ActionView::MissingTemplate
138
- # do nothing
139
- end
140
- end
@@ -1,190 +0,0 @@
1
- # Postage::Mailer allows you to use/re-use existing mailers set up using
2
- # ActionMailer. The only catch is to change inheritance from ActionMailer::Base
3
- # to PostageApp::Mailer. Also don't forget to require 'postageapp/mailer'
4
- #
5
- # Here's an example of a valid PostageApp::Mailer class
6
- #
7
- # require 'postageapp/mailer'
8
- #
9
- # class Notifier < PostageApp::Mailer
10
- # def signup_notification(recipient)
11
- # mail(
12
- # :to => recipient.email,
13
- # :from => 'sender@test.test',
14
- # :subject => 'Test Message'
15
- # )
16
- # end
17
- # end
18
- #
19
- # Postage::Mailer introduces a few mailer methods specific to Postage:
20
- #
21
- # * postageapp_template - template name that is defined in your PostageApp project
22
- # * postageapp_variables - extra variables you want to send along with the message
23
- #
24
- # Sending email
25
- #
26
- # request = Notifier.signup_notification(user) # creates PostageApp::Request object
27
- # response = request.deliver # attempts to deliver the message and creates a PostageApp::Response
28
-
29
- class PostageApp::Mailer < ActionMailer::Base
30
- # Wrapper for creating attachments
31
- # Attachments sent to PostageApp are in the following format:
32
- # 'filename.ext' => {
33
- # 'content_type' => 'content/type',
34
- # 'content' => 'base64_encoded_content'
35
- # }
36
-
37
- class Attachments < Hash
38
- def initialize(message)
39
- @_message = message
40
-
41
- message.arguments['attachments'] ||= { }
42
- end
43
-
44
- def []=(filename, attachment)
45
- default_content_type = MIME::Types.type_for(filename).first.content_type rescue ''
46
-
47
- case (attachment)
48
- when Hash
49
- content_type = attachment[:content_type] || default_content_type
50
- content = Base64.encode64(attachment[:body])
51
- else
52
- content_type = default_content_type
53
- content = Base64.encode64(attachment)
54
- end
55
-
56
- @_message.arguments['attachments'][filename] = {
57
- 'content_type' => content_type,
58
- 'content' => content
59
- }
60
- end
61
- end
62
-
63
- # Instead of initializing Mail object, we prepare PostageApp::Request
64
- def initialize(method_name = nil, *args)
65
- super()
66
-
67
- @_message = PostageApp::Request.new(:send_message)
68
-
69
- if method_name
70
- process(method_name, *args)
71
- end
72
- end
73
-
74
- # Possible to define custom uid. Should be sufficiently unique
75
- def postageapp_uid(value = nil)
76
- value ? @_message.uid = value : @_message.uid
77
- end
78
-
79
- def postageapp_api_key(value = nil)
80
- value ? @_message.api_key = value : @_message.api_key
81
- end
82
-
83
- # In API call we can specify PostageApp template that will be used
84
- # to generate content of the message
85
- def postageapp_template(value = nil)
86
- if (value)
87
- @_message.arguments['template'] = value
88
- else
89
- @_message.arguments['template']
90
- end
91
- end
92
-
93
- # Hash of variables that will be used to inject into the content
94
- def postageapp_variables(value = nil)
95
- if (value)
96
- @_message.arguments['variables'] = value
97
- else
98
- @_message.arguments['variables']
99
- end
100
- end
101
-
102
- def attachments
103
- @_attachments ||= Attachments.new(@_message)
104
- end
105
-
106
- # Override for headers assignment
107
- def headers(args = nil)
108
- @_message.headers(args)
109
- end
110
-
111
- # Overriding method that prepares Mail object. This time we'll be
112
- # contructing PostageApp::Request payload.
113
- def mail(headers = { }, &block)
114
- # Guard flag to prevent both the old and the new API from firing
115
- # Should be removed when old API is removed
116
- @mail_was_called = true
117
- m = @_message
118
-
119
- # At the beginning, do not consider class default for parts order neither content_type
120
- content_type = headers[:content_type]
121
- parts_order = headers[:parts_order]
122
-
123
- # Call all the procs (if any)
124
- default_values = self.class.default.merge(self.class.default) do |k,v|
125
- if (v.respond_to?(:call))
126
- v.bind(self).call
127
- else
128
- v
129
- end
130
- end
131
-
132
- # Handle defaults
133
- headers = headers.reverse_merge(default_values)
134
-
135
- # Set configure delivery behavior
136
- wrap_delivery_behavior!(headers.delete(:delivery_method))
137
-
138
- # Assigning recipients
139
- m.arguments['recipients'] = headers.delete(:to)
140
-
141
- # Assign all headers except parts_order, content_type and body
142
- assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
143
- m.headers.merge!(assignable)
144
-
145
- # Render the templates and blocks
146
- responses, explicit_order = collect_responses_and_parts_order(headers, &block)
147
- create_parts_from_responses(m, responses)
148
-
149
- m
150
- end
151
-
152
- protected
153
- def create_parts_from_responses(m, responses) #:nodoc:
154
- content = m.arguments['content'] ||= { }
155
-
156
- responses.each do |part|
157
- content[part[:content_type]] = part[:body]
158
- end
159
- end
160
- end
161
-
162
- # A set of methods that are useful when request needs to behave as Mail
163
- class PostageApp::Request
164
- attr_accessor :delivery_handler
165
- attr_accessor :perform_deliveries
166
- attr_accessor :raise_delivery_errors
167
-
168
- def inform_interceptors
169
- Mail.inform_interceptors(self)
170
- end
171
-
172
- # Either doing an actual send, or passing it along to Mail::TestMailer
173
- # Probably not the best way as we're skipping way too many intermediate methods
174
- def deliver
175
- inform_interceptors
176
-
177
- if (perform_deliveries)
178
- if (@delivery_method == Mail::TestMailer)
179
- @delivery_method.deliveries << self
180
- else
181
- self.send
182
- end
183
- end
184
- end
185
-
186
- # Not 100% on this, but I need to assign this so I can properly handle deliver method
187
- def delivery_method(method = nil, settings = { })
188
- @delivery_method = method
189
- end
190
- end