outbox-bandwidth 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +8 -0
- data/lib/.DS_Store +0 -0
- data/lib/outbox/.DS_Store +0 -0
- data/lib/outbox/bandwidth.rb +12 -0
- data/lib/outbox/bandwidth/.DS_Store +0 -0
- data/lib/outbox/bandwidth/client.rb +56 -0
- data/lib/outbox/bandwidth/version.rb +7 -0
- data/outbox-bandwidth.gemspec +28 -0
- data/outbox-bandwidth.rb +3 -0
- data/spec/outbox/bandwidth/client_spec.rb +73 -0
- data/spec/outbox/bandwidth_spec.rb +9 -0
- data/spec/spec_helper.rb +4 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 795ddc3b92fe3d399e8628c635e202a8d8d004ee23a830386450aa7c1ac4d224
|
4
|
+
data.tar.gz: 908e1f5e20edae4ec276a8464ab8820d3a7fc8ab9784b3c02c52708dbf0933fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 738d34f68f434df58f3c62d10407e3ba87231fa53001bd0568ca245fa6f14734cb9e761b2d587cb585dcc49a5c331707e261787228b1fae30c88d76945d3e942
|
7
|
+
data.tar.gz: 2a5775769b1c4bc79ff3e3dc92aff28c7a10cf08ff34152bd4ee47f0acf38dbfc23fb8e017ff26153f384de9f0379f82fd7c061b1354c9fc5fcfb1b3e84e7ed4
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'vendor/**/*'
|
4
|
+
DisplayCopNames: true
|
5
|
+
DisplayStyleGuide: true
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/**/*'
|
13
|
+
|
14
|
+
Naming/FileName:
|
15
|
+
Exclude:
|
16
|
+
- 'lib/outbox-bandwidth.rb'
|
17
|
+
|
18
|
+
Layout/LineLength:
|
19
|
+
IgnoreCopDirectives: true
|
20
|
+
Max: 100
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2020 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/Rakefile
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bandwidth'
|
4
|
+
|
5
|
+
module Outbox
|
6
|
+
module Bandwidth
|
7
|
+
# Uses Bandwidth's official Ruby API client (bandwidth) to deliver
|
8
|
+
# SMS messages.
|
9
|
+
#
|
10
|
+
# Outbox::Messages::SMS.default_client(
|
11
|
+
# :bandwidth,
|
12
|
+
# account_sid: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
13
|
+
# token: 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
|
14
|
+
# secret: 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
|
15
|
+
# )
|
16
|
+
# sms = Outbox::Messages::SMS.new(
|
17
|
+
# to: '+15552224444',
|
18
|
+
# from: '+15551115555',
|
19
|
+
# body: 'Hello World'
|
20
|
+
# )
|
21
|
+
# sms.deliver
|
22
|
+
class Client < Outbox::Clients::Base
|
23
|
+
attr_reader :api_client
|
24
|
+
include ::Bandwidth::Messaging
|
25
|
+
|
26
|
+
def initialize(settings = nil)
|
27
|
+
super
|
28
|
+
|
29
|
+
options = @settings.dup
|
30
|
+
@api_client = ::Bandwidth::Client.new(
|
31
|
+
messaging_basic_auth_user_name: options[:token],
|
32
|
+
messaging_basic_auth_password: options[:secret]
|
33
|
+
)
|
34
|
+
@account_id = options[:subaccount_id] || options[:account_id]
|
35
|
+
end
|
36
|
+
|
37
|
+
def deliver(sms)
|
38
|
+
messaging_client = @api_client.messaging_client.client
|
39
|
+
body = ::Bandwidth::MessageRequest.new
|
40
|
+
body.application_id = sms[:application_id]
|
41
|
+
body.to = sms.to
|
42
|
+
body.from = sms.from
|
43
|
+
body.text = sms.body
|
44
|
+
body.media = [sms[:media_url]] unless sms[:media_url].nil?
|
45
|
+
messaging_client.create_message(account_id(sms), body: body)
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def account_id(sms)
|
51
|
+
return sms[:account_id] unless sms[:account_id].nil?
|
52
|
+
@account_id
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'outbox/bandwidth/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'outbox-bandwidth'
|
9
|
+
spec.version = Outbox::Bandwidth::VERSION
|
10
|
+
spec.authors = ['Pete Browne', 'Kemp Travis']
|
11
|
+
spec.email = ['pete.browne@localmed.com']
|
12
|
+
spec.summary = 'Outbox SMS client for Bandwidth.'
|
13
|
+
spec.description = 'Bandwidth API wrapper for Outbox, a generic interface for sending notificatons.'
|
14
|
+
spec.homepage = 'https://github.com/localmed/outbox-bandwidth'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'bandwidth-sdk', '~> 3.9.0'
|
23
|
+
spec.add_runtime_dependency 'outbox', '~> 0.2'
|
24
|
+
spec.add_development_dependency 'bundler', '>= 1.6'
|
25
|
+
spec.add_development_dependency 'rake', '~> 12.0.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.5.0'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.82.0'
|
28
|
+
end
|
data/outbox-bandwidth.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
describe Outbox::Bandwidth::Client do
|
7
|
+
describe '.new' do
|
8
|
+
it 'configures the Bandwidth API client' do
|
9
|
+
api_client = double(:api_client)
|
10
|
+
expect(::Bandwidth::Client).to receive(:new).with(
|
11
|
+
messaging_basic_auth_user_name: 'AC1',
|
12
|
+
messaging_basic_auth_password: 'abcdef'
|
13
|
+
).and_return(api_client)
|
14
|
+
client = Outbox::Bandwidth::Client.new(
|
15
|
+
token: 'AC1',
|
16
|
+
secret: 'abcdef'
|
17
|
+
)
|
18
|
+
expect(client.api_client).to be(api_client)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#deliver' do
|
23
|
+
before do
|
24
|
+
@messaging_client = double(:messaging_client)
|
25
|
+
@api_client = double(:api_client)
|
26
|
+
@body = double(:body)
|
27
|
+
allow(::Bandwidth::MessageRequest).to receive(:new).and_return(@body)
|
28
|
+
allow(::Bandwidth::Client).to receive(:new).with(
|
29
|
+
messaging_basic_auth_user_name: 'AC1',
|
30
|
+
messaging_basic_auth_password: 'abcdef'
|
31
|
+
).and_return(@api_client)
|
32
|
+
@client = Outbox::Bandwidth::Client.new(
|
33
|
+
token: 'AC1',
|
34
|
+
secret: 'abcdef',
|
35
|
+
account_id: 'account_1'
|
36
|
+
)
|
37
|
+
@sms = Outbox::Messages::SMS.new do
|
38
|
+
to '+14155551212'
|
39
|
+
from 'Company Name'
|
40
|
+
body 'Hello world.'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'delivers the SMS' do
|
45
|
+
expect(@body).to receive(:application_id=)
|
46
|
+
expect(@body).to receive(:to=)
|
47
|
+
expect(@body).to receive(:from=)
|
48
|
+
expect(@body).to receive(:text=)
|
49
|
+
expect(@api_client).to receive_message_chain(:messaging_client, :client) { @messaging_client }
|
50
|
+
expect(@messaging_client).to receive(:create_message).with(
|
51
|
+
'account_1',
|
52
|
+
body: @body
|
53
|
+
)
|
54
|
+
@client.deliver(@sms)
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with a subaccount' do
|
58
|
+
it 'delivers the SMS from the subaccount' do
|
59
|
+
@sms[:account_id] = 'subaccount_id_1'
|
60
|
+
expect(@body).to receive(:application_id=)
|
61
|
+
expect(@body).to receive(:to=)
|
62
|
+
expect(@body).to receive(:from=)
|
63
|
+
expect(@body).to receive(:text=)
|
64
|
+
expect(@api_client).to receive_message_chain(:messaging_client, :client) { @messaging_client }
|
65
|
+
expect(@messaging_client).to receive(:create_message).with(
|
66
|
+
'subaccount_id_1',
|
67
|
+
body: @body
|
68
|
+
)
|
69
|
+
@client.deliver(@sms)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: outbox-bandwidth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pete Browne
|
8
|
+
- Kemp Travis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bandwidth-sdk
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.9.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.9.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: outbox
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.2'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.2'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.6'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.6'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 12.0.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 12.0.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 3.5.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 3.5.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.82.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.82.0
|
98
|
+
description: Bandwidth API wrapper for Outbox, a generic interface for sending notificatons.
|
99
|
+
email:
|
100
|
+
- pete.browne@localmed.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".DS_Store"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- Rakefile
|
113
|
+
- lib/.DS_Store
|
114
|
+
- lib/outbox/.DS_Store
|
115
|
+
- lib/outbox/bandwidth.rb
|
116
|
+
- lib/outbox/bandwidth/.DS_Store
|
117
|
+
- lib/outbox/bandwidth/client.rb
|
118
|
+
- lib/outbox/bandwidth/version.rb
|
119
|
+
- outbox-bandwidth.gemspec
|
120
|
+
- outbox-bandwidth.rb
|
121
|
+
- spec/outbox/bandwidth/client_spec.rb
|
122
|
+
- spec/outbox/bandwidth_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
homepage: https://github.com/localmed/outbox-bandwidth
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubygems_version: 3.0.3
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Outbox SMS client for Bandwidth.
|
147
|
+
test_files:
|
148
|
+
- spec/outbox/bandwidth/client_spec.rb
|
149
|
+
- spec/outbox/bandwidth_spec.rb
|
150
|
+
- spec/spec_helper.rb
|