lipwig 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60476fb310740f79d87ecfbfd2c0771ccf0dc14b
4
+ data.tar.gz: c40710bce00094743adf3d4736d7ebc87213d51e
5
+ SHA512:
6
+ metadata.gz: 7e4b52545bbc618fd20f9b115ec5845d74148f591f5fed2b4b884df314c673890596809c2d954c79e9bb94ba49c07e679b44a230cca6225fee2be6b594d94eb2
7
+ data.tar.gz: 8f62d0675fabed1fead520851049a68ca28eabf8e51ee4dc0ae4e11cc223039c0e9ba820f95b3d98760de920941d8d21b5fdc9c5406d440672d08102f544d0d7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm: 2.3.2
4
+ before_install: gem install bundler -v 1.13.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at pat@freelancing-gods.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,60 @@
1
+ # Lipwig
2
+
3
+ Lipwig is a small tool that for sending bulk emails in a slightly more friendly vibe than BCC'ing everyone.
4
+
5
+ ## Why?
6
+
7
+ I have a habit of inviting friends to various events and shows, but I don't like putting everyone's email address in the _To_ field (it's not nice to disclose so many peoples' email addresses). I also don't like putting everyone in the _BCC_ field (it's nice to keep couples' email addresses together, and make the email feel at least a little more personal).
8
+
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
+
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
+ ## Installation
14
+
15
+ $ gem install lipwig
16
+
17
+ ## Usage
18
+
19
+ Similar to Jekyll, Lipwig expects email files to be a mixture of YAML and Markdown. Here's an example:
20
+
21
+ from: "Pat Allan <pat@obfuscated.email.com>"
22
+ subject: "Party time"
23
+ recipients:
24
+ - "rey@obfuscated.email.com",
25
+ - - "finn@obfuscated.email.com"
26
+ - "poe@obfuscated.email.com"
27
+ - "Kylo Ren <ben@obfuscated.email.com>"
28
+ ---
29
+ Hi everyone,
30
+
31
+ It's time for a **party**. How about next week? Shall I cook pancakes?
32
+
33
+ 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
+
35
+ ### Options
36
+
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.
38
+
39
+ ### Commands
40
+
41
+ You can review the HTML of the email in your browser (currently built with macOS in mind):
42
+
43
+ $ lipwig preview my-email.markdown
44
+
45
+ You can clear out the generated preview files:
46
+
47
+ $ lipwig clear
48
+
49
+ And you can send the emails:
50
+
51
+ $ lipwig send my-email.markdown
52
+
53
+ ## Contributing
54
+
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.
56
+
57
+ ## Licence
58
+
59
+ Copyright (c) 2016, Lipwig is developed and maintained by Pat Allan, and is
60
+ released under the open MIT Licence.
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lipwig"
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
data/bin/setup ADDED
@@ -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
data/exe/lipwig ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'lipwig'
5
+
6
+ Lipwig::CLI.call ARGV[0], ARGV[1]
data/lib/lipwig/cli.rb ADDED
@@ -0,0 +1,44 @@
1
+ class Lipwig::CLI
2
+ def self.call(command = '', source = '')
3
+ new(command, source).call
4
+ end
5
+
6
+ def initialize(command, source)
7
+ @command, @source = command, source
8
+ end
9
+
10
+ def call
11
+ case command
12
+ when 'send'
13
+ Lipwig::Sender.call email
14
+ when 'preview'
15
+ Lipwig::Preview.call email
16
+ when 'clear'
17
+ Dir['lipwig-preview-*.html'].each { |file| File.delete file }
18
+ else
19
+ puts "Unknown command #{command}." unless command == 'help'
20
+ puts <<-MESSAGE
21
+ Commands are:
22
+ send: Send the email to the specified recipients.
23
+ preview: Open the HTML for the email in your browser.
24
+ clear: Remove temporary preview files.
25
+
26
+ Example Usage:
27
+ $ lipwig send email.markdown
28
+ $ lipwig preview email.markdown
29
+
30
+ Sending emails requires LIPWIG_POSTMARK_API_KEY to be set. Recipients are
31
+ whatever is set in the email's frontmatter, but can be overridden by
32
+ LIPWIG_RECIPIENTS.
33
+ MESSAGE
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :command, :source
40
+
41
+ def email
42
+ @email ||= Lipwig::Parser.call File.read(source)
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ class Lipwig::Email
2
+ attr_accessor :from, :subject, :body, :recipients
3
+ end
@@ -0,0 +1,49 @@
1
+ class Lipwig::Parser
2
+ MARKER = /---\s*/
3
+
4
+ def self.call(input)
5
+ new(input).call
6
+ end
7
+
8
+ def initialize(input)
9
+ @input = input
10
+ end
11
+
12
+ def call
13
+ email = Lipwig::Email.new
14
+ email.from = frontmatter['from']
15
+ email.subject = frontmatter['subject']
16
+ email.recipients = frontmatter['recipients']
17
+ email.body = html
18
+ email
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :input
24
+
25
+ def frontmatter
26
+ @frontmatter ||= YAML.load input.split(MARKER).first.strip
27
+ end
28
+
29
+ def html
30
+ <<-HTML
31
+ <html>
32
+ <head>
33
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
34
+ </head>
35
+ <body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
36
+ #{ renderer.render(markdown).strip }
37
+ </body>
38
+ </html>
39
+ HTML
40
+ end
41
+
42
+ def markdown
43
+ @markdown ||= input.split(MARKER).last.strip
44
+ end
45
+
46
+ def renderer
47
+ @renderer ||= Redcarpet::Markdown.new Redcarpet::Render::HTML.new
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ class Lipwig::Preview
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
+ File.write filename, email.body
12
+
13
+ `open #{filename}`
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :email
19
+
20
+ def filename
21
+ @filename ||= "#{Dir.pwd}/lipwig-preview-#{Time.now.to_i}.html"
22
+ end
23
+ end
@@ -0,0 +1,46 @@
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
9
+
10
+ def call
11
+ client.deliver_in_batches(messages).each do |response|
12
+ puts "Delivery To: #{Array(response[:to]).join(', ')}"
13
+ puts "Delivery Status: #{response[:message]}"
14
+ puts ""
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :email
21
+
22
+ def client
23
+ @client ||= Postmark::ApiClient.new ENV['LIPWIG_POSTMARK_API_KEY']
24
+ end
25
+
26
+ def from
27
+ email.from || ENV['LIPWIG_FROM']
28
+ end
29
+
30
+ def messages
31
+ recipients.collect do |recipient|
32
+ {
33
+ :from => from,
34
+ :to => recipient,
35
+ :subject => email.subject,
36
+ :html_body => email.body
37
+ }
38
+ end
39
+ end
40
+
41
+ def recipients
42
+ return [ENV['LIPWIG_RECIPIENTS']] if ENV['LIPWIG_RECIPIENTS']
43
+
44
+ email.recipients
45
+ end
46
+ end
data/lib/lipwig.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'postmark'
2
+ require 'redcarpet'
3
+ require 'yaml'
4
+
5
+ module Lipwig
6
+ #
7
+ end
8
+
9
+ require 'lipwig/cli'
10
+ require 'lipwig/email'
11
+ require 'lipwig/parser'
12
+ require 'lipwig/preview'
13
+ require 'lipwig/sender'
data/lipwig.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "lipwig"
5
+ spec.version = '0.0.1'
6
+ spec.authors = ["Pat Allan"]
7
+ spec.email = ["pat@freelancing-gods.com"]
8
+
9
+ spec.summary = %q{Write group emails in Markdown, send via Postmark.}
10
+ spec.homepage = "https://github.com/pat/lipwig"
11
+
12
+ spec.files = `git ls-files -z`.split("\x0").reject do |file|
13
+ file.match(%r{^(test|spec|features)/})
14
+ end
15
+ spec.bindir = "exe"
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |file| File.basename(file) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency "postmark", "~> 1.9"
20
+ spec.add_runtime_dependency "redcarpet", "~> 3.3"
21
+
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lipwig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pat Allan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-19 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: redcarpet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
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
+ description:
56
+ email:
57
+ - pat@freelancing-gods.com
58
+ executables:
59
+ - lipwig
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - README.markdown
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/lipwig
72
+ - lib/lipwig.rb
73
+ - lib/lipwig/cli.rb
74
+ - lib/lipwig/email.rb
75
+ - lib/lipwig/parser.rb
76
+ - lib/lipwig/preview.rb
77
+ - lib/lipwig/sender.rb
78
+ - lipwig.gemspec
79
+ homepage: https://github.com/pat/lipwig
80
+ licenses: []
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Write group emails in Markdown, send via Postmark.
102
+ test_files: []