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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60476fb310740f79d87ecfbfd2c0771ccf0dc14b
4
- data.tar.gz: c40710bce00094743adf3d4736d7ebc87213d51e
3
+ metadata.gz: b7edc14564c6463b4e40b18ecc6833aadbfc1e3c
4
+ data.tar.gz: 2f4b269b1116a5ca9fe849d2ae182cd391724d4a
5
5
  SHA512:
6
- metadata.gz: 7e4b52545bbc618fd20f9b115ec5845d74148f591f5fed2b4b884df314c673890596809c2d954c79e9bb94ba49c07e679b44a230cca6225fee2be6b594d94eb2
7
- data.tar.gz: 8f62d0675fabed1fead520851049a68ca28eabf8e51ee4dc0ae4e11cc223039c0e9ba820f95b3d98760de920941d8d21b5fdc9c5406d440672d08102f544d0d7
6
+ metadata.gz: 93d2fcf69d63fd149ff11650a011bc16491f95aaef75fb110d02d630e93399b266851b33a83d3c075341212e55e28c8d11a37dbe043376a5a6c3e80bfe08879f
7
+ data.tar.gz: 049cdea1040d2484d90c0bf7de82426d63ade663bafeec0d6d89c3d676b34218548aefffa75410f403e369a1f6358ec13f53ab9af998d265637c469c90e7a6c9
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem "mail", "~> 2.6"
6
+ gem "postmark", "~> 1.9"
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
- The environment variable `LIPWIG_POSTMARK_API_KEY` is expected to be set with your API key. 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.
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/[USERNAME]/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.
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
@@ -1,4 +1,3 @@
1
- require 'postmark'
2
1
  require 'redcarpet'
3
2
  require 'yaml'
4
3
 
@@ -10,4 +9,4 @@ require 'lipwig/cli'
10
9
  require 'lipwig/email'
11
10
  require 'lipwig/parser'
12
11
  require 'lipwig/preview'
13
- require 'lipwig/sender'
12
+ require 'lipwig/senders'
data/lib/lipwig/cli.rb CHANGED
@@ -10,7 +10,7 @@ class Lipwig::CLI
10
10
  def call
11
11
  case command
12
12
  when 'send'
13
- Lipwig::Sender.call email
13
+ Lipwig::Senders.call email
14
14
  when 'preview'
15
15
  Lipwig::Preview.call email
16
16
  when 'clear'
@@ -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
- class Lipwig::Sender
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.1'
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.1
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: 2016-11-19 00:00:00.000000000 Z
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/sender.rb
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: []