lipwig 0.0.1 → 0.1.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 +4 -4
- data/Gemfile +3 -0
- data/README.markdown +24 -4
- data/exe/lipwig +0 -0
- data/lib/lipwig.rb +1 -2
- data/lib/lipwig/cli.rb +1 -1
- data/lib/lipwig/senders.rb +20 -0
- data/lib/lipwig/senders/abstract.rb +27 -0
- data/lib/lipwig/{sender.rb → senders/postmark.rb} +2 -18
- data/lib/lipwig/senders/smtp.rb +44 -0
- data/lib/lipwig/senders/smtp_connection.rb +39 -0
- data/lipwig.gemspec +1 -2
- metadata +7 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7edc14564c6463b4e40b18ecc6833aadbfc1e3c
|
4
|
+
data.tar.gz: 2f4b269b1116a5ca9fe849d2ae182cd391724d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d2fcf69d63fd149ff11650a011bc16491f95aaef75fb110d02d630e93399b266851b33a83d3c075341212e55e28c8d11a37dbe043376a5a6c3e80bfe08879f
|
7
|
+
data.tar.gz: 049cdea1040d2484d90c0bf7de82426d63ade663bafeec0d6d89c3d676b34218548aefffa75410f403e369a1f6358ec13f53ab9af998d265637c469c90e7a6c9
|
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -8,12 +8,18 @@ I have a habit of inviting friends to various events and shows, but I don't like
|
|
8
8
|
|
9
9
|
So, I'd been writing Ruby scripts to send neatly formatted emails, but Lipwig wraps up that logic and makes it a bit more re-usable.
|
10
10
|
|
11
|
-
It currently uses Postmark's API, because that's what I use. I'm open to patches that allow for SMTP settings or other provider APIs as well.
|
12
|
-
|
13
11
|
## Installation
|
14
12
|
|
15
13
|
$ gem install lipwig
|
16
14
|
|
15
|
+
Also, you'll need either the `postmark` gem or the `mail` gem, depending on whether you want to send via Postmark's API or by SMTP.
|
16
|
+
|
17
|
+
$ gem install postmark
|
18
|
+
# or
|
19
|
+
$ gem install mail
|
20
|
+
|
21
|
+
Lipwig is known to work with Postmark >= 1.9 and Mail >= 2.6.4.
|
22
|
+
|
17
23
|
## Usage
|
18
24
|
|
19
25
|
Similar to Jekyll, Lipwig expects email files to be a mixture of YAML and Markdown. Here's an example:
|
@@ -32,9 +38,23 @@ Similar to Jekyll, Lipwig expects email files to be a mixture of YAML and Markdo
|
|
32
38
|
|
33
39
|
As you can see, the recipients value expects an array, and it can contain arrays to send a single email to more than one person. Everything that follows after the `---` is Markdown, and will be rendered as HTML in the resulting email.
|
34
40
|
|
41
|
+
### Sending Configuration
|
42
|
+
|
43
|
+
If you're using Postmark's API, then all you need to set is the `LIPWIG_POSTMARK_API_KEY` environment variable.
|
44
|
+
|
45
|
+
For SMTP, there's a handful of required environment variables:
|
46
|
+
|
47
|
+
* LIPWIG_SMTP_ADDRESS
|
48
|
+
* LIPWIG_SMTP_PORT
|
49
|
+
* LIPWIG_SMTP_USERNAME
|
50
|
+
* LIPWIG_SMTP_PASSWORD
|
51
|
+
* LIPWIG_SMTP_DOMAIN
|
52
|
+
|
53
|
+
If you're using SMTP and sending many emails, it's recommended you use the persistent connection approach if your provider supports it, by setting `LIPWIG_SMTP_CONNECTION=true`.
|
54
|
+
|
35
55
|
### Options
|
36
56
|
|
37
|
-
|
57
|
+
You can use `LIPWIG_FROM` for your default _From_ setting - though anything specified in your email file will override this. `LIPWIG_RECIPIENTS`, on the otherhand, will override your email file's recipients - useful for a quick test before you fill up everyone's inboxes.
|
38
58
|
|
39
59
|
### Commands
|
40
60
|
|
@@ -52,7 +72,7 @@ And you can send the emails:
|
|
52
72
|
|
53
73
|
## Contributing
|
54
74
|
|
55
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pat/lipwig. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
56
76
|
|
57
77
|
## Licence
|
58
78
|
|
data/exe/lipwig
CHANGED
File without changes
|
data/lib/lipwig.rb
CHANGED
data/lib/lipwig/cli.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Lipwig::Senders
|
2
|
+
UnknownSenderError = Class.new(StandardError)
|
3
|
+
|
4
|
+
def self.call(email)
|
5
|
+
if ENV['LIPWIG_POSTMARK_API_KEY']
|
6
|
+
require 'lipwig/senders/postmark'
|
7
|
+
Lipwig::Senders::Postmark.call email
|
8
|
+
elsif ENV['LIPWIG_SMTP_CONNECTION'] == 'true'
|
9
|
+
require 'lipwig/senders/smtp_connection'
|
10
|
+
Lipwig::Senders::SMTPConnection.call email
|
11
|
+
elsif ENV['LIPWIG_SMTP_ADDRESS']
|
12
|
+
require 'lipwig/senders/smtp'
|
13
|
+
Lipwig::Senders::SMTP.call email
|
14
|
+
else
|
15
|
+
raise UnknownSenderError, "Sending protocol could not be determined"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'lipwig/senders/abstract'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Lipwig::Senders::Abstract
|
2
|
+
def self.call(email)
|
3
|
+
new(email).call
|
4
|
+
end
|
5
|
+
|
6
|
+
def initialize(email)
|
7
|
+
@email = email
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
raise NoMethodError, "Sender must implement this call method"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :email
|
17
|
+
|
18
|
+
def from
|
19
|
+
email.from || ENV['LIPWIG_FROM']
|
20
|
+
end
|
21
|
+
|
22
|
+
def recipients
|
23
|
+
return [ENV['LIPWIG_RECIPIENTS']] if ENV['LIPWIG_RECIPIENTS']
|
24
|
+
|
25
|
+
email.recipients
|
26
|
+
end
|
27
|
+
end
|
@@ -1,12 +1,6 @@
|
|
1
|
-
|
2
|
-
def self.call(email)
|
3
|
-
new(email).call
|
4
|
-
end
|
5
|
-
|
6
|
-
def initialize(email)
|
7
|
-
@email = email
|
8
|
-
end
|
1
|
+
require 'postmark'
|
9
2
|
|
3
|
+
class Lipwig::Senders::Postmark < Lipwig::Senders::Abstract
|
10
4
|
def call
|
11
5
|
client.deliver_in_batches(messages).each do |response|
|
12
6
|
puts "Delivery To: #{Array(response[:to]).join(', ')}"
|
@@ -23,10 +17,6 @@ class Lipwig::Sender
|
|
23
17
|
@client ||= Postmark::ApiClient.new ENV['LIPWIG_POSTMARK_API_KEY']
|
24
18
|
end
|
25
19
|
|
26
|
-
def from
|
27
|
-
email.from || ENV['LIPWIG_FROM']
|
28
|
-
end
|
29
|
-
|
30
20
|
def messages
|
31
21
|
recipients.collect do |recipient|
|
32
22
|
{
|
@@ -37,10 +27,4 @@ class Lipwig::Sender
|
|
37
27
|
}
|
38
28
|
end
|
39
29
|
end
|
40
|
-
|
41
|
-
def recipients
|
42
|
-
return [ENV['LIPWIG_RECIPIENTS']] if ENV['LIPWIG_RECIPIENTS']
|
43
|
-
|
44
|
-
email.recipients
|
45
|
-
end
|
46
30
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'mail'
|
2
|
+
|
3
|
+
class Lipwig::Senders::SMTP < Lipwig::Senders::Abstract
|
4
|
+
def call
|
5
|
+
recipients.each do |recipient|
|
6
|
+
mail = Mail.new
|
7
|
+
mail.delivery_method delivery_method, delivery_method_options
|
8
|
+
|
9
|
+
mail.content_type = 'text/html; charset=UTF-8'
|
10
|
+
mail.from = from
|
11
|
+
mail.to = recipient
|
12
|
+
mail.subject = email.subject
|
13
|
+
mail.body = email.body
|
14
|
+
|
15
|
+
begin
|
16
|
+
puts "Delivery To: #{Array(recipient).join(', ')}"
|
17
|
+
mail.deliver!
|
18
|
+
puts "Delivery Status: OK", ""
|
19
|
+
rescue => error
|
20
|
+
puts "Delivery Status: Failed (#{error.message})", ""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :email
|
28
|
+
|
29
|
+
def delivery_method
|
30
|
+
:smtp
|
31
|
+
end
|
32
|
+
|
33
|
+
def delivery_method_options
|
34
|
+
@delivery_method_options ||= {
|
35
|
+
:address => ENV['LIPWIG_SMTP_ADDRESS'],
|
36
|
+
:port => ENV['LIPWIG_SMTP_PORT'],
|
37
|
+
:authentication => :plain,
|
38
|
+
:user_name => ENV['LIPWIG_SMTP_USERNAME'],
|
39
|
+
:password => ENV['LIPWIG_SMTP_PASSWORD'],
|
40
|
+
:domain => ENV['LIPWIG_SMTP_DOMAIN'],
|
41
|
+
:enable_starttls_auto => true
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'mail'
|
2
|
+
require 'lipwig/senders/smtp'
|
3
|
+
|
4
|
+
class Lipwig::Senders::SMTPConnection < Lipwig::Senders::SMTP
|
5
|
+
def call
|
6
|
+
connection.start(
|
7
|
+
ENV['LIPWIG_SMTP_DOMAIN'],
|
8
|
+
ENV['LIPWIG_SMTP_USERNAME'],
|
9
|
+
ENV['LIPWIG_SMTP_PASSWORD'],
|
10
|
+
:plain
|
11
|
+
)
|
12
|
+
|
13
|
+
super
|
14
|
+
|
15
|
+
connection.finish
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :email
|
21
|
+
|
22
|
+
def connection
|
23
|
+
@connection ||= begin
|
24
|
+
smtp = Net::SMTP.new(
|
25
|
+
ENV['LIPWIG_SMTP_ADDRESS'], ENV['LIPWIG_SMTP_PORT']
|
26
|
+
)
|
27
|
+
smtp.enable_starttls_auto
|
28
|
+
smtp
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delivery_method
|
33
|
+
:smtp_connection
|
34
|
+
end
|
35
|
+
|
36
|
+
def delivery_method_options
|
37
|
+
{:connection => connection}
|
38
|
+
end
|
39
|
+
end
|
data/lipwig.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "lipwig"
|
5
|
-
spec.version = '0.0
|
5
|
+
spec.version = '0.1.0'
|
6
6
|
spec.authors = ["Pat Allan"]
|
7
7
|
spec.email = ["pat@freelancing-gods.com"]
|
8
8
|
|
@@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.executables = spec.files.grep(%r{^exe/}) { |file| File.basename(file) }
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_runtime_dependency "postmark", "~> 1.9"
|
20
19
|
spec.add_runtime_dependency "redcarpet", "~> 3.3"
|
21
20
|
|
22
21
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lipwig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: postmark
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.9'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.9'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: redcarpet
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +60,11 @@ files:
|
|
74
60
|
- lib/lipwig/email.rb
|
75
61
|
- lib/lipwig/parser.rb
|
76
62
|
- lib/lipwig/preview.rb
|
77
|
-
- lib/lipwig/
|
63
|
+
- lib/lipwig/senders.rb
|
64
|
+
- lib/lipwig/senders/abstract.rb
|
65
|
+
- lib/lipwig/senders/postmark.rb
|
66
|
+
- lib/lipwig/senders/smtp.rb
|
67
|
+
- lib/lipwig/senders/smtp_connection.rb
|
78
68
|
- lipwig.gemspec
|
79
69
|
homepage: https://github.com/pat/lipwig
|
80
70
|
licenses: []
|