twilito 0.3.3 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cfb75e4c673aacee3f2e2d4d76bc4106c0129820825918b12f6ccd0c440a2bb
4
- data.tar.gz: de0d9a0d43911c1db4cd3406aab39a4beb89f6f17d75e02b4dd0c13863c5bd8e
3
+ metadata.gz: 7735e0e748d2013a87e0184c5d6c233f3bf0c90ede19b62c6674e96b3f592d18
4
+ data.tar.gz: 1ec6957aa7b4efa692ab07716595debff865c11c54267befdee64d4cd84596a4
5
5
  SHA512:
6
- metadata.gz: 37fdc8154d808290a9b85c6d55a5a93905882d558203ebdd587148d6a2b9f4661cc5455287a86a3d0739792aee9cabbe58b58eefe150980e13bebcdcb2646479
7
- data.tar.gz: 607ad6172943a0ddc9d8bdfd9ed51b78e9d3f1f005bb34a6003967b1c6b089013eec8974d48cebd4b699ca7a3ccc6a621fcdb696908d201c6322de5314376fc4
6
+ metadata.gz: e91c012d2b04d4003d49344f6cf288c5e590ffe5ab3e531b277252ae823d1a1dabf8522133869f09c3ad4ae2627cf9376dc9e14e5624fc26bb359945a64a6e97
7
+ data.tar.gz: 024b225407ef5e759703186b13b9919a9c449363642b5bde09b4a6074251213f7a81092c3c806b430f5dbf49d935601ff6e52076a4fce53e34c4a605b93e0989
@@ -7,7 +7,7 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby: ["2.4", "2.5", "2.6", "2.7", "3.0"]
10
+ ruby: ["3.0", "3.1", "3.2"]
11
11
  name: Run Tests (Ruby ${{ matrix.ruby }})
12
12
  steps:
13
13
  - uses: actions/checkout@master
data/.rubocop.yml CHANGED
@@ -2,6 +2,8 @@ AllCops:
2
2
  Exclude:
3
3
  - "bin/**/*"
4
4
  - "twilito.gemspec"
5
+ AllCops:
6
+ TargetRubyVersion: 3.2
5
7
 
6
8
  Metrics/BlockLength:
7
9
  Exclude:
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ruby '>= 2.4.0'
3
+ ruby '>= 3.0.0'
4
4
 
5
5
  source "https://rubygems.org"
6
6
 
data/Gemfile.lock CHANGED
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twilito (0.3.3)
4
+ twilito (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- addressable (2.6.0)
10
- public_suffix (>= 2.0.2, < 4.0)
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
11
  ast (2.4.1)
12
- coderay (1.1.2)
13
- crack (0.4.3)
14
- safe_yaml (~> 1.0.0)
15
- hashdiff (0.3.8)
16
- method_source (0.9.2)
12
+ coderay (1.1.3)
13
+ crack (0.4.5)
14
+ rexml
15
+ hashdiff (1.0.1)
16
+ method_source (1.0.0)
17
17
  minitest (5.11.3)
18
18
  parallel (1.19.2)
19
19
  parser (2.7.1.3)
20
20
  ast (~> 2.4.0)
21
- pry (0.12.2)
22
- coderay (~> 1.1.0)
23
- method_source (~> 0.9.0)
24
- public_suffix (3.0.3)
21
+ pry (0.14.2)
22
+ coderay (~> 1.1)
23
+ method_source (~> 1.0)
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.5.1)
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
@@ -52,15 +51,15 @@ PLATFORMS
52
51
  DEPENDENCIES
53
52
  bundler (~> 2.0)
54
53
  minitest (~> 5.11)
55
- pry
54
+ pry (~> 0.14)
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
- ruby 2.7.2p137
62
+ ruby 3.2.2p53
64
63
 
65
64
  BUNDLED WITH
66
- 2.2.14
65
+ 2.4.19
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. Just enough of a wrapper to abstract away Twilio's REST API for sending messages, without _anything_ else.
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 is designed for currently maintained Ruby versions. (3.0 and up as of 8/2023). Unit tests [run in CI](https://github.com/alexford/twilito/actions) on 3.0, 3.1, and 3.2
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 defaulted (see below)
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
- from: '+15554444444',
34
- content: 'This is my content',
33
+ from: '+15554444444', # or 'messaging_service_sid'
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
- #### Every argument can be defaulted
66
+ ### Configuring Defaults For Required Arguments
67
+
68
+ The five required arguments (`to`, `from` (or `messaging_service_sid`), `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
- **Everything can be defaulted, including the message body, so that a bare `Twilio.send_sms!` can work in your code**
88
+ ### Using Other, Optional (Arbitrary) Arguments
87
89
 
88
- #### Sending MMS
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
- # Use the optional media_url argument, which is sent
92
- # to Twilio as MediaUrl
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
- content: 'This is my content',
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(twilio_params(args))
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
- def twilio_params(args)
35
- {
36
- 'To' => args[:to],
37
- 'From' => args[:from],
38
- 'Body' => args[:body],
39
- 'MediaUrl' => args[:media_url],
40
- 'StatusCallback' => args[:status_callback]
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
@@ -15,7 +15,7 @@ module Twilito
15
15
 
16
16
  class Configuration
17
17
  attr_accessor :account_sid, :auth_token, :from, :to, :body,
18
- :twilio_host, :twilio_version
18
+ :twilio_host, :twilio_version, :messaging_service_sid
19
19
 
20
20
  TWILIO_HOST = 'api.twilio.com'
21
21
  TWILIO_VERSION = '2010-04-01'
@@ -24,6 +24,7 @@ module Twilito
24
24
  {
25
25
  to: to,
26
26
  from: from,
27
+ messaging_service_sid: messaging_service_sid,
27
28
  body: body,
28
29
  account_sid: account_sid,
29
30
  auth_token: auth_token
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twilito
4
- VERSION = "0.3.3"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/twilito.rb CHANGED
@@ -38,6 +38,13 @@ module Twilito
38
38
  configuration.to_h.merge(args).tap do |merged|
39
39
  missing_keys = merged.select { |_k, v| v.nil? }.keys
40
40
 
41
+ # Only one of :from or :messaging_service_sid must be set
42
+ missing_keys = [] if (missing_keys == [:from]) || (missing_keys == [:messaging_service_sid])
43
+ missing_keys = missing_keys.map do |key|
44
+ key == :from ? "from (or messaging_service_sid)" : key
45
+ end
46
+ missing_keys.delete(:messaging_service_sid)
47
+
41
48
  raise ArgumentError, "Missing argument(s): #{missing_keys.join(', ')}" if missing_keys.any?
42
49
  end
43
50
  end
data/twilito.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.version = Twilito::VERSION
11
11
  spec.authors = ["Alex Ford"]
12
12
  spec.email = ["alexford@hey.com"]
13
- spec.required_ruby_version = '>= 2.4.0'
13
+ spec.required_ruby_version = '>= 3.0'
14
14
 
15
15
  spec.summary = "A tiny, zero dependency, and easy to test helper for sending text messages with Twilio"
16
16
  spec.homepage = "https://github.com/alexford/twilito"
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 2.0"
26
26
  spec.add_development_dependency "minitest", "~> 5.11"
27
- spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "pry", "~> 0.14"
28
28
  spec.add_development_dependency "rake", "~> 13.0"
29
- spec.add_development_dependency "rubocop"
30
- spec.add_development_dependency "webmock", "~> 3"
29
+ spec.add_development_dependency "rubocop", "~> 0.85"
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.3.3
4
+ version: 0.5.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-03-12 00:00:00.000000000 Z
11
+ date: 2023-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.14'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '0.14'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,30 +70,30 @@ dependencies:
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '0.85'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '0.85'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
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
@@ -145,14 +145,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
146
  - - ">="
147
147
  - !ruby/object:Gem::Version
148
- version: 2.4.0
148
+ version: '3.0'
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  requirements:
151
151
  - - ">="
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.1.4
155
+ rubygems_version: 3.4.10
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