sendwithus_ruby_action_mailer 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b5ed4fd380e163f80dcfa9072963cb10ffa2c0e
4
- data.tar.gz: decd4114b665b03bd3d9c6aa360201e11ea16845
3
+ metadata.gz: f252eb70f4fcd2d85986136d8c9499d3d351d653
4
+ data.tar.gz: 3c49269296138883a73eab6bbbaad233f3e52d2d
5
5
  SHA512:
6
- metadata.gz: 17749e64d882871acb621e98708531d0983feaa815485c1b0d80e79b33286586304668cbdb5d38fe3e495b6a3f8f1b97c060e0b7f016a120eab76cecd8ecdcdf
7
- data.tar.gz: b9619fcb4f91c8fb1249427c7bb5a1c92121849e0004e8f67a28a6661814bc9680679b4eed1fa20c65340221e30c6466d7fd8b6c36267f911da5c1756e32aa0c
6
+ metadata.gz: 4a07c488dfd89616b7d2c311448330a19eefec96b0799eb96429949f0c5bb7ce0c620963be4cba0d05e865c9d7ee107e9bf3e2e547bfe5dd105bef6105029f79
7
+ data.tar.gz: 6913518eb2496016f241d0869bfcbc21ad3b846381704bee0e0eedc51958844c240d96b38638c0cf3c68d44e0178674d00c69fe85254e2421835e3e42a48377d
@@ -0,0 +1,7 @@
1
+ ### Client version
2
+
3
+ ### Expected behaviour
4
+
5
+ ### Actual behaviour
6
+
7
+ ### Steps to reproduce
@@ -0,0 +1,28 @@
1
+ <!--- Provide a general summary of your changes in the Title above -->
2
+
3
+ ## Description
4
+ <!--- Describe your changes in detail if necessary -->
5
+
6
+ ## Motivation and Context
7
+ <!--- Why is this change required? What problem does it solve? -->
8
+ <!--- If it fixes an open issue, please link to the issue here. -->
9
+
10
+ ## How Has This Been Tested?
11
+ <!--- Please describe in detail how you tested your changes. -->
12
+ <!--- Include details of your testing environment, and the tests you ran to -->
13
+ <!--- see how your change affects other areas of the code, etc. -->
14
+
15
+ ## Types of changes
16
+ <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
17
+ - [ ] Bug fix (non-breaking change which fixes an issue)
18
+ - [ ] New feature (non-breaking change which adds functionality)
19
+ - [ ] Breaking change (fix or feature that would cause existing functionality to change)
20
+
21
+ ## Checklist:
22
+ <!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
23
+ <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
24
+ - [ ] My code follows the code style of this project.
25
+ - [ ] My change requires a change to the documentation.
26
+ - [ ] I have updated the documentation accordingly.
27
+ - [ ] I have added tests to cover my changes.
28
+ - [ ] All new and existing tests passed.
data/README.md CHANGED
@@ -47,7 +47,7 @@ class Notifier < SendWithUsMailer::Base
47
47
 
48
48
  def welcome(recipient)
49
49
  assign(:account, recipient)
50
-
50
+ #=> in sendwithus email template {{ account }}
51
51
  assign(:captain_name, recipient.name)
52
52
  #=> in sendwithus email template {{ captain_name }}
53
53
  assign :team, {team_name: recipient.team_name, captain: recipient.name}
@@ -93,10 +93,21 @@ mail.deliver # sends the email
93
93
  You never instantiate your mailer class. Rather, you just call the method you defined
94
94
  on the class itself.
95
95
 
96
+ ### Sending mail asynchronously with ActiveJob
97
+
98
+ `````Ruby
99
+ Notifier.welcome(nick).deliver_later # sends the email asynchronously
100
+
101
+ mail = Notifier.welcome(david) # => a SendWithUsMailer::MailParams object
102
+ mail.deliver_later # sends the email asynchronously
103
+ `````
104
+
105
+ You never instantiate your mailer class. Rather, you just call the method you defined
106
+ on the class itself.
96
107
 
97
108
  ### Conditional Delivery
98
109
 
99
- If you have to check for a condition for senting the email (useful when it's a scheduled sending with Sidekiq for instance), you can simply not call the mail method and the email won't be sent out.
110
+ If you have to check for a condition for sending the email (useful when it's a scheduled sending with Sidekiq for instance), you can simply not call the mail method and the email won't be sent out.
100
111
 
101
112
  `````Ruby
102
113
  class Notifier < SendWithUsMailer::Base
@@ -1,3 +1,4 @@
1
1
  require "sendwithus_ruby_action_mailer/version"
2
2
  require "sendwithus_ruby_action_mailer/base"
3
3
  require "sendwithus_ruby_action_mailer/mail_params"
4
+ require "sendwithus_ruby_action_mailer/jobs/mail_job"
@@ -0,0 +1,15 @@
1
+ require "active_job"
2
+
3
+ module SendWithUsMailer
4
+ module Jobs
5
+ # The <tt>SendWithUsMailer::Jobs::MailJob</tt> class is used when you
6
+ # want to send transactional emails outside of the request-response cycle.
7
+ class MailJob < ActiveJob::Base
8
+ queue_as :mailers
9
+
10
+ def perform(email_id, to, options)
11
+ SendWithUs::Api.new.send_email(email_id, to, options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -79,5 +79,30 @@ module SendWithUsMailer
79
79
  tags: @tags
80
80
  ) if @email_id.present?
81
81
  end
82
+
83
+ alias_method :deliver_now, :deliver
84
+
85
+ # Invoke <tt>SendWithUs::Api</tt> to deliver the message later via ActiveJob.
86
+ # The <tt>SendWithUs</tt> module is implemented in the +send_with_us+ gem.
87
+ #
88
+ # IMPORTANT NOTE: <tt>SendWithUs</tt> must be configured prior to calling this method.
89
+ # In particular, the +api_key+ must be set (following the guidelines in the
90
+ # +send_with_us+ documentation).
91
+ def deliver_later
92
+ Jobs::MailJob.perform_later(
93
+ @email_id,
94
+ @to,
95
+ data: @email_data,
96
+ from: @from,
97
+ cc: @cc,
98
+ bcc: @bcc,
99
+ esp_account: @esp_account,
100
+ version_name: @version_name,
101
+ locale: @locale,
102
+ files: @files,
103
+ headers: @headers,
104
+ tags: @tags
105
+ ) if @email_id.present?
106
+ end
82
107
  end
83
108
  end
@@ -1,3 +1,3 @@
1
1
  module SendWithUsMailer
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -21,7 +21,9 @@ Gem::Specification.new do |gem|
21
21
  gem.require_paths = ["lib"]
22
22
 
23
23
  gem.add_runtime_dependency 'send_with_us', '>= 1.9.0'
24
- gem.add_development_dependency 'actionpack'
24
+ gem.add_runtime_dependency 'actionpack'
25
+ gem.add_runtime_dependency 'activejob'
26
+
25
27
  gem.add_development_dependency 'rake'
26
28
  gem.add_development_dependency 'minitest-colorize'
27
29
  gem.add_development_dependency 'mocha'
@@ -1,6 +1,8 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  describe SendWithUsMailer::MailParams do
4
+ include ActiveJob::TestHelper
5
+
4
6
  subject { SendWithUsMailer::MailParams.new }
5
7
 
6
8
  describe "initialization" do
@@ -63,9 +65,45 @@ describe SendWithUsMailer::MailParams do
63
65
  subject.deliver
64
66
  end
65
67
 
66
- it "doesnt call the send_with_us gem if mail method is not called" do
68
+ it "doesn't call the send_with_us gem if mail method is not called" do
67
69
  SendWithUs::Api.any_instance.expects(:send_with).never
68
70
  subject.deliver
69
71
  end
70
72
  end
73
+
74
+ describe "#deliver_now" do
75
+ it "method exists" do
76
+ subject.respond_to?(:deliver_now).must_equal true
77
+ end
78
+
79
+ it "calls the send_with_us gem" do
80
+ subject.merge!(email_id: 'x')
81
+ SendWithUs::Api.any_instance.expects(:send_email)
82
+ subject.deliver_now
83
+ end
84
+
85
+ it "doesn't call the send_with_us gem if mail method is not called" do
86
+ SendWithUs::Api.any_instance.expects(:send_with).never
87
+ subject.deliver_now
88
+ end
89
+ end
90
+
91
+ describe "#deliver_later" do
92
+ it "method exists" do
93
+ subject.respond_to?(:deliver_later).must_equal true
94
+ end
95
+
96
+ it "enqueues the job" do
97
+ subject.merge!(email_id: 'x')
98
+ assert_enqueued_with(job: SendWithUsMailer::Jobs::MailJob) do
99
+ subject.deliver_later
100
+ end
101
+ end
102
+
103
+ it "doesn't call the send_with_us gem if no email_id" do
104
+ assert_no_enqueued_jobs do
105
+ subject.deliver_later
106
+ end
107
+ end
108
+ end
71
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendwithus_ruby_action_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Rempel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: send_with_us
@@ -31,7 +31,21 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activejob
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
@@ -90,6 +104,8 @@ executables: []
90
104
  extensions: []
91
105
  extra_rdoc_files: []
92
106
  files:
107
+ - ".github/ISSUE_TEMPLATE"
108
+ - ".github/PULL_REQUEST_TEMPLATE"
93
109
  - ".gitignore"
94
110
  - Gemfile
95
111
  - LICENSE.txt
@@ -97,6 +113,7 @@ files:
97
113
  - Rakefile
98
114
  - lib/sendwithus_ruby_action_mailer.rb
99
115
  - lib/sendwithus_ruby_action_mailer/base.rb
116
+ - lib/sendwithus_ruby_action_mailer/jobs/mail_job.rb
100
117
  - lib/sendwithus_ruby_action_mailer/mail_params.rb
101
118
  - lib/sendwithus_ruby_action_mailer/version.rb
102
119
  - sendwithus_ruby_action_mailer.gemspec