Skip to content

Commit 1956b94

Browse files
shrutiburmansbansla
authored andcommitted
feat!: Merge branch '6.x.x-rc' to main (#651)
1 parent 0146307 commit 1956b94

File tree

1,111 files changed

+181689
-267769
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,111 files changed

+181689
-267769
lines changed

.github/workflows/test-and-deploy.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
timeout-minutes: 20
1818
strategy:
1919
matrix:
20-
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', 'ruby-head', 'jruby-9.2' ]
20+
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', 'ruby-head', 'jruby-9.2', 'jruby-9.3', 'jruby-9.4' ]
2121
steps:
2222
- name: Checkout twilio-ruby
2323
uses: actions/checkout@v3
@@ -45,6 +45,16 @@ jobs:
4545
- name: Run Unit Tests
4646
run: make test
4747

48+
- name: Run Cluster Test
49+
if: (!github.event.pull_request.head.repo.fork)
50+
env:
51+
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
52+
TWILIO_API_KEY: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY}}
53+
TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }}
54+
TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }}
55+
TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }}
56+
run: make cluster-test
57+
4858
- name: Fix code coverage paths
4959
if: ${{ (github.event_name == 'pull_request' || github.ref_type == 'branch') && matrix.ruby == '3.0' && !github.event.pull_request.head.repo.fork }}
5060
working-directory: ./coverage

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ docs/_build
1414
.bundle
1515
.rakeTasks
1616
.yardoc
17+
.openapi-generator*
18+
.idea/
19+
1720

1821
coverage

CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
twilio-ruby changelog
2-
=====================
2+
=====================
33

44
[2023-04-19] Version 5.77.0
55
---------------------------

CONTRIBUTING.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ This code was generated by
3737
/ /
3838
"""
3939
```
40+
or
41+
```
42+
* This code was generated by
43+
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
44+
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
45+
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
46+
*
47+
```
4048
then it is a generated file and the change will need to be made by us, but
4149
submitting an issue will help us track it and keep you up-to-date. If the file
4250
isn't generated, you can help us out even more by submitting a Pull Request with
@@ -152,4 +160,4 @@ you are working:
152160
* All classes and methods **must be documented**.
153161
154162
[issue-link]: https://github.com/twilio/twilio-ruby/issues/new
155-
[github]: https://github.com/twilio/twilio-ruby
163+
[github]: https://github.com/twilio/twilio-ruby

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ docker-push:
3232
docker push twilio/twilio-ruby:${GITHUB_TAG}
3333
docker push twilio/twilio-ruby:apidefs-${API_DEFINITIONS_SHA}
3434
docker push twilio/twilio-ruby:${CURRENT_TAG}
35+
36+
cluster-test:
37+
bundle exec rspec ./cluster_spec.rb

README.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ The individual releases [here][refdocs].
1818

1919
This library supports the following Ruby implementations:
2020

21-
- Ruby 2.4
22-
- Ruby 2.5
23-
- Ruby 2.6
24-
- Ruby 2.7
25-
- Ruby 3.0
26-
- Ruby 3.1
21+
* Ruby 2.4
22+
* Ruby 2.5
23+
* Ruby 2.6
24+
* Ruby 2.7
25+
* Ruby 3.0
26+
* Ruby 3.1
27+
* Ruby 3.2
2728

28-
### Migrating from 4.x
29+
* JRuby 9.2
30+
* JRuby 9.3
31+
* JRuby 9.4
32+
33+
### Migrating from 5.x
2934

3035
[Upgrade Guide][upgrade]
3136

@@ -34,13 +39,13 @@ This library supports the following Ruby implementations:
3439
To install using [Bundler][bundler] grab the latest stable version:
3540

3641
```ruby
37-
gem 'twilio-ruby', '~> 5.77.0'
42+
gem 'twilio-ruby', '~> 6.0.0'
3843
```
3944

4045
To manually install `twilio-ruby` via [Rubygems][rubygems] simply gem install:
4146

4247
```bash
43-
gem install twilio-ruby -v 5.77.0
48+
gem install twilio-ruby -v 6.0.0
4449
```
4550

4651
To build and install the development branch yourself from the latest source:
@@ -337,6 +342,7 @@ If you've instead found a bug in the library or would like new features added, g
337342

338343
[apidocs]: https://www.twilio.com/docs/api
339344
[twiml]: https://www.twilio.com/docs/api/twiml
345+
[libdocs]: https://www.twilio.com/docs/libraries/reference/twilio-ruby/
340346
[refdocs]: https://twilio.github.io/twilio-ruby
341347
[capability]: https://github.com/twilio/twilio-ruby/wiki/JWT-Tokens
342348
[wiki]: https://github.com/twilio/twilio-ruby/wiki

UPGRADE.md

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
_After `5.0.0` all `MINOR` and `MAJOR` version bumps will have upgrade notes
44
posted here._
55

6+
[2023-05-03] 5.x.x to 6.x.x
7+
-----------------------------
8+
### Overview
9+
10+
##### Twilio Ruby Helper Library’s major version 6.0.0 is now available. We ensured that you can upgrade to Ruby helper Library 6.0.0 version without any breaking changes
11+
12+
Behind the scenes Ruby Helper is now auto-generated via OpenAPI with this release. This enables us to rapidly add new features and enhance consistency across versions and languages.
13+
14+
To learn more about the Ruby Helper Library, check out [our docs](https://www.twilio.com/docs/libraries/ruby).
15+
616
[2017-09-29] 5.x.x to 5.3.x
717
---------------------------
818

cluster_spec.rb

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
require 'rspec/matchers'
2+
require 'twilio-ruby'
3+
4+
# rubocop:disable Metrics/BlockLength
5+
describe 'Cluster Test' do
6+
before(:each) do
7+
@account_sid = ENV['TWILIO_ACCOUNT_SID']
8+
@secret = ENV['TWILIO_API_SECRET']
9+
@api_key = ENV['TWILIO_API_KEY']
10+
@to_number = ENV['TWILIO_TO_NUMBER']
11+
@from_number = ENV['TWILIO_FROM_NUMBER']
12+
@client = Twilio::REST::Client.new @api_key, @secret, @account_sid
13+
end
14+
15+
it 'can send a text' do
16+
message = @client.messages.create(
17+
to: @to_number,
18+
from: @from_number,
19+
body: 'Cluster test message from twilio-ruby'
20+
)
21+
expect(message).to_not eq(nil)
22+
expect(message.body.include?('Cluster test message from twilio-ruby')).to eq(true)
23+
expect(message.from).to eq(@from_number)
24+
expect(message.to).to eq(@to_number)
25+
end
26+
27+
it 'can list numbers' do
28+
phone_numbers = @client.incoming_phone_numbers.list
29+
expect(phone_numbers).to_not eq(nil)
30+
expect(phone_numbers).to_not match_array([])
31+
end
32+
33+
it 'list a number' do
34+
phone_numbers = @client.incoming_phone_numbers.list(phone_number: @from_number)
35+
expect(phone_numbers).to_not eq(nil)
36+
expect(phone_numbers[0].phone_number).to eq(@from_number)
37+
end
38+
39+
it 'allows special characters for friendly and identity name' do
40+
service = @client.chat.v2.services.create(friendly_name: 'service|friendly&name')
41+
expect(service).to_not eq(nil)
42+
43+
user = @client.chat.v2.services(service.sid).users.create(identity: 'user|identity&string')
44+
expect(user).to_not eq(nil)
45+
46+
is_user_deleted = @client.chat.v2.services(service.sid).users(user.sid).delete
47+
expect(is_user_deleted).to eq(true)
48+
49+
is_service_deleted = @client.chat.v2.services(service.sid).delete
50+
expect(is_service_deleted).to eq(true)
51+
end
52+
53+
it 'test list params' do
54+
sink_configuration = { 'destination' => 'http://example.org/webhook', 'method' => 'post',
55+
'batch_events' => false }
56+
types = [{ 'type' => 'com.twilio.messaging.message.delivered' },
57+
{ 'type' => 'com.twilio.messaging.message.sent' }]
58+
59+
sink = @client.events.v1.sinks.create(
60+
description: 'test sink ruby',
61+
sink_configuration: sink_configuration,
62+
sink_type: 'webhook'
63+
)
64+
expect(sink).to_not eq(nil)
65+
66+
subscription = @client.events.v1.subscriptions.create(
67+
description: 'test subscription ruby',
68+
types: types,
69+
sink_sid: sink.sid
70+
)
71+
expect(subscription).to_not eq(nil)
72+
73+
expect(@client.events.v1.subscriptions(subscription.sid).delete).to eq(true)
74+
expect(@client.events.v1.sinks(sink.sid).delete).to eq(true)
75+
end
76+
end
77+
# rubocop:enable Metrics/BlockLength

lib/twilio-ruby/base/client_base.rb

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
module Twilio
2+
module REST
3+
class ClientBase
4+
# rubocop:disable Style/ClassVars
5+
@@default_region = 'us1'
6+
# rubocop:enable Style/ClassVars
7+
8+
attr_accessor :http_client, :username, :password, :account_sid, :auth_token, :region, :edge, :logger,
9+
:user_agent_extensions
10+
11+
# rubocop:disable Metrics/ParameterLists
12+
def initialize(username = nil, password = nil, account_sid = nil, region = nil, http_client = nil, logger = nil,
13+
user_agent_extensions = nil)
14+
@username = username || Twilio.account_sid
15+
@password = password || Twilio.auth_token
16+
@region = region || Twilio.region
17+
@edge = Twilio.edge
18+
@account_sid = account_sid || @username
19+
@auth_token = @password
20+
@auth = [@username, @password]
21+
@http_client = http_client || Twilio.http_client || Twilio::HTTP::Client.new
22+
@logger = logger || Twilio.logger
23+
@user_agent_extensions = user_agent_extensions || []
24+
end
25+
# rubocop:enable Metrics/ParameterLists
26+
27+
##
28+
# Makes a request to the Twilio API using the configured http client
29+
# Authentication information is automatically added if none is provided
30+
# rubocop:disable Lint/ShadowedArgument
31+
def request(host, port, method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) # rubocop:disable Metrics/MethodLength
32+
auth ||= @auth
33+
headers = generate_headers(method)
34+
uri = build_uri(uri)
35+
36+
if @logger
37+
@logger.debug('--BEGIN Twilio API Request--')
38+
@logger.debug("Request Method: <#{method}>")
39+
40+
headers.each do |key, value|
41+
@logger.debug("#{key}:#{value}") unless key.downcase == 'authorization'
42+
end
43+
44+
url = URI(uri)
45+
@logger.debug("Host:#{url.host}")
46+
@logger.debug("Path:#{url.path}")
47+
@logger.debug("Query:#{url.query}")
48+
@logger.debug("Request Params:#{params}")
49+
end
50+
51+
response = @http_client.request(
52+
host,
53+
port,
54+
method,
55+
uri,
56+
params,
57+
data,
58+
headers,
59+
auth,
60+
timeout
61+
)
62+
63+
if @logger
64+
@logger.debug("Response Status Code:#{response.status_code}")
65+
@logger.debug("Response Headers:#{response.headers}")
66+
@logger.debug('--END TWILIO API REQUEST--')
67+
end
68+
69+
response
70+
end
71+
# rubocop:enable Lint/ShadowedArgument
72+
73+
##
74+
# Build the final request uri
75+
def build_uri(uri)
76+
return uri if @region.nil? && @edge.nil?
77+
78+
parsed_url = URI(uri)
79+
pieces = parsed_url.host.split('.')
80+
product = pieces[0]
81+
domain = pieces[-2, 2]
82+
new_edge = @edge
83+
new_region = @region
84+
85+
case pieces.length
86+
when 4
87+
new_region ||= pieces[1]
88+
when 5
89+
new_edge ||= pieces[1]
90+
new_region ||= pieces[2]
91+
end
92+
93+
new_region = @@default_region if !new_edge.nil? && new_region.nil?
94+
95+
parsed_url.host = [product, new_edge, new_region, domain].reject(&:nil?).join('.')
96+
parsed_url.to_s
97+
end
98+
99+
##
100+
# Validate the new SSL certificate for the Twilio API
101+
def validate_ssl_certificate
102+
response = request('api.twilio.com', '8443', 'GET', 'https://api.twilio.com:8443/.json')
103+
return unless response.status_code < 200 || response.status_code >= 300
104+
105+
raise RestError.new 'Unexpected response from certificate endpoint', response
106+
end
107+
108+
def generate_headers(method)
109+
ruby_config = RbConfig::CONFIG
110+
headers = {}
111+
headers['User-Agent'] =
112+
"twilio-ruby/#{Twilio::VERSION} (#{ruby_config['host_os']} #{ruby_config['host_cpu']}) Ruby/#{RUBY_VERSION}"
113+
headers['Accept-Charset'] = 'utf-8'
114+
115+
user_agent_extensions.each { |extension| headers['User-Agent'] += " #{extension}" }
116+
117+
headers['Content-Type'] = 'application/x-www-form-urlencoded' if method == 'POST' && !headers['Content-Type']
118+
119+
headers['Accept'] = 'application/json' unless headers['Accept']
120+
headers
121+
end
122+
end
123+
end
124+
end

lib/twilio-ruby/framework/rest/error.rb

-12
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
module Twilio
44
module REST
55
class TwilioError < StandardError
6-
# @deprecated all errors that have a body are now 'Twilio::RestError's
7-
def body
8-
warn "'Twilio::REST::TwilioError#body' has been deprecated. No 'TwilioError' objects are raised with a body."
9-
nil
10-
end
116
end
127

138
class RestError < TwilioError
@@ -23,13 +18,6 @@ def initialize(message, response)
2318
@response = response
2419
end
2520

26-
# @deprecated use #response instead
27-
def body
28-
warn 'This error used to be a "Twilio::REST::TwilioError" but is now a "Twilio::REST::RestError". ' \
29-
'Please use #response instead of #body.'
30-
@response
31-
end
32-
3321
def to_s
3422
message
3523
end

lib/twilio-ruby/framework/twilio_response.rb

-19
This file was deleted.

0 commit comments

Comments
 (0)