Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 5250407

Browse files
authored
Merge pull request #957 from TwilioDevEd/fix-ruby-snippets
Fix ruby snippets linter issues
2 parents 44496e0 + 4ed1f78 commit 5250407

File tree

147 files changed

+346
-349
lines changed

Some content is hidden

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

147 files changed

+346
-349
lines changed

Diff for: .rubocop.yml

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Style/FrozenStringLiteralComment:
1111
Enabled: false
1212
Metrics/BlockLength:
1313
Enabled: false
14+
Metrics/MethodLength:
15+
Enabled: false

Diff for: api-auth/api-auth.5.x.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'twilio-ruby'
22

33
# To set up environmental variables, see http://twil.io/secure
4-
account_sid = ENV['TWILIO_ACCOUNT_SID'] # Your Account SID from www.twilio.com/console
5-
api_key = ENV['TWILIO_API_KEY'] # You can generate this from www.twilio.com/console/runtime/api-keys/create
6-
api_secret = ENV['TWILIO_API_KEY_SECRET'] # You can generate this from www.twilio.com/console/runtime/api-keys/create
4+
account_sid = ENV['TWILIO_ACCOUNT_SID'] # Your Account SID from www.twilio.com/console
5+
api_key = ENV['TWILIO_API_KEY'] # You can generate this from www.twilio.com/console/runtime/api-keys/create
6+
api_secret = ENV['TWILIO_API_KEY_SECRET'] # You can generate this from www.twilio.com/console/runtime/api-keys/create
77

88
# DANGER! This is insecure. See http://twil.io/secure
99
@client = Twilio::REST::Client.new api_key, api_secret, account_sid

Diff for: client/capability-token-2way/capability-token.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sinatra'
33

44
get '/token' do
5-
# To set up environmental variables, see http://twil.io/secure
5+
# To set up environmental variables, see http://twil.io/secure
66
account_sid = ENV['TWILIO_ACCOUNT_SID']
77
auth_token = ENV['TWILIO_AUTH_TOKEN']
88
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)

Diff for: client/capability-token-incoming/capability-token.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sinatra'
33

44
get '/token' do
5-
# To set up environmental variables, see http://twil.io/secure
5+
# To set up environmental variables, see http://twil.io/secure
66
account_sid = ENV['TWILIO_ACCOUNT_SID']
77
auth_token = ENV['TWILIO_AUTH_TOKEN']
88
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)

Diff for: client/capability-token-outgoing/capability-token.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sinatra'
33

44
get '/token' do
5-
# To set up environmental variables, see http://twil.io/secure
5+
# To set up environmental variables, see http://twil.io/secure
66
account_sid = ENV['TWILIO_ACCOUNT_SID']
77
auth_token = ENV['TWILIO_AUTH_TOKEN']
88
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)

Diff for: client/capability-token/capability-token.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sinatra'
33

44
get '/token' do
5-
# To set up environmental variables, see http://twil.io/secure
5+
# To set up environmental variables, see http://twil.io/secure
66
account_sid = ENV['TWILIO_ACCOUNT_SID']
77
auth_token = ENV['TWILIO_AUTH_TOKEN']
88
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)

Diff for: client/response-twiml-client/response-twiml-client.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
r.Dial callerId: '+15017122661' do |d|
88
# wrap the phone number or client name in the appropriate TwiML verb
99
# by checking if the number given has only digits and format symbols
10-
if params['To'].match?(/^[\d\+\-\(\) ]+$/)
10+
if params['To'].match?(/^[\d+\-() ]+$/)
1111
d.Number params['To']
1212
else
1313
d.Client params['To']

Diff for: fax/basic-send/basic-send.5.x.rb

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
Net::HTTP.start(uri.host, uri.port,
1212
use_ssl: uri.scheme == 'https') do |http|
13-
1413
request = Net::HTTP::Post.new uri.request_uri
1514
request.basic_auth account_sid, auth_token
1615
request.body = URI.encode_www_form(To: '+15558675310',

Diff for: fax/instance-get-example/instance-get-example.5.x.rb

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
Net::HTTP.start(uri.host, uri.port,
1212
use_ssl: uri.scheme == 'https') do |http|
13-
1413
request = Net::HTTP::Get.new uri.request_uri
1514
request.basic_auth(account_sid, auth_token)
1615

Diff for: fax/instance-post-example/instance-post-example.5.x.rb

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
Net::HTTP.start(uri.host, uri.port,
1212
use_ssl: uri.scheme == 'https') do |http|
13-
1413
request = Net::HTTP::Post.new uri.request_uri
1514
request.basic_auth(account_sid, auth_token)
1615
request.body = URI.encode_www_form(Status: 'canceled')

Diff for: fax/list-get-example/list-get-example.5.x.rb

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
Net::HTTP.start(uri.host, uri.port,
1212
use_ssl: uri.scheme == 'https') do |http|
13-
1413
request = Net::HTTP::Get.new uri.request_uri
1514
request.basic_auth(account_sid, auth_token)
1615

Diff for: fax/sip-send/example-1/example-1.5.x.rb

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
Net::HTTP.start(uri.host, uri.port,
1212
use_ssl: uri.scheme == 'https') do |http|
13-
1413
request = Net::HTTP::Post.new uri.request_uri
1514
request.basic_auth(account_sid, auth_token)
1615
request.body = URI.encode_www_form(To: 'sip:[email protected]',

Diff for: fax/sip-send/example-2/example-2.5.x.rb

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
Net::HTTP.start(uri.host, uri.port,
1212
use_ssl: uri.scheme == 'https') do |http|
13-
1413
request = Net::HTTP::Post.new uri.request_uri
1514
request.basic_auth(account_sid, auth_token)
1615
request.body = URI.encode_www_form(To: 'sip:[email protected]',

Diff for: guides/voice/recording-add-on-guide/use-add-on-data/use-add-on-data.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
payload_url = add_ons['results']['ibm_watson_speechtotext']['payload'][0]['url']
3333

34-
# To set up environmental variables, see http://twil.io/secure
34+
# To set up environmental variables, see http://twil.io/secure
3535
account_sid = ENV['TWILIO_ACCOUNT_SID']
3636
auth_token = ENV['TWILIO_AUTH_TOKEN']
3737
resp = HTTParty.get(

Diff for: ip-messaging/rest/roles/update-role/update-role.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
# Update a role
1212
role = service.roles('RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch
1313
new_permissions = role.permissions | ['sendMediaMessage']
14-
role = role.update(permission: new_permissions)
14+
role.update(permission: new_permissions)
1515
puts "Role #{role.sid} now has permissions #{role.permissions.join(', ')}"

Diff for: ip-messaging/users/token-generation-server/token-generation-server.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# Create an Access Token for Chat usage
2727
token = Twilio::Util::AccessToken.new(
28-
# To set up environmental variables, see http://twil.io/secure
28+
# To set up environmental variables, see http://twil.io/secure
2929
ENV['TWILIO_ACCOUNT_SID'],
3030
ENV['TWILIO_API_KEY'],
3131
ENV['TWILIO_API_SECRET'],

Diff for: lookups/lookup-get-basic-example-1/lookup-get-basic-example-1.5.x.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
puts number.carrier['type']
1414
puts number.carrier['name']
15-
rescue Twilio::REST::RestError => err
16-
if err.status_code === 404
15+
rescue Twilio::REST::RestError => e
16+
if e.status_code == 404
1717
puts 'No carrier information'
1818
else
19-
puts err.message
19+
puts e.message
2020
end
2121
end

Diff for: lookups/lookup-get-carrier-cname-example-1/lookup-get-carrier-cname-example-1.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
encoded_phone_number = CGI.escape('+15108675310')
1111
number = @client.lookups.v1
1212
.phone_numbers(encoded_phone_number)
13-
.fetch(type: ['carrier', 'caller-name'])
13+
.fetch(type: %w[carrier caller-name])
1414

1515
puts number.carrier['type']
1616
puts number.carrier['name']

Diff for: notifications/rest/services/update-service/update-service.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
service = client.notify.v1.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
1212

13-
service = service.update(
13+
service.update(
1414
friendly_name: 'Another Awesome Service',
1515
facebook_messenger_page_id: 'your_page_id',
1616
messaging_service_sid: 'your_twilio_messaging_service_sid'

Diff for: notifications/rest/users/create-user/create-user.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
.notify.v1.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
1313
.users.create(
1414
identity: 'User0001',
15-
segment: ['premium', 'fitness-lifestyle']
15+
segment: %w[premium fitness-lifestyle]
1616
)
1717

1818
puts user.sid

Diff for: pricing/get-voice-number-with-origination-number/get-voice-number-with-origination-number.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
auth_token = ENV['TWILIO_AUTH_TOKEN']
88
@client = Twilio::REST::Client.new(account_sid, auth_token)
99

10-
numbers = @client.pricing.voice.numbers('+15108675310')
10+
number = @client.pricing.voice.numbers('+15108675310')
1111
puts number.fetch(origination_number: '+12421234567')
1212
.outbound_call_price['current_price']

Diff for: pricing/get-voice-number/get-voice-number.5.x.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
auth_token = ENV['TWILIO_AUTH_TOKEN']
88
@client = Twilio::REST::Client.new(account_sid, auth_token)
99

10-
numbers = @client.pricing.voice.numbers('+15108675310')
10+
number = @client.pricing.voice.numbers('+15108675310')
1111
puts number.fetch.outbound_call_price['current_price']

Diff for: quickstart/ruby/autopilot/create-first-task/create_hello_world_task.5.x.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# Build task actions that say something and listens for a repsonse.
1212
hello_world_task_actions = {
13-
"actions" => [
13+
'actions' => [
1414
{ "say": "Hi there, I'm your virtual assistant! How can I help you?" },
1515
{ "listen": true }
1616
]
@@ -19,11 +19,11 @@
1919
# Create the hello_world task
2020
# Replace 'UAXXX...' with your Assistant's unique SID https://www.twilio.com/console/autopilot/list
2121
task = @client.autopilot.assistants('UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
22-
.tasks
23-
.create(
24-
unique_name: "hello-world",
25-
actions: hello_world_task_actions
26-
)
22+
.tasks
23+
.create(
24+
unique_name: 'hello-world',
25+
actions: hello_world_task_actions
26+
)
2727

28-
puts "Hello-world task has been created!"
28+
puts 'Hello-world task has been created!'
2929
puts task.sid

Diff for: quickstart/ruby/autopilot/create-hello-world-samples/create_hello_world_samples.5.x.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010

1111
# Build task actions that say something and listens for a repsonse.
1212
phrases = [
13-
"hello",
14-
"hi",
15-
"Hello",
16-
"Hi there"
13+
'hello',
14+
'hi',
15+
'Hello',
16+
'Hi there'
1717
]
1818

1919
# Create the hello_world task
2020
# Replace 'UAXXX...' with your Assistant's unique SID https://www.twilio.com/console/autopilot/list
2121
phrases.each do |phrase|
2222
sample = @client.autopilot.assistants('UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
23-
.tasks("hello-world")
24-
.samples
25-
.create(
26-
language: "en-us",
27-
tagged_text: phrase
28-
)
23+
.tasks('hello-world')
24+
.samples
25+
.create(
26+
language: 'en-us',
27+
tagged_text: phrase
28+
)
2929

3030
puts sample.sid
3131
end

Diff for: quickstart/ruby/autopilot/create-joke-samples/create_joke_samples.5.x.rb

+18-18
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
@client = Twilio::REST::Client.new(account_sid, auth_token)
1010

1111
phrases = [
12-
"Tell me a joke",
13-
"Tell me a joke",
14-
"Id like to hear a joke",
15-
"Do you know any good jokes?",
16-
"Joke",
17-
"Tell joke",
18-
"Tell me something funny",
19-
"Make me laugh",
20-
"I want to hear a joke",
21-
"Can I hear a joke?",
22-
"I like jokes",
23-
"Id like to hear a punny joke"
12+
'Tell me a joke',
13+
'Tell me a joke',
14+
'Id like to hear a joke',
15+
'Do you know any good jokes?',
16+
'Joke',
17+
'Tell joke',
18+
'Tell me something funny',
19+
'Make me laugh',
20+
'I want to hear a joke',
21+
'Can I hear a joke?',
22+
'I like jokes',
23+
'Id like to hear a punny joke'
2424
]
2525

2626
# Replace 'UAXXX...' with your Assistant's unique SID https://www.twilio.com/console/autopilot/list
2727
phrases.each do |phrase|
2828
sample = @client.autopilot.assistants('UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
29-
.tasks("tell-a-joke")
30-
.samples
31-
.create(
32-
language: "en-us",
33-
tagged_text: phrase
34-
)
29+
.tasks('tell-a-joke')
30+
.samples
31+
.create(
32+
language: 'en-us',
33+
tagged_text: phrase
34+
)
3535

3636
puts sample.sid
3737
end

Diff for: quickstart/ruby/autopilot/create-joke-task/create_joke_task.5.x.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
# Provide actions for the new task
1212
joke_actions = {
13-
"actions" => [
14-
{ "say": "I was going to look for my missing watch, but I could never find the time." },
13+
'actions' => [
14+
{ "say": 'I was going to look for my missing watch, but I could never find the time.' }
1515
]
1616
}
1717

1818
# Create a new task named 'tell_a_joke'
1919
# Replace 'UAXXX...' with your Assistant's unique SID https://www.twilio.com/console/autopilot/list
2020
task = @client.autopilot.assistants('UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
21-
.tasks
22-
.create(
23-
unique_name: "tell-a-joke",
24-
actions: joke_actions
25-
)
21+
.tasks
22+
.create(
23+
unique_name: 'tell-a-joke',
24+
actions: joke_actions
25+
)
2626

27-
puts "Tell-a-joke task has been created!"
27+
puts 'Tell-a-joke task has been created!'
2828
puts task.sid

Diff for: quickstart/ruby/autopilot/query-task/query_task.5.x.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
# Replace 'UAXXX...' with your Assistant's unique SID https://www.twilio.com/console/autopilot/list
1212
query = @client.preview.understand
13-
.assistants('UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
14-
.queries
15-
.create(language: 'en-US', query: 'Tell me a joke')
13+
.assistants('UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
14+
.queries
15+
.create(language: 'en-US', query: 'Tell me a joke')
1616

1717
puts query.results['task']

Diff for: quickstart/ruby/sms/example-1/send_notifications.5.x.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
to = '+15555555555' # Your mobile phone number
1111

1212
client.messages.create(
13-
from: from,
14-
to: to,
15-
body: "Hey friend!"
13+
from: from,
14+
to: to,
15+
body: 'Hey friend!'
1616
)

Diff for: quickstart/ruby/sms/example-2/send_notifications.5.x.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
to = '+15555555555' # Your mobile phone number
1111

1212
client.messages.create(
13-
from: from,
14-
to: to,
15-
body: "Hey friend!"
13+
from: from,
14+
to: to,
15+
body: 'Hey friend!'
1616
)
17-

Diff for: quickstart/ruby/voice/example-1-make-call/outgoing_call.5.x.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
@client = Twilio::REST::Client.new(account_sid, auth_token)
1010

1111
call = @client.calls.create(
12-
to: "+15558675310",
13-
from: "+15017122661",
14-
url: "http://demo.twilio.com/docs/voice.xml")
15-
puts call.to
12+
to: '+15558675310',
13+
from: '+15017122661',
14+
url: 'http://demo.twilio.com/docs/voice.xml'
15+
)
16+
puts call.to

0 commit comments

Comments
 (0)