pushpop-twilio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+
4
+ rvm:
5
+ - 2.1.1
6
+
7
+ script:
8
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pushpop'
4
+ gem 'twilio-ruby'
5
+
6
+ group :development, :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'mail'
10
+ end
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,60 @@
1
+ ## pushpop-twilio
2
+
3
+ Twilio plugin for [Pushpop](https://github.com/pushpop-project/pushpop).
4
+
5
+ ### Installation
6
+
7
+ Add `pushpop-twilio` to your Gemfile:
8
+
9
+ ``` ruby
10
+ gem 'pushpop-twilio'
11
+ ```
12
+
13
+ or install it as a gem:
14
+
15
+ ``` shell
16
+ $ gem install pushpop-twilio
17
+ ```
18
+
19
+ ### Usage
20
+
21
+ The `twilio` plugin provides a DSL to specify SMS recipient information as well as the message itself.
22
+
23
+ Here's an example:
24
+
25
+ ``` ruby
26
+ job 'send a text' do
27
+
28
+ twilio do
29
+ to '+18005555555'
30
+ body 'Quick, move your car!'
31
+ end
32
+
33
+ end
34
+ ```
35
+
36
+ The `twilio` plugin requires that the following environment variables are set:
37
+
38
+ + `TWILIO_AUTH_TOKEN`
39
+ + `TWILIO_SID`
40
+ + `TWILIO_FROM`
41
+
42
+ ##### Non-DSL Methods
43
+
44
+ If you need a lower level interface to Twilio functionality, use the `send_message` method exposed by the plugin directly. Here's an example:
45
+
46
+ ``` ruby
47
+ job 'send a few texts' do
48
+
49
+ twilio do
50
+ ['+18005555555','+18005555556'].each do |to_number|
51
+ send_message(to_number, 'Quick, move your car!')
52
+ end
53
+ end
54
+
55
+ end
56
+ ```
57
+
58
+ ### Contributing
59
+
60
+ 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,61 @@
1
+ require 'pushpop'
2
+ require 'twilio-ruby'
3
+
4
+ TWILIO_SID = ENV['TWILIO_SID']
5
+ TWILIO_AUTH_TOKEN = ENV['TWILIO_AUTH_TOKEN']
6
+ TWILIO_FROM = ENV['TWILIO_FROM']
7
+
8
+ module Pushpop
9
+
10
+ class Twilio < Step
11
+
12
+ PLUGIN_NAME = 'twilio'
13
+
14
+ Pushpop::Job.register_plugin(Twilio::PLUGIN_NAME, Twilio)
15
+
16
+ attr_accessor :_from
17
+ attr_accessor :_to
18
+ attr_accessor :_body
19
+
20
+ def run(last_response=nil, step_responses=nil)
21
+
22
+ self.configure(last_response, step_responses)
23
+
24
+ _to = self._to
25
+ _from = self._from || TWILIO_FROM
26
+ _body = self._body
27
+
28
+ if _to && _from && _body
29
+ send_message(_to, _from, _body)
30
+ else
31
+ raise 'Please configure to, from, and body to send an SMS'
32
+ end
33
+ end
34
+
35
+ def send_message(to, from, body)
36
+ client = ::Twilio::REST::Client.new(TWILIO_SID, TWILIO_AUTH_TOKEN)
37
+ client.account.messages.create(
38
+ from: from,
39
+ to: to,
40
+ body: body )
41
+ end
42
+
43
+ def from(from)
44
+ self._from = from
45
+ end
46
+
47
+ def to(to)
48
+ self._to = to
49
+ end
50
+
51
+ def body(body)
52
+ self._body = body
53
+ end
54
+
55
+ def configure(last_response=nil, step_responses=nil)
56
+ self.instance_exec(last_response, step_responses, &block)
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,5 @@
1
+ module Pushpop
2
+ class Twilio
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'pushpop-twilio/version'
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.name = "pushpop-twilio"
8
+ s.version = Pushpop::Twilio::VERSION
9
+ s.authors = ["Josh Dzielak"]
10
+ s.email = "josh@keen.io"
11
+ s.homepage = "https://github.com/pushpop-project/pushpop-twilio"
12
+ s.summary = "Twilio plugin for sending SMS messages from Pushpop"
13
+
14
+ s.add_dependency "pushpop"
15
+ s.add_dependency "twilio-ruby"
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,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushpop::Twilio do
4
+
5
+ describe '#configure' do
6
+
7
+ it 'should set various params' do
8
+
9
+ step = Pushpop::Twilio.new do
10
+ to '+18555555555'
11
+ from '+18555555556'
12
+ body 'use code 3:16 for high leniency'
13
+ end
14
+
15
+ step.configure
16
+
17
+ step._to.should == '+18555555555'
18
+ step._from.should == '+18555555556'
19
+ step._body.should == 'use code 3:16 for high leniency'
20
+
21
+ end
22
+
23
+ end
24
+
25
+ describe '#run' do
26
+
27
+ it 'should send a message' do
28
+
29
+ step = Pushpop::Twilio.new do |response|
30
+ to '+18555555555'
31
+ from '+18555555556'
32
+ body "The response is #{response}"
33
+ end
34
+ step.configure
35
+ step.stub(:send_message).with('+18555555555', '+18555555556', 'The response is 365').and_return(5)
36
+ step.run(365).should == 5
37
+
38
+ end
39
+
40
+ it 'should not send a message if body not specified' do
41
+ step = Pushpop::Twilio.new do
42
+ to '+18555555555'
43
+ from '+18555555556'
44
+ end
45
+ step.configure
46
+ step.stub(:send_message).and_return(5)
47
+ expect {
48
+ step.run(365)
49
+ }.to raise_error /Please configure/
50
+ end
51
+
52
+ it 'should not send a message if to not specified' do
53
+ step = Pushpop::Twilio.new do |response|
54
+ from '+18555555556'
55
+ body "The response is #{response}"
56
+ end
57
+ step.configure
58
+ step.stub(:send_message).and_return(5)
59
+ expect {
60
+ step.run(365)
61
+ }.to raise_error /Please configure/
62
+
63
+ end
64
+
65
+ it 'should not send a message if from not specified' do
66
+ step = Pushpop::Twilio.new do |response|
67
+ to '+18555555556'
68
+ body "The response is #{response}"
69
+ end
70
+ step.configure
71
+ step.stub(:send_message).and_return(5)
72
+ expect {
73
+ step.run(365)
74
+ }.to raise_error /Please configure/
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,6 @@
1
+ <% if response %>
2
+ <pre><%= response %></pre>
3
+ <% else %>
4
+ <pre><%= step_responses[:test] %></pre>
5
+ <% end %>
6
+
@@ -0,0 +1,11 @@
1
+ $: << File.join(File.dirname(__FILE__), '../lib')
2
+
3
+ require 'pushpop'
4
+ require 'pushpop-twilio'
5
+
6
+ RSpec.configure do |config|
7
+ config.before :each do
8
+ Pushpop.jobs.clear
9
+ end
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pushpop-twilio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
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: twilio-ruby
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-twilio.rb
59
+ - lib/pushpop-twilio/version.rb
60
+ - pushpop-twilio.gemspec
61
+ - spec/pushpop-twilio_spec.rb
62
+ - spec/spec.html.erb
63
+ - spec/spec_helper.rb
64
+ homepage: https://github.com/pushpop-project/pushpop-twilio
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: Twilio plugin for sending SMS messages from Pushpop
88
+ test_files:
89
+ - spec/pushpop-twilio_spec.rb
90
+ - spec/spec.html.erb
91
+ - spec/spec_helper.rb