pushpop-sendgrid 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +21 -0
- data/README.md +79 -0
- data/Rakefile +16 -0
- data/lib/pushpop-sendgrid.rb +108 -0
- data/lib/pushpop-sendgrid/version.rb +5 -0
- data/pushpop-sendgrid.gemspec +22 -0
- data/spec/pushpop-sendgrid_spec.rb +82 -0
- data/spec/spec.html.erb +6 -0
- data/spec/spec_helper.rb +11 -0
- metadata +91 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.1.1)
|
5
|
+
i18n (~> 0.6, >= 0.6.9)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.1)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.3.6)
|
11
|
+
builder (3.2.2)
|
12
|
+
clockwork (0.7.5)
|
13
|
+
activesupport
|
14
|
+
tzinfo
|
15
|
+
diff-lcs (1.2.5)
|
16
|
+
i18n (0.6.9)
|
17
|
+
json (1.8.1)
|
18
|
+
jwt (1.0.0)
|
19
|
+
keen (0.8.2)
|
20
|
+
addressable (~> 2.3.5)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
mail (2.6.1)
|
23
|
+
mime-types (>= 1.16, < 3)
|
24
|
+
mime-types (2.3)
|
25
|
+
minitest (5.3.4)
|
26
|
+
multi_json (1.10.1)
|
27
|
+
pushpop (0.1.0)
|
28
|
+
clockwork
|
29
|
+
keen
|
30
|
+
rake (10.3.2)
|
31
|
+
rspec (3.0.0)
|
32
|
+
rspec-core (~> 3.0.0)
|
33
|
+
rspec-expectations (~> 3.0.0)
|
34
|
+
rspec-mocks (~> 3.0.0)
|
35
|
+
rspec-core (3.0.1)
|
36
|
+
rspec-support (~> 3.0.0)
|
37
|
+
rspec-expectations (3.0.1)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.0.0)
|
40
|
+
rspec-mocks (3.0.1)
|
41
|
+
rspec-support (~> 3.0.0)
|
42
|
+
rspec-support (3.0.0)
|
43
|
+
thread_safe (0.3.4)
|
44
|
+
twilio-ruby (3.11.5)
|
45
|
+
builder (>= 2.1.2)
|
46
|
+
jwt (>= 0.1.2)
|
47
|
+
multi_json (>= 1.3.0)
|
48
|
+
tzinfo (1.2.1)
|
49
|
+
thread_safe (~> 0.1)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
mail
|
56
|
+
pushpop
|
57
|
+
rake
|
58
|
+
rspec
|
59
|
+
twilio-ruby
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Author Josh Dzielak
|
2
|
+
Copyright (c) 2014 Keen Labs
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
## pushpop-sendgrid
|
2
|
+
|
3
|
+
Sendgrid plugin for [Pushpop](https://github.com/keenlabs/pushpop).
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
|
7
|
+
Add `pushpop-sendgrid` to your Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'pushpop-sendgrid'
|
11
|
+
```
|
12
|
+
|
13
|
+
or install it as a gem:
|
14
|
+
|
15
|
+
``` shell
|
16
|
+
$ gem install pushpop-sendgrid
|
17
|
+
```
|
18
|
+
|
19
|
+
### Usage
|
20
|
+
|
21
|
+
The `sendgrid` plugin gives you a DSL to specify typical email parameters.
|
22
|
+
|
23
|
+
Here's an example:
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
job 'send an email' do
|
27
|
+
|
28
|
+
sendgrid do
|
29
|
+
to 'josh+pushpop@keen.io'
|
30
|
+
from 'pushpopapp+123@keen.io'
|
31
|
+
subject 'Is your inbox lonely?'
|
32
|
+
attachment '/funny_images/sad_inbox.jpeg'
|
33
|
+
body 'This email was intentionally left blank.'
|
34
|
+
preview false
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
```
|
39
|
+
The `to`, `from`, and `subject` methods should be self-explanatory. All expect strings.
|
40
|
+
|
41
|
+
The `body` method can take a string, or it can take the same parameters as the `template` method provided by the base step class. This example will use the rendered template contents as the body:
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
body 'pingpong_report.html.erb', response, step_responses
|
45
|
+
```
|
46
|
+
|
47
|
+
The `attachment` method is optional and takes a path to a file to be attached.
|
48
|
+
|
49
|
+
The `preview` setting is optional and defaults to false. If you set it to true the email contents will print out
|
50
|
+
to the console but the email will not be sent.
|
51
|
+
|
52
|
+
The `sendgrid` plugin requires that the following environment variables are set:
|
53
|
+
|
54
|
+
+ `SENDGRID_DOMAIN`
|
55
|
+
+ `SENDGRID_USERNAME`
|
56
|
+
+ `SENDGRID_PASSWORD`
|
57
|
+
|
58
|
+
##### Non-DSL methods
|
59
|
+
|
60
|
+
Need to send multiple emails in one step? Need more control over email sending? The DSL approach won't be sufficient for you.
|
61
|
+
Instead, use the `send_email` method exposed by the plugin directly. Here's an example:
|
62
|
+
|
63
|
+
``` ruby
|
64
|
+
job 'send multiple emails' do
|
65
|
+
|
66
|
+
step 'send some emails' do
|
67
|
+
|
68
|
+
['josh+1@keen.io', 'justin+1@keen.io'].each do |to_address|
|
69
|
+
send_email to_address, 'pushpop-app@keen.io', 'Nice subject', 'Nice body'
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
### Contributing
|
78
|
+
|
79
|
+
Code and documentation issues and pull requests are welcome.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$stdout.sync = true
|
2
|
+
|
3
|
+
$: << File.join(File.dirname(__FILE__), './lib')
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
desc 'Run Rspec unit tests'
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
+
t.pattern = 'spec/**/*_spec.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :spec
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
|
16
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'pushpop'
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
Mail.defaults do
|
5
|
+
delivery_method :smtp, { address: 'smtp.sendgrid.net',
|
6
|
+
port: 587,
|
7
|
+
domain: ENV['SENDGRID_DOMAIN'],
|
8
|
+
user_name: ENV['SENDGRID_USERNAME'],
|
9
|
+
password: ENV['SENDGRID_PASSWORD'],
|
10
|
+
authentication: 'plain',
|
11
|
+
enable_starttls_auto: true }
|
12
|
+
end
|
13
|
+
|
14
|
+
module Pushpop
|
15
|
+
|
16
|
+
class Sendgrid < Step
|
17
|
+
|
18
|
+
PLUGIN_NAME = 'sendgrid'
|
19
|
+
|
20
|
+
Pushpop::Job.register_plugin(Sendgrid::PLUGIN_NAME, Sendgrid)
|
21
|
+
|
22
|
+
attr_accessor :_from
|
23
|
+
attr_accessor :_to
|
24
|
+
attr_accessor :_subject
|
25
|
+
attr_accessor :_body
|
26
|
+
attr_accessor :_preview
|
27
|
+
attr_accessor :_attachment
|
28
|
+
|
29
|
+
def run(last_response=nil, step_responses=nil)
|
30
|
+
|
31
|
+
self.configure(last_response, step_responses)
|
32
|
+
|
33
|
+
# print the message if its just a preview
|
34
|
+
return print_preview if self._preview
|
35
|
+
|
36
|
+
_to = self._to
|
37
|
+
_from = self._from
|
38
|
+
_subject = self._subject
|
39
|
+
_body = self._body
|
40
|
+
_attachment = self._attachment
|
41
|
+
|
42
|
+
if _to && _from && _subject && _body
|
43
|
+
send_email(_to, _from, _subject, _body, _attachment)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def send_email(_to, _from, _subject, _body, _attachment)
|
48
|
+
Mail.deliver do
|
49
|
+
to _to
|
50
|
+
from _from
|
51
|
+
subject _subject
|
52
|
+
add_file _attachment if _attachment
|
53
|
+
text_part do
|
54
|
+
body _body
|
55
|
+
end
|
56
|
+
html_part do
|
57
|
+
content_type 'text/html; charset=UTF-8'
|
58
|
+
body _body
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def configure(last_response=nil, step_responses=nil)
|
64
|
+
self.instance_exec(last_response, step_responses, &block)
|
65
|
+
end
|
66
|
+
|
67
|
+
def from(from)
|
68
|
+
self._from = from
|
69
|
+
end
|
70
|
+
|
71
|
+
def to(to)
|
72
|
+
self._to = to
|
73
|
+
end
|
74
|
+
|
75
|
+
def subject(subject)
|
76
|
+
self._subject = subject
|
77
|
+
end
|
78
|
+
|
79
|
+
def preview(preview)
|
80
|
+
self._preview = preview
|
81
|
+
end
|
82
|
+
|
83
|
+
def body(*args)
|
84
|
+
if args.length == 1
|
85
|
+
self._body = args.first
|
86
|
+
else
|
87
|
+
self._body = template(*args)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def attachment(_attachment)
|
92
|
+
self._attachment = _attachment
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def print_preview
|
98
|
+
puts <<MESSAGE
|
99
|
+
To: #{self._to}
|
100
|
+
From: #{self._from}
|
101
|
+
Subject: #{self._subject}
|
102
|
+
|
103
|
+
#{self._body}
|
104
|
+
MESSAGE
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'pushpop-sendgrid/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
|
7
|
+
s.name = "pushpop-sendgrid"
|
8
|
+
s.version = Pushpop::Sendgrid::VERSION
|
9
|
+
s.authors = ["Josh Dzielak"]
|
10
|
+
s.email = "josh@keen.io"
|
11
|
+
s.homepage = "https://github.com/pushpop-project/pushpop-sendgrid"
|
12
|
+
s.summary = "Sendgrid plugin for sending emails with Pushpop"
|
13
|
+
|
14
|
+
s.add_dependency "pushpop"
|
15
|
+
s.add_dependency "mail"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
SPEC_TEMPLATES_DIRECTORY ||= File.expand_path('../', __FILE__)
|
4
|
+
|
5
|
+
describe Pushpop::Sendgrid do
|
6
|
+
|
7
|
+
describe '#configure' do
|
8
|
+
|
9
|
+
it 'should set various params' do
|
10
|
+
|
11
|
+
step = Pushpop::Sendgrid.new do
|
12
|
+
to 'josh@keen.io'
|
13
|
+
from 'depths@hell.com'
|
14
|
+
subject 'time is up'
|
15
|
+
body 'use code 3:16 for high leniency'
|
16
|
+
preview true
|
17
|
+
end
|
18
|
+
|
19
|
+
step.configure
|
20
|
+
|
21
|
+
step._to.should == 'josh@keen.io'
|
22
|
+
step._from.should == 'depths@hell.com'
|
23
|
+
step._subject.should == 'time is up'
|
24
|
+
step._body.should == 'use code 3:16 for high leniency'
|
25
|
+
step._preview.should == true
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#run' do
|
32
|
+
|
33
|
+
it 'should send some email' do
|
34
|
+
|
35
|
+
Mail.stub(:deliver)
|
36
|
+
|
37
|
+
step = Pushpop::Sendgrid.new do |response|
|
38
|
+
to 'josh@keen.io'
|
39
|
+
from 'alerts+pushpop@keen.io'
|
40
|
+
subject "There were #{response} Pageviews Today!"
|
41
|
+
body 'hey wats up'
|
42
|
+
end
|
43
|
+
|
44
|
+
step.run(365)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should not sent email if nothing is configured' do
|
49
|
+
Mail.stub(:deliver).never
|
50
|
+
step = Pushpop::Sendgrid.new do end
|
51
|
+
step.run(365)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#body' do
|
57
|
+
|
58
|
+
it 'should use a string if given 1 arg' do
|
59
|
+
step = Pushpop::Sendgrid.new
|
60
|
+
step.body 'hello world'
|
61
|
+
step._body.should == 'hello world'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should use a template if more than 1 arg is passed' do
|
65
|
+
step = Pushpop::Sendgrid.new
|
66
|
+
step.body('spec.html.erb', 500, {}, SPEC_TEMPLATES_DIRECTORY)
|
67
|
+
step._body.strip.should == '<pre>500</pre>'
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#attachment' do
|
73
|
+
|
74
|
+
it 'should attach a file to an email' do
|
75
|
+
step = Pushpop::Sendgrid.new
|
76
|
+
step.attachment 'huzzah.txt'
|
77
|
+
step._attachment.should == 'huzzah.txt'
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
data/spec/spec.html.erb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushpop-sendgrid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Dzielak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pushpop
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mail
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description:
|
47
|
+
email: josh@keen.io
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .travis.yml
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/pushpop-sendgrid.rb
|
59
|
+
- lib/pushpop-sendgrid/version.rb
|
60
|
+
- pushpop-sendgrid.gemspec
|
61
|
+
- spec/pushpop-sendgrid_spec.rb
|
62
|
+
- spec/spec.html.erb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
homepage: https://github.com/pushpop-project/pushpop-sendgrid
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.23
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Sendgrid plugin for sending emails with Pushpop
|
88
|
+
test_files:
|
89
|
+
- spec/pushpop-sendgrid_spec.rb
|
90
|
+
- spec/spec.html.erb
|
91
|
+
- spec/spec_helper.rb
|