postmark_mailer 0.1.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e6bd29eeef550d9a64ed7b5bc53b31f8a9fe8cf
4
+ data.tar.gz: b9d5f9e35700b6e82daf2b9982aaba7ffdd0913a
5
+ SHA512:
6
+ metadata.gz: 0b753e46aa48f657b2da94c3b7f58775ff5fb3fa6871f83307680ed68257ffd959843f7e6707675eaf5ffe4f08e6c69213a9b2255483799ca341496ed3121560
7
+ data.tar.gz: a89ac4dd4ad93aa1ab786da61f49c674af1b8c4a9a9d01116b33240cb4b48603fd8b14a8f867a40adca7211b63dfa7dc140bfc8b83a518d88f04e0df36dc7d0e
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.3] - 2018-09-27
8
+ ### Added
9
+ - A crude facsimile of `#action_name` to mimic the method of the same name found in ActionMailer.
10
+ - Documentation in README for `#prevent_delivery?` usage.
11
+
12
+ ## [0.1.2] - 2018-04-04
13
+ ### Added
14
+ - Support for Rails 5.
15
+
16
+ ## [0.1.1] - 2017-12-01
17
+ ### Added
18
+ - Basic configuration options.
19
+
20
+ ### Removed
21
+ - Copypasta from initial commit.
22
+
23
+ ## [0.1.0] - 2017-12-01
24
+ ### Added
25
+ - Rough outline of initial code extracted from Science Exchange.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in postmark_mailer.gemspec
6
+ gemspec
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ postmark_mailer (0.1.0)
5
+ activejob (~> 4.2)
6
+ postmark
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activejob (4.2.10)
12
+ activesupport (= 4.2.10)
13
+ globalid (>= 0.3.0)
14
+ activesupport (4.2.10)
15
+ i18n (~> 0.7)
16
+ minitest (~> 5.1)
17
+ thread_safe (~> 0.3, >= 0.3.4)
18
+ tzinfo (~> 1.1)
19
+ concurrent-ruby (1.0.5)
20
+ diff-lcs (1.3)
21
+ globalid (0.4.1)
22
+ activesupport (>= 4.2.0)
23
+ i18n (0.9.1)
24
+ concurrent-ruby (~> 1.0)
25
+ json (2.1.0)
26
+ minitest (5.10.3)
27
+ postmark (1.10.0)
28
+ json
29
+ rake
30
+ rake (10.4.2)
31
+ rspec (3.6.0)
32
+ rspec-core (~> 3.6.0)
33
+ rspec-expectations (~> 3.6.0)
34
+ rspec-mocks (~> 3.6.0)
35
+ rspec-core (3.6.0)
36
+ rspec-support (~> 3.6.0)
37
+ rspec-expectations (3.6.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.6.0)
40
+ rspec-mocks (3.6.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.6.0)
43
+ rspec-support (3.6.0)
44
+ thread_safe (0.3.6)
45
+ tzinfo (1.2.4)
46
+ thread_safe (~> 0.1)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 1.16)
53
+ postmark_mailer!
54
+ rake (~> 10.0)
55
+ rspec (~> 3.0)
56
+
57
+ BUNDLED WITH
58
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Science Exchange, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,141 @@
1
+ # PostmarkMailer
2
+
3
+ This gem is designed to provide a (nearly) drop-in replacement for Ruby on Rails' `ActionMailer` for those wishing to deliver emails using [Postmark's Templates API](https://postmarkapp.com/why/templates). Its interface mimics that of `ActionMailer` so switching existing mailers should require minimal effort, and usage should be familiar to most Ruby on Rails developers.
4
+
5
+ _**NOTE:** This gem only provides a means of delivering transactional emails from a Ruby on Rails application with a Postmark template, and does **not** provide any functionality for managing templates. Such functionality is already provided by Postmark's API and their Ruby client._
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'postmark_mailer', github: 'scienceexchange/postmark_mailer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install postmark_mailer
22
+
23
+ ## Usage
24
+
25
+ To start sending emails with Postmark's templates, you will need to set up some minimal configuration, and then make some changes to the mailer classes themselves.
26
+
27
+ ### Configuration
28
+
29
+ In `app/initializers/postmark_mailer.rb`, add the following configuration block:
30
+
31
+ ```ruby
32
+ PostmarkMailer.configure do |config|
33
+ config.api_key = YOUR_POSTMARK_API_KEY # required
34
+ config.default_delivery_queue = :mailers # defaults to :default
35
+ end
36
+ ```
37
+
38
+ ### Defining Mailers
39
+
40
+ To illustrate the usage of `PostmarkMailer`, let's take a look at a typical Rails mailer:
41
+
42
+ ```ruby
43
+ class MyCoolMailer < ActionMailer::Base
44
+ def welcome(user)
45
+ @user = user
46
+
47
+ mail(
48
+ to: @user.email,
49
+ subject: 'Welcome to Our Product!'
50
+ )
51
+ end
52
+ end
53
+ ```
54
+
55
+ The same mailer, using this gem would look like this:
56
+
57
+ ```ruby
58
+ class MyCoolMailer < PostmarkMailer::Base
59
+ def welcome(user)
60
+ mail(
61
+ to: user.email,
62
+ template_id: 123_456,
63
+ template_model: {
64
+ first_name: user.first_name
65
+ }
66
+ )
67
+ end
68
+ end
69
+ ```
70
+
71
+ Note the important changes:
72
+
73
+ * The mailer now inherits from `PostmarkMailer::Base` instead of `ActionMailer::Base`.
74
+ * You add `template_id` to your options hash. _(This is required.)_
75
+ * You add `template_model` to your options hash, which is an optional hash of whatever data you'd like to render in your template. _(This is optional–in the unlikely event your template does not render any specific data, you can safely omit this option.)_
76
+
77
+ The options you pass into the `#mail` method are ultimately passed on to the `#deliver_with_template` method provided by the Postmark API Ruby client, and so you'll want to [refer to their documentation for a list of all the availabale options](https://postmarkapp.com/developer/api/templates-api#email-with-template).
78
+
79
+ Because Postmark handles the templating and rendering, you no longer need the views for this mailer, so in this example, you could safely remove `app/views/mailers/my_cool_mailer/welcome.html.erb`.
80
+
81
+ ### Delivering Mailers
82
+
83
+ Just as you would with a standard mailer, simply call:
84
+
85
+ ```ruby
86
+ MyCoolMailer.welcome(user).deliver_later
87
+ ```
88
+
89
+ or, less optimally:
90
+
91
+ ```ruby
92
+ MyCoolMailer.welcome(user).deliver_now
93
+ ```
94
+
95
+ ### Preventing Delivery
96
+
97
+ In some mailers, you may wish to prevent delivery based on some business logic. For instance, if you offer email preferences to your users, you may want to check their preferences and prevent delivery if they've disabled email notifications.
98
+
99
+ To add mailer-wide logic, simply define a `prevent_delivery?` method in your mailer:
100
+
101
+ ```ruby
102
+ class MyCoolMailer < PostmarkMailer::Base
103
+ def welcome(user)
104
+ @user = user
105
+ mail(
106
+ to: @user.email,
107
+ template_id: 123_456,
108
+ template_model: {
109
+ first_name: @user.first_name
110
+ }
111
+ )
112
+ end
113
+
114
+ private
115
+
116
+ def prevent_delivery?
117
+ # Substitute the line below with your own logic
118
+ @user.all_emails_disabled?
119
+ end
120
+ end
121
+ ```
122
+
123
+ ## Development
124
+
125
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
126
+
127
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
128
+
129
+ ## Contributing
130
+
131
+ This gem is in it's infancy, so functionality is extremely limited at this point. Bug reports and pull requests are welcome on GitHub at https://github.com/scienceexchange/postmark_mailer.
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+
137
+ ## About Science Exchange
138
+
139
+ PostmarkMailer is maintained by [Science Exchange](https://www.scienceexchange.com), the leading platform for outsourcing scientific research and development. Science Exchange is not affiliated with Postmark or Wildbit, LLC, and usage of Postmark is subject to their Terms of Service.
140
+
141
+ If you're interested helping improve the pace of scientific research, you should know that [we're hiring!](https://jobs.lever.co/scienceexchange/e277508e-1bda-4ed2-b3f3-ed78d3345402)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "postmark_mailer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,20 @@
1
+ require 'postmark_mailer/version'
2
+ require 'postmark_mailer/configuration'
3
+ require 'postmark_mailer/base'
4
+ require 'postmark_mailer/delivery_job'
5
+ require 'postmark_mailer/message_delivery'
6
+ require 'postmark_mailer/null_delivery'
7
+
8
+ module PostmarkMailer
9
+ class << self
10
+ attr_writer :configuration
11
+ end
12
+
13
+ def self.configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ module PostmarkMailer
2
+ class Base
3
+ attr_accessor :action_name
4
+
5
+ class << self
6
+ private
7
+
8
+ def respond_to_missing?(method, *)
9
+ new.respond_to?(method) || super
10
+ end
11
+
12
+ def method_missing(method, *args)
13
+ if respond_to_missing?(method)
14
+ new(method.to_s).public_send(method, *args)
15
+ else
16
+ super
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def initialize(method_name = nil)
24
+ @action_name = method_name
25
+ end
26
+
27
+ def mail(options)
28
+ if prevent_delivery?
29
+ NullDelivery.new(options)
30
+ else
31
+ MessageDelivery.new(options)
32
+ end
33
+ end
34
+
35
+ def prevent_delivery?; end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ module PostmarkMailer
2
+ class Configuration
3
+ attr_accessor :api_key, :default_delivery_queue
4
+
5
+ def initialize
6
+ @api_key = nil
7
+ @default_delivery_queue = :default
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require "active_job"
2
+
3
+ module PostmarkMailer
4
+ class DeliveryJob < ActiveJob::Base
5
+ queue_as { PostmarkMailer.configuration.default_delivery_queue }
6
+
7
+ def perform(options)
8
+ MessageDelivery.new(options).deliver_now
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'postmark'
2
+
3
+ module PostmarkMailer
4
+ class MessageDelivery
5
+ attr_accessor :client, :options
6
+
7
+ def initialize(opts)
8
+ @client = Postmark::ApiClient.new(PostmarkMailer.configuration.api_key)
9
+ @options = opts
10
+ end
11
+
12
+ def deliver_now
13
+ client.deliver_with_template(options)
14
+ end
15
+
16
+ def deliver_later
17
+ DeliveryJob.perform_later(options)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require 'postmark_mailer'
2
+ # Null object for MessageDelivery. Follows the same interface but performs no
3
+ # deliveries.
4
+ module PostmarkMailer
5
+ class NullDelivery < MessageDelivery
6
+ # Does nothing
7
+ # @return [nil]
8
+ def deliver_now; end
9
+
10
+ # Does nothing
11
+ # @return [nil]
12
+ def deliver_later; end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module PostmarkMailer
2
+ VERSION = '0.1.3'.freeze
3
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'postmark_mailer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'postmark_mailer'
8
+ spec.version = PostmarkMailer::VERSION
9
+ spec.authors = ['John Ellis']
10
+ spec.email = ['john@scienceexchange.com']
11
+
12
+ spec.summary = 'An ActionMailer replacement for those wishing to send emails using Postmark Templates.'
13
+ spec.description = "Designed to mimic ActionMailer's familiar interface, this gem offers a way to send transactional emails that are rendered by Postmark's Templates feature and delivered via the Postmark API."
14
+ spec.homepage = 'https://github.com/scienceexchange/postmark_mailer'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.16'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+
37
+ spec.add_dependency 'activejob', '>= 4.2'
38
+ spec.add_dependency 'postmark'
39
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postmark_mailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - John Ellis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activejob
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: postmark
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Designed to mimic ActionMailer's familiar interface, this gem offers
84
+ a way to send transactional emails that are rendered by Postmark's Templates feature
85
+ and delivered via the Postmark API.
86
+ email:
87
+ - john@scienceexchange.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CHANGELOG.md
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/postmark_mailer.rb
104
+ - lib/postmark_mailer/base.rb
105
+ - lib/postmark_mailer/configuration.rb
106
+ - lib/postmark_mailer/delivery_job.rb
107
+ - lib/postmark_mailer/message_delivery.rb
108
+ - lib/postmark_mailer/null_delivery.rb
109
+ - lib/postmark_mailer/version.rb
110
+ - postmark_mailer.gemspec
111
+ homepage: https://github.com/scienceexchange/postmark_mailer
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.5.2
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: An ActionMailer replacement for those wishing to send emails using Postmark
135
+ Templates.
136
+ test_files: []