outbox-twilio 0.2.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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +6 -0
- data/lib/outbox-twilio.rb +1 -0
- data/lib/outbox/twilio.rb +10 -0
- data/lib/outbox/twilio/client.rb +46 -0
- data/lib/outbox/twilio/version.rb +5 -0
- data/outbox-twilio.gemspec +26 -0
- data/spec/outbox/twilio/client_spec.rb +51 -0
- data/spec/outbox/twilio_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f76b2573c58081b5482e6d6c6cb737a7a7b6e61c
|
4
|
+
data.tar.gz: d189ed5b419e0c30d3a59f69e07d67022fe1732a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c75f9d19ae1d5163a7d7f0b09fa328d7c0b013077d06e7cf676846eaee24d271b04a8d16afa12ea86e8053c2e9388bf87a99af03d0f07b953466ab814f92fcb9
|
7
|
+
data.tar.gz: d463c686af3d5be49db8d514fd0eda925405fedebb15b625ec6e9de459c38cfff57880da303c4cbf5414bfd4be566005a04084dbd8cf7790f02776202f42ec18
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 LocalMed
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
Outbox::Twilio
|
2
|
+
==============
|
3
|
+
|
4
|
+
[](http://badge.fury.io/rb/outbox-twilio)
|
5
|
+
|
6
|
+
Twilio SMS client wrapper for [Outbox](https://github.com/localmed/outbox).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
gem 'outbox-twilio'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
``` bash
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
``` bash
|
25
|
+
$ gem install outbox-twilio
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Configure Outbox to use Outbox::Twilio as the default SMS client:
|
31
|
+
|
32
|
+
``` ruby
|
33
|
+
Outbox::Messages::SMS.default_client(
|
34
|
+
:twilio,
|
35
|
+
account_sid: 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
36
|
+
auth_token: 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
|
37
|
+
# Supports other Twilio::REST::Client options:
|
38
|
+
timeout: 30,
|
39
|
+
retry_limit: 1
|
40
|
+
)
|
41
|
+
```
|
42
|
+
|
43
|
+
SMS messages will now use the Twilio API for devlivery:
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
sms = Outbox::Messages::SMS.new(
|
47
|
+
from: '+15551115555',
|
48
|
+
body: 'Hello World',
|
49
|
+
# supports Twilio's non-standard parameters:
|
50
|
+
media_url: 'https://www.example.com/hearts.png'
|
51
|
+
)
|
52
|
+
sms.deliver('+15552224444')
|
53
|
+
```
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( https://github.com/localmed/outbox-twilio/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'outbox/twilio'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'twilio-ruby'
|
2
|
+
|
3
|
+
module Outbox
|
4
|
+
module Twilio
|
5
|
+
# Uses Twilio's official Ruby API client (twilio-ruby) to deliver
|
6
|
+
# SMS messages.
|
7
|
+
#
|
8
|
+
# Outbox::Messages::SMS.default_client(
|
9
|
+
# :twilio,
|
10
|
+
# account_sid: 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
11
|
+
# auth_token: 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
|
12
|
+
# )
|
13
|
+
# sms = Outbox::Messages::SMS.new(
|
14
|
+
# from: '+15551115555',
|
15
|
+
# body: 'Hello World'
|
16
|
+
# )
|
17
|
+
# sms.deliver('+15552224444')
|
18
|
+
class Client < Outbox::Clients::Base
|
19
|
+
attr_reader :api_client
|
20
|
+
|
21
|
+
def initialize(settings = nil)
|
22
|
+
super
|
23
|
+
|
24
|
+
options = @settings.dup
|
25
|
+
@api_client = ::Twilio::REST::Client.new(
|
26
|
+
options.delete(:account_sid),
|
27
|
+
options.delete(:auth_token),
|
28
|
+
options
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def deliver(sms)
|
33
|
+
params = {
|
34
|
+
from: sms.from,
|
35
|
+
to: sms.to,
|
36
|
+
body: sms.body,
|
37
|
+
media_url: sms[:media_url],
|
38
|
+
status_callback: sms[:status_callback],
|
39
|
+
application_sid: sms[:application_sid]
|
40
|
+
}
|
41
|
+
params.delete_if { |_, value| value.nil? }
|
42
|
+
@api_client.account.messages.create(params)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'outbox/twilio/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'outbox-twilio'
|
8
|
+
spec.version = Outbox::Twilio::VERSION
|
9
|
+
spec.authors = ['Pete Browne']
|
10
|
+
spec.email = ['pete.browne@localmed.com']
|
11
|
+
spec.summary = %q{Outbox SMS client for Twilio.}
|
12
|
+
spec.description = %q{Twilio API wrapper for Outbox, a generic interface for sending notificatons.}
|
13
|
+
spec.homepage = 'https://github.com/localmed/outbox-twilio'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'outbox', '~> 0.2'
|
22
|
+
spec.add_runtime_dependency 'twilio-ruby', '~> 3.11'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outbox::Twilio::Client do
|
4
|
+
describe '.new' do
|
5
|
+
it 'configures the Twilio API client' do
|
6
|
+
api_client = double(:api_client)
|
7
|
+
expect(::Twilio::REST::Client).to receive(:new).with(
|
8
|
+
'AC1',
|
9
|
+
'abcdef',
|
10
|
+
timeout: 5,
|
11
|
+
retry_limit: 2
|
12
|
+
).and_return(api_client)
|
13
|
+
client = Outbox::Twilio::Client.new(
|
14
|
+
account_sid: 'AC1',
|
15
|
+
auth_token: 'abcdef',
|
16
|
+
timeout: 5,
|
17
|
+
retry_limit: 2
|
18
|
+
)
|
19
|
+
expect(client.api_client).to be(api_client)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#deliver' do
|
24
|
+
before do
|
25
|
+
@client = Outbox::Twilio::Client.new(
|
26
|
+
account_sid: 'AC1',
|
27
|
+
auth_token: 'abcdef'
|
28
|
+
)
|
29
|
+
@sms = Outbox::Messages::SMS.new do
|
30
|
+
to '+14155551212'
|
31
|
+
from 'Company Name'
|
32
|
+
body 'Hello world.'
|
33
|
+
end
|
34
|
+
@sms[:media_url] = 'http://www.example.com/hearts.png'
|
35
|
+
@sms[:status_callback] = 'http://www.example.com/callback'
|
36
|
+
@sms[:application_sid] = '1234'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'delivers the SMS' do
|
40
|
+
expect(@client.api_client.account.messages).to receive(:create).with(
|
41
|
+
to: '+14155551212',
|
42
|
+
from: 'Company Name',
|
43
|
+
body: 'Hello world.',
|
44
|
+
media_url: 'http://www.example.com/hearts.png',
|
45
|
+
status_callback: 'http://www.example.com/callback',
|
46
|
+
application_sid: '1234'
|
47
|
+
)
|
48
|
+
@client.deliver(@sms)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: outbox-twilio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pete Browne
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: outbox
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: twilio-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.11'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Twilio API wrapper for Outbox, a generic interface for sending notificatons.
|
84
|
+
email:
|
85
|
+
- pete.browne@localmed.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/outbox-twilio.rb
|
97
|
+
- lib/outbox/twilio.rb
|
98
|
+
- lib/outbox/twilio/client.rb
|
99
|
+
- lib/outbox/twilio/version.rb
|
100
|
+
- outbox-twilio.gemspec
|
101
|
+
- spec/outbox/twilio/client_spec.rb
|
102
|
+
- spec/outbox/twilio_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: https://github.com/localmed/outbox-twilio
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Outbox SMS client for Twilio.
|
128
|
+
test_files:
|
129
|
+
- spec/outbox/twilio/client_spec.rb
|
130
|
+
- spec/outbox/twilio_spec.rb
|
131
|
+
- spec/spec_helper.rb
|