twilito 0.1.0 → 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 +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +8 -26
- data/lib/twilito/api.rb +1 -0
- data/lib/twilito/result.rb +11 -7
- data/lib/twilito/version.rb +1 -1
- data/twilito.gemspec +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 319e2e7600c3634e97209ebeec8cde162d5dbae23d4f42854d9dd744babe6f05
|
4
|
+
data.tar.gz: 730b25f694951541de4a93a22f658e2dc9c3ea29d1604ad16a1a9a0602887a75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 784f7d0f2e7b19510da416817bcd807af73b05d3cb894233316d449490f74c5d5a6a6302a4f03294cd6a80cf8d17f22088003c629ae2c898d2a8426c9925ac48
|
7
|
+
data.tar.gz: a2e9efd049e3cedf04a3a83ac9ce0d6337b88a3bbb861858ff10b432445bf240b4de0b037fbd9c426d93dcd61fb6d22f46b9989877fea06600a4bbd181e52346
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/alexford/twilito)
|
4
4
|
|
5
|
-
A tiny, zero dependency helper for sending text messages with Twilio
|
5
|
+
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.
|
6
6
|
|
7
7
|
## Why
|
8
8
|
|
9
|
-
Twilio's full
|
9
|
+
Twilio's [full Ruby library](https://github.com/twilio/twilio-ruby) does a *lot*, and has a large memory footprint to go with it—too large for just sending a message. It's also more difficult to mock and verify in tests than I'd like.
|
10
10
|
|
11
|
-
Using Twilio's REST API directly is fine, but can be cumbersome.
|
11
|
+
Using [Twilio's REST API](https://www.twilio.com/docs/usage/api) directly is fine, but can be cumbersome.
|
12
12
|
|
13
|
-
Twilito
|
13
|
+
You should consider using Twilito if the only thing you need to do is send text messages and you don't want to worry about making HTTP requests to Twilio yourself.
|
14
|
+
|
15
|
+
If you use more of Twilio, consider [twilio-ruby](https://github.com/twilio/twilio-ruby) or interact with the REST API in another way.
|
14
16
|
|
15
17
|
## Usage
|
16
18
|
|
@@ -41,7 +43,7 @@ result.response # => Raw response (instance of Net::HTTPResponse)
|
|
41
43
|
result.data # => Hash of response data (parsed from JSON)
|
42
44
|
```
|
43
45
|
|
44
|
-
#### Use
|
46
|
+
#### Use send_sms! to raise on error instead
|
45
47
|
|
46
48
|
```ruby
|
47
49
|
begin
|
@@ -78,27 +80,7 @@ end
|
|
78
80
|
Twilito.send_sms!(to: '+15555555555', body: 'Foo')
|
79
81
|
```
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
```ruby
|
84
|
-
# In an initializer or something like that:
|
85
|
-
|
86
|
-
Twilito.configure do |config|
|
87
|
-
# Store your secrets elsewhere
|
88
|
-
config.account_sid = ENV['TWILIO_ACCOUNT_SID']
|
89
|
-
config.auth_token = ENV['TWILIO_AUTH_TOKEN']
|
90
|
-
|
91
|
-
config.from = '+16145555555'
|
92
|
-
config.to = '+15555555555'
|
93
|
-
config.body = 'A new user signed up'
|
94
|
-
end
|
95
|
-
```
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
# Later, in your code:
|
99
|
-
|
100
|
-
Twilito.send_sms!
|
101
|
-
```
|
83
|
+
**Everything can be defaulted, including the message body, so that a bare `Twilio.send_sms!` can work in your code**
|
102
84
|
|
103
85
|
## Testing your code
|
104
86
|
|
data/lib/twilito/api.rb
CHANGED
@@ -7,6 +7,7 @@ module Twilito
|
|
7
7
|
|
8
8
|
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
9
9
|
req = Net::HTTP::Post.new(uri)
|
10
|
+
req.initialize_http_header({ 'User-Agent' => "Ruby Twilito/#{Twilito::VERSION}" })
|
10
11
|
req.basic_auth(args[:account_sid], args[:auth_token])
|
11
12
|
req.set_form_data(twilio_params(args))
|
12
13
|
|
data/lib/twilito/result.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Twilito
|
4
|
-
Result = Struct.new(:success
|
5
|
-
def
|
6
|
-
|
4
|
+
Result = Struct.new(:success, :errors, :sid, :response) do
|
5
|
+
def initialize(success:, errors: [], sid: nil, response: nil)
|
6
|
+
super(success, errors, sid, response)
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.
|
10
|
-
new(success
|
9
|
+
def self.success(**args)
|
10
|
+
new(success: true, **args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def self.failure(**args)
|
14
|
+
new(success: false, **args)
|
15
15
|
end
|
16
16
|
|
17
17
|
def data
|
18
18
|
JSON.parse(response_body || '{}')
|
19
19
|
end
|
20
20
|
|
21
|
+
def success?
|
22
|
+
to_h[:success] || false
|
23
|
+
end
|
24
|
+
|
21
25
|
private
|
22
26
|
|
23
27
|
def response_body
|
data/lib/twilito/version.rb
CHANGED
data/twilito.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.version = Twilito::VERSION
|
11
11
|
spec.authors = ["Alex Ford"]
|
12
12
|
spec.email = ["alexford87@me.com"]
|
13
|
+
spec.required_ruby_version = '>= 2.4.0'
|
13
14
|
|
14
15
|
spec.summary = "A tiny, zero dependency, and easy to test helper for sending text messages with Twilio"
|
15
16
|
spec.homepage = "https://github.com/alexford/twilito"
|
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.2.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: 2019-
|
11
|
+
date: 2019-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,14 +116,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
requirements:
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
119
|
+
version: 2.4.0
|
120
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.0.
|
126
|
+
rubygems_version: 3.0.3
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: A tiny, zero dependency, and easy to test helper for sending text messages
|