twilito 0.1.0 → 0.3.3

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: 7761e9e3ab42c77312bdb7207896ece722ce001a9a1c099c4a79b702f72c2aba
4
- data.tar.gz: e1e4830cf7ea75dd00f55ffb796bf034128490a2ecbc6e066d8195771e6bf133
3
+ metadata.gz: 3cfb75e4c673aacee3f2e2d4d76bc4106c0129820825918b12f6ccd0c440a2bb
4
+ data.tar.gz: de0d9a0d43911c1db4cd3406aab39a4beb89f6f17d75e02b4dd0c13863c5bd8e
5
5
  SHA512:
6
- metadata.gz: 12b4f5cf4934394c5e4e2f2ff3a9931c42ea6d33ebdd8faa0e7a53f27ee89a6a7a779b2cac9b122264cfbd7358556c974728e7550075db92449b1f873a6b2ba8
7
- data.tar.gz: 7a4e56dfac70088de70c35bd34012573bb87c807461883062ec41a6149716676d2317f3fb849947b8a36b8bafe88251550f0f9d61d083c2840cc2a1ebe24efcc
6
+ metadata.gz: 37fdc8154d808290a9b85c6d55a5a93905882d558203ebdd587148d6a2b9f4661cc5455287a86a3d0739792aee9cabbe58b58eefe150980e13bebcdcb2646479
7
+ data.tar.gz: 607ad6172943a0ddc9d8bdfd9ed51b78e9d3f1f005bb34a6003967b1c6b089013eec8974d48cebd4b699ca7a3ccc6a621fcdb696908d201c6322de5314376fc4
@@ -0,0 +1,20 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: ["2.4", "2.5", "2.6", "2.7", "3.0"]
11
+ name: Run Tests (Ruby ${{ matrix.ruby }})
12
+ steps:
13
+ - uses: actions/checkout@master
14
+ - name: Setup ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ bundler-cache: true
19
+ - name: Run tests
20
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -1,9 +1,10 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /_yardoc/
4
+ /docs/
4
5
  /coverage/
5
- /doc/
6
6
  /pkg/
7
7
  /tmp/
8
8
 
9
- .ruby-version
9
+ .ruby-version
10
+ .DS_Store
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ruby '2.6.1'
3
+ ruby '>= 2.4.0'
4
4
 
5
5
  source "https://rubygems.org"
6
6
 
data/Gemfile.lock CHANGED
@@ -1,29 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twilito (0.1.0)
4
+ twilito (0.3.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  addressable (2.6.0)
10
10
  public_suffix (>= 2.0.2, < 4.0)
11
+ ast (2.4.1)
11
12
  coderay (1.1.2)
12
13
  crack (0.4.3)
13
14
  safe_yaml (~> 1.0.0)
14
15
  hashdiff (0.3.8)
15
16
  method_source (0.9.2)
16
17
  minitest (5.11.3)
18
+ parallel (1.19.2)
19
+ parser (2.7.1.3)
20
+ ast (~> 2.4.0)
17
21
  pry (0.12.2)
18
22
  coderay (~> 1.1.0)
19
23
  method_source (~> 0.9.0)
20
24
  public_suffix (3.0.3)
21
- rake (10.5.0)
25
+ rainbow (3.0.0)
26
+ rake (13.0.1)
27
+ regexp_parser (1.7.1)
28
+ rexml (3.2.4)
29
+ rubocop (0.85.1)
30
+ parallel (~> 1.10)
31
+ parser (>= 2.7.0.1)
32
+ rainbow (>= 2.2.2, < 4.0)
33
+ regexp_parser (>= 1.7)
34
+ rexml
35
+ rubocop-ast (>= 0.0.3)
36
+ ruby-progressbar (~> 1.7)
37
+ unicode-display_width (>= 1.4.0, < 2.0)
38
+ rubocop-ast (0.0.3)
39
+ parser (>= 2.7.0.1)
40
+ ruby-progressbar (1.10.1)
22
41
  safe_yaml (1.0.5)
42
+ unicode-display_width (1.7.0)
23
43
  webmock (3.5.1)
24
44
  addressable (>= 2.3.6)
25
45
  crack (>= 0.3.2)
26
46
  hashdiff
47
+ yard (0.9.25)
27
48
 
28
49
  PLATFORMS
29
50
  ruby
@@ -32,12 +53,14 @@ DEPENDENCIES
32
53
  bundler (~> 2.0)
33
54
  minitest (~> 5.11)
34
55
  pry
35
- rake (~> 10.0)
56
+ rake (~> 13.0)
57
+ rubocop
36
58
  twilito!
37
59
  webmock (~> 3)
60
+ yard (~> 0.9)
38
61
 
39
62
  RUBY VERSION
40
- ruby 2.6.1p33
63
+ ruby 2.7.2p137
41
64
 
42
65
  BUNDLED WITH
43
- 2.0.1
66
+ 2.2.14
data/README.md CHANGED
@@ -1,19 +1,23 @@
1
1
  # Twilito
2
2
 
3
- [![Build Status](https://travis-ci.org/alexford/twilito.svg?branch=master)](https://travis-ci.org/alexford/twilito)
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
- A tiny, zero dependency helper for sending text messages with Twilio
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
 
7
7
  ## Why
8
8
 
9
- Twilio's full on Ruby library does a lot, and has a large memory footprint—too large for just sending an SMS. It's also more difficult to mock and verify than I'd like for a simple task like sending an individual SMS.
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 is just enough of a wrapper to abstract away the REST API without loading the rest of the Twilio ecosystem.
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
 
19
+ Twilito should work on Ruby 2.4 and up.
20
+
17
21
  #### Install the gem
18
22
 
19
23
  ```
@@ -23,16 +27,17 @@ gem 'twilito'
23
27
  #### Simplest case
24
28
 
25
29
  ```ruby
26
- # All options are required (but can be defaulted, see below)
30
+ # All of these arguments are required, but can be defaulted (see below)
27
31
  result = Twilito.send_sms(
28
32
  to: '+15555555555',
29
33
  from: '+15554444444',
30
- content: 'This is my content'
34
+ content: 'This is my content',
31
35
  account_sid: '...', # Twilio Credentials
32
36
  auth_token: '...'
33
37
  )
34
38
 
35
- # Returns Twilito::Result struct
39
+
40
+ # Returns instance of Twilito::Result
36
41
 
37
42
  result.success? # => boolean
38
43
  result.errors # => [] or error messages
@@ -41,7 +46,7 @@ result.response # => Raw response (instance of Net::HTTPResponse)
41
46
  result.data # => Hash of response data (parsed from JSON)
42
47
  ```
43
48
 
44
- #### Use send! to raise on error instead
49
+ #### Use send_sms! to raise on error instead
45
50
 
46
51
  ```ruby
47
52
  begin
@@ -78,26 +83,34 @@ end
78
83
  Twilito.send_sms!(to: '+15555555555', body: 'Foo')
79
84
  ```
80
85
 
81
- #### Really, everything
86
+ **Everything can be defaulted, including the message body, so that a bare `Twilio.send_sms!` can work in your code**
87
+
88
+ #### Sending MMS
82
89
 
83
90
  ```ruby
84
- # In an initializer or something like that:
91
+ # Use the optional media_url argument, which is sent
92
+ # to Twilio as MediaUrl
85
93
 
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']
94
+ result = Twilito.send_sms(
95
+ to: '+15555555555',
96
+ content: 'This is my content',
97
+ media_url: 'https://example.com/image.png',
98
+ )
90
99
 
91
- config.from = '+16145555555'
92
- config.to = '+15555555555'
93
- config.body = 'A new user signed up'
94
- end
95
100
  ```
96
101
 
102
+ #### Set the optional `callback_url` argument if you want to receive HTTP callbacks from Twilio
103
+
97
104
  ```ruby
98
- # Later, in your code:
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
+ )
99
113
 
100
- Twilito.send_sms!
101
114
  ```
102
115
 
103
116
  ## Testing your code
@@ -106,4 +119,23 @@ _TODO: Add examples of mocking and/or test helpers for asserting your code sends
106
119
 
107
120
  ## Contributing
108
121
 
109
- _TODO_
122
+ ### Contribute Feedback, Ideas, and Bug Reports
123
+
124
+ - Create or comment on an issue
125
+
126
+ ### Contribute Code
127
+
128
+ - Find an open issue or create one
129
+ - Fork this repo and open a PR
130
+ - Write unit tests for your change
131
+
132
+ ### Contribute Docs
133
+
134
+ - Open a PR to make the README better, or help with contribution guidelines, etc.
135
+ - There is currently an open issue for adding RDoc/YARD documentation
136
+
137
+ ### Contribute Beer
138
+
139
+ Did Twilito save you some RAM?
140
+
141
+ <a href="https://www.buymeacoffee.com/alexford" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/lato-white.png" alt="Buy Me A Beer" height="51" width="217" style="height: 51px !important;width: 217px !important;" ></a>
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
+ require 'yard'
5
6
 
6
7
  Rake::TestTask.new(:test) do |t|
7
8
  t.libs << "test"
@@ -10,3 +11,8 @@ Rake::TestTask.new(:test) do |t|
10
11
  end
11
12
 
12
13
  task default: :test
14
+
15
+ YARD::Rake::YardocTask.new do |t|
16
+ t.files = ['lib/**/*.rb'] # optional
17
+ t.options = ['-odocs'] # optional
18
+ end
data/lib/twilito.rb CHANGED
@@ -13,7 +13,7 @@ module Twilito
13
13
  include API
14
14
 
15
15
  def send_sms(**args)
16
- response = send_sms!(args)
16
+ response = send_sms!(**args)
17
17
  Result.success(
18
18
  response: response,
19
19
  sid: JSON.parse(response.read_body)['sid']
@@ -28,21 +28,17 @@ module Twilito
28
28
  args = merge_configuration(args)
29
29
 
30
30
  send_response(args).tap do |response|
31
- unless response.is_a? Net::HTTPSuccess
32
- raise SendError.new('Error from Twilio API', response)
33
- end
31
+ raise SendError.new('Error from Twilio API', response) unless response.is_a? Net::HTTPSuccess
34
32
  end
35
33
  end
36
34
 
37
35
  private
38
36
 
39
- def merge_configuration(**args)
37
+ def merge_configuration(args)
40
38
  configuration.to_h.merge(args).tap do |merged|
41
39
  missing_keys = merged.select { |_k, v| v.nil? }.keys
42
40
 
43
- if missing_keys.any?
44
- raise ArgumentError, "Missing argument(s): #{missing_keys.join(', ')}"
45
- end
41
+ raise ArgumentError, "Missing argument(s): #{missing_keys.join(', ')}" if missing_keys.any?
46
42
  end
47
43
  end
48
44
  end
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' => user_agent)
10
11
  req.basic_auth(args[:account_sid], args[:auth_token])
11
12
  req.set_form_data(twilio_params(args))
12
13
 
@@ -34,8 +35,14 @@ module Twilito
34
35
  {
35
36
  'To' => args[:to],
36
37
  'From' => args[:from],
37
- 'Body' => args[:body]
38
- }
38
+ 'Body' => args[:body],
39
+ 'MediaUrl' => args[:media_url],
40
+ 'StatusCallback' => args[:status_callback]
41
+ }.compact
42
+ end
43
+
44
+ def user_agent
45
+ "Ruby Twilito/#{Twilito::VERSION}"
39
46
  end
40
47
  end
41
48
  end
@@ -1,29 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twilito
4
- Result = Struct.new(:success?, :errors, :sid, :response, keyword_init: true) do
5
- def self.success(**args)
6
- new(success?: true, **args)
4
+ class Result
5
+ attr_reader :success, :errors, :sid, :response
6
+
7
+ def initialize(success:, errors: [], sid: nil, response: nil)
8
+ @success = success
9
+ @errors = errors
10
+ @sid = sid
11
+ @response = response
7
12
  end
8
13
 
9
- def self.failure(**args)
10
- new(success?: false, **args)
14
+ def self.success(response:, sid:)
15
+ new(success: true, response: response, sid: sid)
11
16
  end
12
17
 
13
- def errors
14
- to_h[:errors] || []
18
+ def self.failure(response:, errors:)
19
+ new(success: false, response: response, errors: errors)
15
20
  end
16
21
 
17
22
  def data
18
23
  JSON.parse(response_body || '{}')
19
24
  end
20
25
 
26
+ def success?
27
+ success || false
28
+ end
29
+
21
30
  private
22
31
 
23
32
  def response_body
24
- return nil unless to_h[:response]&.respond_to?(:read_body)
33
+ return nil unless response&.respond_to?(:read_body)
25
34
 
26
- to_h[:response].read_body
35
+ response.read_body
27
36
  end
28
37
  end
29
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twilito
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.3"
5
5
  end
data/twilito.gemspec CHANGED
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.licenses = ['MIT']
10
10
  spec.version = Twilito::VERSION
11
11
  spec.authors = ["Alex Ford"]
12
- spec.email = ["alexford87@me.com"]
12
+ spec.email = ["alexford@hey.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"
@@ -24,6 +25,8 @@ Gem::Specification.new do |spec|
24
25
  spec.add_development_dependency "bundler", "~> 2.0"
25
26
  spec.add_development_dependency "minitest", "~> 5.11"
26
27
  spec.add_development_dependency "pry"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
+ spec.add_development_dependency "rubocop"
28
30
  spec.add_development_dependency "webmock", "~> 3"
31
+ spec.add_development_dependency "yard", "~> 0.9"
29
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.1.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Ford
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-27 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: webmock
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,13 +94,28 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '3'
83
- description:
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ description:
84
112
  email:
85
- - alexford87@me.com
113
+ - alexford@hey.com
86
114
  executables: []
87
115
  extensions: []
88
116
  extra_rdoc_files: []
89
117
  files:
118
+ - ".github/workflows/main.yml"
90
119
  - ".gitignore"
91
120
  - ".rubocop.yml"
92
121
  - ".travis.yml"
@@ -108,7 +137,7 @@ homepage: https://github.com/alexford/twilito
108
137
  licenses:
109
138
  - MIT
110
139
  metadata: {}
111
- post_install_message:
140
+ post_install_message:
112
141
  rdoc_options: []
113
142
  require_paths:
114
143
  - lib
@@ -116,15 +145,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
145
  requirements:
117
146
  - - ">="
118
147
  - !ruby/object:Gem::Version
119
- version: '0'
148
+ version: 2.4.0
120
149
  required_rubygems_version: !ruby/object:Gem::Requirement
121
150
  requirements:
122
151
  - - ">="
123
152
  - !ruby/object:Gem::Version
124
153
  version: '0'
125
154
  requirements: []
126
- rubygems_version: 3.0.1
127
- signing_key:
155
+ rubygems_version: 3.1.4
156
+ signing_key:
128
157
  specification_version: 4
129
158
  summary: A tiny, zero dependency, and easy to test helper for sending text messages
130
159
  with Twilio