twilito 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -11
- data/README.md +15 -26
- data/lib/twilito/api.rb +8 -9
- data/lib/twilito/version.rb +1 -1
- data/twilito.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac55859f2c24ea8da46a22d84d2b34473c586280bd4f2541d70fdbe5de044229
|
4
|
+
data.tar.gz: 9301076c59a7372e51870b2b65c33fe793e3163333f6925e67646d8dd1f0c497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8528c27bcf15dffa8a1e844fd80cd5e648102ca6c7e20afb3af00edbbe7193ba23ff86f367771f901f4e92198ba1304afa730f757cb27964178b68cb3dd524b
|
7
|
+
data.tar.gz: 9edd9bc5e5c52a872db0a4e45e0eba6b04a5fba0de98ef615ca2c1a5c8dbb5abf01f772cb6760a7c3e363cbfa98a6e9129a13f67a366bad746a0f57e7f09135c
|
data/Gemfile.lock
CHANGED
@@ -6,13 +6,13 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
addressable (2.
|
10
|
-
public_suffix (>= 2.0.2, <
|
9
|
+
addressable (2.7.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
11
|
ast (2.4.1)
|
12
12
|
coderay (1.1.2)
|
13
|
-
crack (0.4.
|
14
|
-
|
15
|
-
hashdiff (0.
|
13
|
+
crack (0.4.5)
|
14
|
+
rexml
|
15
|
+
hashdiff (1.0.1)
|
16
16
|
method_source (0.9.2)
|
17
17
|
minitest (5.11.3)
|
18
18
|
parallel (1.19.2)
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
pry (0.12.2)
|
22
22
|
coderay (~> 1.1.0)
|
23
23
|
method_source (~> 0.9.0)
|
24
|
-
public_suffix (
|
24
|
+
public_suffix (4.0.6)
|
25
25
|
rainbow (3.0.0)
|
26
26
|
rake (13.0.1)
|
27
27
|
regexp_parser (1.7.1)
|
@@ -38,12 +38,11 @@ GEM
|
|
38
38
|
rubocop-ast (0.0.3)
|
39
39
|
parser (>= 2.7.0.1)
|
40
40
|
ruby-progressbar (1.10.1)
|
41
|
-
safe_yaml (1.0.5)
|
42
41
|
unicode-display_width (1.7.0)
|
43
|
-
webmock (3.
|
42
|
+
webmock (3.12.2)
|
44
43
|
addressable (>= 2.3.6)
|
45
44
|
crack (>= 0.3.2)
|
46
|
-
hashdiff
|
45
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
47
46
|
yard (0.9.25)
|
48
47
|
|
49
48
|
PLATFORMS
|
@@ -56,11 +55,11 @@ DEPENDENCIES
|
|
56
55
|
rake (~> 13.0)
|
57
56
|
rubocop
|
58
57
|
twilito!
|
59
|
-
webmock (~> 3)
|
58
|
+
webmock (~> 3.12)
|
60
59
|
yard (~> 0.9)
|
61
60
|
|
62
61
|
RUBY VERSION
|
63
62
|
ruby 2.7.2p137
|
64
63
|
|
65
64
|
BUNDLED WITH
|
66
|
-
2.2.
|
65
|
+
2.2.15
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Twilito
|
2
2
|
|
3
|
-
A tiny, zero dependency helper for sending text messages with Twilio.
|
3
|
+
A tiny, zero dependency helper for sending text messages with Twilio. _Just enough_ of a wrapper to abstract away Twilio's REST API for sending messages, without _anything_ else.
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/twilito.svg)](https://badge.fury.io/rb/twilito) [![Actions Status](https://github.com/alexford/twilito/workflows/CI/badge.svg)](https://github.com/alexford/twilito/actions)
|
6
6
|
|
@@ -16,7 +16,7 @@ If you use more of Twilio, consider [twilio-ruby](https://github.com/twilio/twil
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
Twilito should work on Ruby 2.4 and up.
|
19
|
+
Twilito should work on Ruby 2.4 and up. Unit tests [run in CI](https://github.com/alexford/twilito/actions) on 2.4, 2.5, 2.6, 2.7, and 3.0.
|
20
20
|
|
21
21
|
#### Install the gem
|
22
22
|
|
@@ -27,11 +27,11 @@ gem 'twilito'
|
|
27
27
|
#### Simplest case
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
# All of these arguments are required, but can be
|
30
|
+
# All of these arguments are required, but can be configured as defaults (see below)
|
31
31
|
result = Twilito.send_sms(
|
32
32
|
to: '+15555555555',
|
33
33
|
from: '+15554444444',
|
34
|
-
|
34
|
+
body: 'This is my content',
|
35
35
|
account_sid: '...', # Twilio Credentials
|
36
36
|
auth_token: '...'
|
37
37
|
)
|
@@ -63,7 +63,9 @@ rescue Twilito::SendError => e
|
|
63
63
|
end
|
64
64
|
```
|
65
65
|
|
66
|
-
|
66
|
+
### Configuring Defaults For Required Arguments
|
67
|
+
|
68
|
+
The five required arguments (`to`, `from`, `body`, `account_sid`, and `auth_token`) can be configured as defaults with `Twilito.configure`.
|
67
69
|
|
68
70
|
```ruby
|
69
71
|
# In an initializer or something like that:
|
@@ -83,34 +85,21 @@ end
|
|
83
85
|
Twilito.send_sms!(to: '+15555555555', body: 'Foo')
|
84
86
|
```
|
85
87
|
|
86
|
-
|
88
|
+
### Using Other, Optional (Arbitrary) Arguments
|
87
89
|
|
88
|
-
|
90
|
+
There are a number of optional parameters defined by Twilio for sending a message (see [the API documentation](https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource)). Any of these can be sent with Twilito using the "Ruby-style" snake cased equivalent of the parameter.
|
89
91
|
|
90
92
|
```ruby
|
91
|
-
#
|
92
|
-
#
|
93
|
+
# Twilito sends arbitrary arguments to Twilio's API after CamelCasing keys to match Twilio's style.
|
94
|
+
# NOTE: This example assumes auth_token, account_sid, and from have already been configured.
|
93
95
|
|
94
96
|
result = Twilito.send_sms(
|
95
97
|
to: '+15555555555',
|
96
|
-
|
97
|
-
media_url: 'https://example.com/image.png',
|
98
|
+
body: 'This is my content',
|
99
|
+
media_url: 'https://example.com/image.png', # MediaUrl
|
100
|
+
status_callback: 'https://your.app.io/sms/callback', # StatusCallback
|
101
|
+
smart_encoded: true # SmartEncoded
|
98
102
|
)
|
99
|
-
|
100
|
-
```
|
101
|
-
|
102
|
-
#### Set the optional `callback_url` argument if you want to receive HTTP callbacks from Twilio
|
103
|
-
|
104
|
-
```ruby
|
105
|
-
# Use the optional media_url argument, which is sent
|
106
|
-
# to Twilio as MediaUrl
|
107
|
-
|
108
|
-
result = Twilito.send_sms(
|
109
|
-
to: '+15555555555',
|
110
|
-
content: 'This is my content',
|
111
|
-
status_callback: 'https://your.app.io/sms/callback',
|
112
|
-
)
|
113
|
-
|
114
103
|
```
|
115
104
|
|
116
105
|
## Testing your code
|
data/lib/twilito/api.rb
CHANGED
@@ -9,7 +9,7 @@ module Twilito
|
|
9
9
|
req = Net::HTTP::Post.new(uri)
|
10
10
|
req.initialize_http_header('User-Agent' => user_agent)
|
11
11
|
req.basic_auth(args[:account_sid], args[:auth_token])
|
12
|
-
req.set_form_data(
|
12
|
+
req.set_form_data(twilio_form_data(args))
|
13
13
|
|
14
14
|
http.request(req)
|
15
15
|
end
|
@@ -31,14 +31,13 @@ module Twilito
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
'
|
41
|
-
}.compact
|
34
|
+
# NOTE: Converts snake_cased hash of arguments to CamelCase to match Twilio
|
35
|
+
# API expectations. Also, removes auth_token and account_sid as those are
|
36
|
+
# included separately in .send_response as basic auth instead of POST body
|
37
|
+
def twilio_form_data(args)
|
38
|
+
args
|
39
|
+
.merge(auth_token: nil, account_sid: nil).compact
|
40
|
+
.reduce({}) { |result, (k, v)| result.merge(k.to_s.split('_').collect(&:capitalize).join => v) }
|
42
41
|
end
|
43
42
|
|
44
43
|
def user_agent
|
data/lib/twilito/version.rb
CHANGED
data/twilito.gemspec
CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "pry"
|
28
28
|
spec.add_development_dependency "rake", "~> 13.0"
|
29
29
|
spec.add_development_dependency "rubocop"
|
30
|
-
spec.add_development_dependency "webmock", "~> 3"
|
30
|
+
spec.add_development_dependency "webmock", "~> 3.12"
|
31
31
|
spec.add_development_dependency "yard", "~> 0.9"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twilito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3'
|
89
|
+
version: '3.12'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3'
|
96
|
+
version: '3.12'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: yard
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
|
-
rubygems_version: 3.
|
155
|
+
rubygems_version: 3.0.3
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: A tiny, zero dependency, and easy to test helper for sending text messages
|