minitext 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +117 -0
- data/Rakefile +10 -10
- data/lib/minitext/allowlist_proxy.rb +30 -0
- data/lib/minitext/configuration.rb +15 -0
- data/lib/minitext/message.rb +10 -40
- data/lib/minitext/test_gateway.rb +1 -1
- data/lib/minitext/twilio_gateway.rb +13 -14
- data/lib/minitext/version.rb +5 -0
- data/lib/minitext.rb +18 -21
- data/minitext.gemspec +39 -0
- data/sig/minitext.rbs +4 -0
- metadata +27 -19
- data/lib/minitext/missing_parameter.rb +0 -3
- data/lib/minitext/railtie.rb +0 -25
- data/lib/minitext/whitelist_proxy.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e868a41b4b38fb23b71eb4fc8e3782023226825d83dd6c8730ec0c942225c02e
|
4
|
+
data.tar.gz: f2acf62b5831c96b0b95874a691bdb8128e36395a4f05fbf32213b3e82c6e74f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f60cd3a92a7a099e536976615b4d54f8e657aadfb9f881decda07ebb4e85d954c3a8a5a4a059ea4f76ff4b2551bf2a77c7235c316e6855042fb6694c841835a5
|
7
|
+
data.tar.gz: ec09e291c700f63f8831d1de157701ecff4f53c3cf5715555b205754e080d1b508013bca0ec510074d579adffba5ba78445a84d1828d8ba720732c1f8482ba6c
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Kyle Rippey
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# minitext
|
2
|
+
|
3
|
+
A simple SMS framework for sending messages via Twilio.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
In your Gemfile add:
|
9
|
+
```ruby
|
10
|
+
gem "minitext"
|
11
|
+
```
|
12
|
+
|
13
|
+
Install your gems:
|
14
|
+
```bash
|
15
|
+
bundle install
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
First set up a gateway:
|
22
|
+
```ruby
|
23
|
+
Minitext.configure do |config|
|
24
|
+
config.gateway = Minitext::TwilioGateway.new(account_sid: 'your_twilio_account_sid', auth_token: 'your_twilio_auth_token')
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
Then send some texts:
|
29
|
+
```ruby
|
30
|
+
Minitext.text(from: '1234567890', to: '9876543210', body: 'Hello world').deliver
|
31
|
+
```
|
32
|
+
|
33
|
+
You can send using a Twilio Messaging Service instead of a from number by specifying it's SID:
|
34
|
+
```ruby
|
35
|
+
Minitext.text(messaging_service_sid: 'your-messaging-service-sid', to: '9876543210', body: 'Hello world').deliver
|
36
|
+
```
|
37
|
+
|
38
|
+
You can send mms texts with a media_url:
|
39
|
+
```ruby
|
40
|
+
Minitext.text(from: '1234567890', to: '9876543210', body: 'Hello world', media_url: 'http://placekitten.com/200/300').deliver
|
41
|
+
```
|
42
|
+
|
43
|
+
### Allowlist proxy
|
44
|
+
|
45
|
+
If you want to restrict the numbers that you can send texts to, use the `AllowlistProxy` wrapper.
|
46
|
+
|
47
|
+
Set up your allowlist proxy:
|
48
|
+
```ruby
|
49
|
+
Minitext.configure do |config|
|
50
|
+
allowlist = ['9876543210']
|
51
|
+
twilio_gateway = Minitext::TwilioGateway.new(account_sid: 'your_twilio_account_sid', auth_token: 'your_twilio_auth_token')
|
52
|
+
|
53
|
+
config.gateway = Minitext::AllowlistProxy.new(allowed: allowlist, gateway: twilio_gateway)
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Then send some texts:
|
58
|
+
```ruby
|
59
|
+
Minitext.text(from: '1234567890', to: '9876543210', body: 'This text should succeed.').deliver
|
60
|
+
|
61
|
+
Minitext.text(from: '1234567890', to: '5559991111', body: 'This text should fail.').deliver
|
62
|
+
```
|
63
|
+
|
64
|
+
|
65
|
+
## Rails configuration
|
66
|
+
|
67
|
+
Here are some examples of how you might configure Minitext in different Rails environments.
|
68
|
+
|
69
|
+
### Production
|
70
|
+
```ruby
|
71
|
+
Minitext.configure do |config|
|
72
|
+
config.gateway = Minitext::TwilioGateway.new(account_sid: '123', auth_token: 'abc')
|
73
|
+
|
74
|
+
# You can set a default `from` number for all messages if you don't want to specify it everywhere you call Minitext.text
|
75
|
+
# config.message_defaults = { from: '5551234567' }
|
76
|
+
|
77
|
+
# Or, you can specify a messaging_service_sid instead:
|
78
|
+
# config.message_defaults = { messaging_service_sid: 'your_default_messaging_service_sid' }
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
### Test
|
83
|
+
```ruby
|
84
|
+
Minitext.configure do |config|
|
85
|
+
config.gateway = Minitext::TestGateway.new
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
### Development
|
90
|
+
```ruby
|
91
|
+
Minitext.configure do |config|
|
92
|
+
# You could allow devs to send messages to themselves in development mode if they start the server with an
|
93
|
+
# environment variable, like so: `SEND_LIVE_SMS_TO=5551234567 rails s`
|
94
|
+
|
95
|
+
allowlist = Array(ENV.fetch("SEND_LIVE_SMS_TO", nil)).compact
|
96
|
+
twilio_gateway = Minitext::TwilioGateway.new(account_sid: '123', auth_token: 'abc')
|
97
|
+
|
98
|
+
config.gateway = Minitext::AllowlistProxy.new(allowed: allowlist, gateway: twilio_gateway)
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
|
103
|
+
## Testing
|
104
|
+
|
105
|
+
If you do not specify a gateway via configuration, Minitext uses a `TestGateway` object by default.
|
106
|
+
|
107
|
+
Example test:
|
108
|
+
```ruby
|
109
|
+
Minitext.text(from: '1234567890', to: '9876543210', body: 'This text should succeed.').deliver
|
110
|
+
|
111
|
+
assert_equal 1, Minitext.gateway.deliveries.length
|
112
|
+
```
|
113
|
+
|
114
|
+
Don't forget to cleanup after yourself in your teardown methods:
|
115
|
+
```ruby
|
116
|
+
Minitext.gateway.deliveries.clear
|
117
|
+
```
|
data/Rakefile
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
begin
|
2
|
-
require
|
3
|
+
require "bundler/setup"
|
3
4
|
rescue LoadError
|
4
|
-
puts
|
5
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
6
|
end
|
6
7
|
|
7
|
-
|
8
|
+
require "bundler/gem_tasks"
|
9
|
+
require "minitest/test_task"
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
t.
|
13
|
-
t.
|
14
|
-
t.pattern = 'test/**/*_test.rb'
|
15
|
-
t.verbose = false
|
11
|
+
Minitest::TestTask.create(:test) do |t|
|
12
|
+
t.libs << "test"
|
13
|
+
t.libs << "lib"
|
14
|
+
t.warning = false
|
15
|
+
t.test_globs = ["test/**/*_test.rb"]
|
16
16
|
end
|
17
17
|
|
18
18
|
task default: :test
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
module Minitext
|
4
|
+
class AllowlistProxy
|
5
|
+
attr_reader :allowed, :gateway
|
6
|
+
|
7
|
+
def initialize(allowed:, gateway: nil)
|
8
|
+
@allowed = Set.new(allowed)
|
9
|
+
@gateway = gateway || TestGateway.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def deliver(message)
|
13
|
+
gateway.deliver(message) if allowed?(message.to)
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method, *args, &block)
|
17
|
+
gateway.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def respond_to_missing?(method, *args)
|
21
|
+
gateway.respond_to?(method)
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def allowed?(to)
|
27
|
+
allowed.include?(to)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Minitext
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :gateway, :message_defaults
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@gateway = TestGateway.new
|
7
|
+
@message_defaults = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def reset!
|
11
|
+
@gateway = TestGateway.new
|
12
|
+
@message_defaults = {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/minitext/message.rb
CHANGED
@@ -1,51 +1,21 @@
|
|
1
1
|
module Minitext
|
2
2
|
class Message
|
3
|
-
attr_accessor :from, :to, :body, :gateway, :media_url
|
3
|
+
attr_accessor :from, :messaging_service_sid, :to, :body, :gateway, :media_url
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(to:, body:, gateway:, from: nil, messaging_service_sid: nil, media_url: nil)
|
6
|
+
if from.nil? && messaging_service_sid.nil?
|
7
|
+
raise ArgumentError.new("must supply either the 'from' or 'messaging_service_sid' argument")
|
8
8
|
end
|
9
|
-
end
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
@gateway = gateway
|
11
|
+
@messaging_service_sid = messaging_service_sid
|
12
|
+
@from = from
|
13
|
+
@to = to
|
14
|
+
@body = body
|
13
15
|
end
|
14
16
|
|
15
17
|
def deliver
|
16
|
-
|
17
|
-
!!gateway.deliver(self)
|
18
|
-
end
|
19
|
-
|
20
|
-
def valid?
|
21
|
-
valid_param?(from) && valid_param?(to) && valid_param?(body) && valid_optional_param?(media_url) && !gateway.nil?
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
|
26
|
-
def valid_optional_param?(param)
|
27
|
-
param.nil? || valid_param?(param)
|
28
|
-
end
|
29
|
-
|
30
|
-
def valid_param?(param)
|
31
|
-
!(param.nil? || param.empty?)
|
32
|
-
end
|
33
|
-
|
34
|
-
def raise_errors
|
35
|
-
case
|
36
|
-
when !valid_param?(from)
|
37
|
-
raise_missing_parameter('from')
|
38
|
-
when !valid_param?(to)
|
39
|
-
raise_missing_parameter('to')
|
40
|
-
when !valid_param?(body)
|
41
|
-
raise_missing_parameter('body')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
|
47
|
-
def raise_missing_parameter(param)
|
48
|
-
raise Minitext::MissingParameter.new("#{param} parameter cannot be nil or empty")
|
18
|
+
gateway.deliver(self)
|
49
19
|
end
|
50
20
|
end
|
51
21
|
end
|
@@ -2,30 +2,29 @@ require 'twilio-ruby'
|
|
2
2
|
|
3
3
|
module Minitext
|
4
4
|
class TwilioGateway
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :account_sid, :auth_token
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
|
9
|
-
|
10
|
-
subaccount = config[:subaccount]
|
11
|
-
@client = Twilio::REST::Client.new(sid, token)
|
12
|
-
@client = client.accounts.get(subaccount) if subaccount
|
7
|
+
def initialize(account_sid:, auth_token:)
|
8
|
+
@account_sid = account_sid
|
9
|
+
@auth_token = auth_token
|
13
10
|
end
|
14
11
|
|
15
12
|
def deliver(message)
|
16
13
|
params = {
|
14
|
+
messaging_service_sid: message.messaging_service_sid,
|
17
15
|
from: message.from,
|
18
16
|
to: message.to,
|
19
17
|
body: message.body.strip,
|
20
|
-
|
18
|
+
media_url: message.media_url,
|
19
|
+
}.compact
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
client.messages.create(**params)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
)
|
26
|
+
def client
|
27
|
+
@client ||= Twilio::REST::Client.new(account_sid, auth_token)
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
data/lib/minitext.rb
CHANGED
@@ -1,32 +1,29 @@
|
|
1
|
-
|
2
|
-
autoload :Message, 'minitext/message'
|
3
|
-
autoload :MissingParameter, 'minitext/missing_parameter'
|
4
|
-
autoload :TestGateway, 'minitext/test_gateway'
|
5
|
-
autoload :TwilioGateway, 'minitext/twilio_gateway'
|
6
|
-
autoload :WhitelistProxy, 'minitext/whitelist_proxy'
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
require_relative "minitext/allowlist_proxy"
|
4
|
+
require_relative "minitext/configuration"
|
5
|
+
require_relative "minitext/message"
|
6
|
+
require_relative "minitext/test_gateway"
|
7
|
+
require_relative "minitext/twilio_gateway"
|
8
|
+
require_relative "minitext/version"
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
module Minitext
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
def self.configuration
|
14
|
+
@configuration ||= Configuration.new
|
14
15
|
end
|
15
16
|
|
16
|
-
def self.
|
17
|
-
|
18
|
-
{gateway: gateway}.merge(@defaults)
|
17
|
+
def self.configure(&block)
|
18
|
+
yield(configuration)
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.
|
22
|
-
|
21
|
+
def self.gateway
|
22
|
+
configuration.gateway
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.text(
|
26
|
-
Message.new(
|
25
|
+
def self.text(**kwargs)
|
26
|
+
Message.new(**configuration.message_defaults.merge(gateway: configuration.gateway).merge(kwargs))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
if defined?(Rails)
|
31
|
-
require 'minitext/railtie'
|
32
|
-
end
|
data/minitext.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/minitext/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "minitext"
|
7
|
+
spec.version = Minitext::VERSION
|
8
|
+
spec.authors = ["Kyle Rippey"]
|
9
|
+
spec.email = ["kylerippey@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = ""
|
12
|
+
spec.description = "A lightweight SMS framework for sending messages via the Twilio API"
|
13
|
+
spec.homepage = "http://github.com/kylerippey/minitext"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "http://github.com/kylerippey/minitext"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.test_files = Dir.glob('test/*_test.rb')
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
spec.add_dependency "twilio-ruby", "~> 6.1"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
data/sig/minitext.rbs
ADDED
metadata
CHANGED
@@ -1,48 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Rippey
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twilio-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '6.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
description: A lightweight SMS framework
|
28
|
-
email:
|
26
|
+
version: '6.1'
|
27
|
+
description: A lightweight SMS framework for sending messages via the Twilio API
|
28
|
+
email:
|
29
|
+
- kylerippey@gmail.com
|
29
30
|
executables: []
|
30
31
|
extensions: []
|
31
32
|
extra_rdoc_files: []
|
32
33
|
files:
|
34
|
+
- ".ruby-version"
|
35
|
+
- CHANGELOG.md
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
33
38
|
- Rakefile
|
34
39
|
- lib/minitext.rb
|
40
|
+
- lib/minitext/allowlist_proxy.rb
|
41
|
+
- lib/minitext/configuration.rb
|
35
42
|
- lib/minitext/message.rb
|
36
|
-
- lib/minitext/missing_parameter.rb
|
37
|
-
- lib/minitext/railtie.rb
|
38
43
|
- lib/minitext/test_gateway.rb
|
39
44
|
- lib/minitext/twilio_gateway.rb
|
40
|
-
- lib/minitext/
|
45
|
+
- lib/minitext/version.rb
|
46
|
+
- minitext.gemspec
|
47
|
+
- sig/minitext.rbs
|
41
48
|
homepage: http://github.com/kylerippey/minitext
|
42
49
|
licenses:
|
43
50
|
- MIT
|
44
|
-
metadata:
|
45
|
-
|
51
|
+
metadata:
|
52
|
+
homepage_uri: http://github.com/kylerippey/minitext
|
53
|
+
source_code_uri: http://github.com/kylerippey/minitext
|
54
|
+
post_install_message:
|
46
55
|
rdoc_options: []
|
47
56
|
require_paths:
|
48
57
|
- lib
|
@@ -50,16 +59,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
59
|
requirements:
|
51
60
|
- - ">="
|
52
61
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
62
|
+
version: 3.0.0
|
54
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
64
|
requirements:
|
56
65
|
- - ">="
|
57
66
|
- !ruby/object:Gem::Version
|
58
67
|
version: '0'
|
59
68
|
requirements: []
|
60
|
-
|
61
|
-
|
62
|
-
signing_key:
|
69
|
+
rubygems_version: 3.4.10
|
70
|
+
signing_key:
|
63
71
|
specification_version: 4
|
64
72
|
summary: ''
|
65
73
|
test_files: []
|
data/lib/minitext/railtie.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'minitext'
|
2
|
-
require 'rails'
|
3
|
-
|
4
|
-
module Minitext
|
5
|
-
class Railtie < Rails::Railtie
|
6
|
-
config.minitext = ActiveSupport::OrderedOptions.new
|
7
|
-
|
8
|
-
initializer "minitext.configure" do |app|
|
9
|
-
Minitext.gateway = app.config.minitext.gateway
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# Usage:
|
15
|
-
# development
|
16
|
-
# config.minitext.gateway = Minitext::TestGateway.new
|
17
|
-
|
18
|
-
# production
|
19
|
-
# config.minitext.gateway = Minitext::TwilioGateway.new(sid: '123', token: 'abc')
|
20
|
-
|
21
|
-
# staging
|
22
|
-
# whitelist = YAML.load_file('twilio_whitelist')
|
23
|
-
# gateway = Minitext::TwilioGateway.new(sid: '123', token: 'abc')
|
24
|
-
# config.minitext.gateway = Minitext::WhitelistProxy.new(whitelist: whitelist, gateway: gateway)
|
25
|
-
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Minitext
|
2
|
-
class WhitelistProxy
|
3
|
-
attr_reader :whitelist, :gateway
|
4
|
-
|
5
|
-
def initialize(params)
|
6
|
-
@whitelist = Array(params.fetch(:whitelist) {Hash.new})
|
7
|
-
@gateway = params.fetch(:gateway) {TestGateway.new}
|
8
|
-
end
|
9
|
-
|
10
|
-
def deliver(message)
|
11
|
-
gateway.deliver(message) if whitelisted?(message.to)
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(method, *args, &block)
|
15
|
-
gateway.send(method, *args, &block)
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
def whitelisted?(recipient)
|
21
|
-
whitelist.include?(recipient)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|