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

Fix ruby snippets linter issues #957

Merged
merged 7 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api-auth/api-auth.5.x.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'twilio-ruby'

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

# DANGER! This is insecure. See http://twil.io/secure
@client = Twilio::REST::Client.new api_key, api_secret, account_sid
Expand Down
2 changes: 1 addition & 1 deletion client/capability-token-2way/capability-token.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'sinatra'

get '/token' do
# To set up environmental variables, see http://twil.io/secure
# To set up environmental variables, see http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)
Expand Down
2 changes: 1 addition & 1 deletion client/capability-token-incoming/capability-token.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'sinatra'

get '/token' do
# To set up environmental variables, see http://twil.io/secure
# To set up environmental variables, see http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)
Expand Down
2 changes: 1 addition & 1 deletion client/capability-token-outgoing/capability-token.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'sinatra'

get '/token' do
# To set up environmental variables, see http://twil.io/secure
# To set up environmental variables, see http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)
Expand Down
2 changes: 1 addition & 1 deletion client/capability-token/capability-token.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'sinatra'

get '/token' do
# To set up environmental variables, see http://twil.io/secure
# To set up environmental variables, see http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
capability = Twilio::JWT::ClientCapability.new(account_sid, auth_token)
Expand Down
2 changes: 1 addition & 1 deletion client/response-twiml-client/response-twiml-client.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
r.Dial callerId: '+15017122661' do |d|
# wrap the phone number or client name in the appropriate TwiML verb
# by checking if the number given has only digits and format symbols
if params['To'].match?(/^[\d\+\-\(\) ]+$/)
if params['To'].match?(/^[\d+\-() ]+$/)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop suggested this change. Remove unnecessary escapes.

d.Number params['To']
else
d.Client params['To']
Expand Down
1 change: 0 additions & 1 deletion fax/basic-send/basic-send.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Net::HTTP.start(uri.host, uri.port,
use_ssl: uri.scheme == 'https') do |http|

request = Net::HTTP::Post.new uri.request_uri
request.basic_auth account_sid, auth_token
request.body = URI.encode_www_form(To: '+15558675310',
Expand Down
1 change: 0 additions & 1 deletion fax/instance-get-example/instance-get-example.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Net::HTTP.start(uri.host, uri.port,
use_ssl: uri.scheme == 'https') do |http|

request = Net::HTTP::Get.new uri.request_uri
request.basic_auth(account_sid, auth_token)

Expand Down
1 change: 0 additions & 1 deletion fax/instance-post-example/instance-post-example.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Net::HTTP.start(uri.host, uri.port,
use_ssl: uri.scheme == 'https') do |http|

request = Net::HTTP::Post.new uri.request_uri
request.basic_auth(account_sid, auth_token)
request.body = URI.encode_www_form(Status: 'canceled')
Expand Down
1 change: 0 additions & 1 deletion fax/list-get-example/list-get-example.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Net::HTTP.start(uri.host, uri.port,
use_ssl: uri.scheme == 'https') do |http|

request = Net::HTTP::Get.new uri.request_uri
request.basic_auth(account_sid, auth_token)

Expand Down
1 change: 0 additions & 1 deletion fax/sip-send/example-1/example-1.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Net::HTTP.start(uri.host, uri.port,
use_ssl: uri.scheme == 'https') do |http|

request = Net::HTTP::Post.new uri.request_uri
request.basic_auth(account_sid, auth_token)
request.body = URI.encode_www_form(To: 'sip:[email protected]',
Expand Down
1 change: 0 additions & 1 deletion fax/sip-send/example-2/example-2.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Net::HTTP.start(uri.host, uri.port,
use_ssl: uri.scheme == 'https') do |http|

request = Net::HTTP::Post.new uri.request_uri
request.basic_auth(account_sid, auth_token)
request.body = URI.encode_www_form(To: 'sip:[email protected]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

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

# To set up environmental variables, see http://twil.io/secure
# To set up environmental variables, see http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
resp = HTTParty.get(
Expand Down
2 changes: 1 addition & 1 deletion ip-messaging/rest/roles/update-role/update-role.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
# Update a role
role = service.roles('RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch
new_permissions = role.permissions | ['sendMediaMessage']
role = role.update(permission: new_permissions)
role.update(permission: new_permissions)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary reassignment.

puts "Role #{role.sid} now has permissions #{role.permissions.join(', ')}"
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Create an Access Token for Chat usage
token = Twilio::Util::AccessToken.new(
# To set up environmental variables, see http://twil.io/secure
# To set up environmental variables, see http://twil.io/secure
ENV['TWILIO_ACCOUNT_SID'],
ENV['TWILIO_API_KEY'],
ENV['TWILIO_API_SECRET'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

puts number.carrier['type']
puts number.carrier['name']
rescue Twilio::REST::RestError => err
if err.status_code === 404
rescue Twilio::REST::RestError => e
if e.status_code === 404 # rubocop:disable Style/CaseEquality
alexisbcc marked this conversation as resolved.
Show resolved Hide resolved
puts 'No carrier information'
else
puts err.message
puts e.message
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
encoded_phone_number = CGI.escape('+15108675310')
number = @client.lookups.v1
.phone_numbers(encoded_phone_number)
.fetch(type: ['carrier', 'caller-name'])
.fetch(type: %w[carrier caller-name])

puts number.carrier['type']
puts number.carrier['name']
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

service = service.update(
service.update(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary reassignment.

friendly_name: 'Another Awesome Service',
facebook_messenger_page_id: 'your_page_id',
messaging_service_sid: 'your_twilio_messaging_service_sid'
Expand Down
2 changes: 1 addition & 1 deletion notifications/rest/users/create-user/create-user.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.notify.v1.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.users.create(
identity: 'User0001',
segment: ['premium', 'fitness-lifestyle']
segment: %w[premium fitness-lifestyle]
)

puts user.sid
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

numbers = @client.pricing.voice.numbers('+15108675310')
number = @client.pricing.voice.numbers('+15108675310')
puts number.fetch(origination_number: '+12421234567')
.outbound_call_price['current_price']
2 changes: 1 addition & 1 deletion pricing/get-voice-number/get-voice-number.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

numbers = @client.pricing.voice.numbers('+15108675310')
number = @client.pricing.voice.numbers('+15108675310')
puts number.fetch.outbound_call_price['current_price']
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

puts "Hello-world task has been created!"
puts 'Hello-world task has been created!'
puts task.sid
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@

# Build task actions that say something and listens for a repsonse.
phrases = [
"hello",
"hi",
"Hello",
"Hi there"
'hello',
'hi',
'Hello',
'Hi there'
]

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

puts sample.sid
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
@client = Twilio::REST::Client.new(account_sid, auth_token)

phrases = [
"Tell me a joke",
"Tell me a joke",
"Id like to hear a joke",
"Do you know any good jokes?",
"Joke",
"Tell joke",
"Tell me something funny",
"Make me laugh",
"I want to hear a joke",
"Can I hear a joke?",
"I like jokes",
"Id like to hear a punny joke"
'Tell me a joke',
'Tell me a joke',
'Id like to hear a joke',
'Do you know any good jokes?',
'Joke',
'Tell joke',
'Tell me something funny',
'Make me laugh',
'I want to hear a joke',
'Can I hear a joke?',
'I like jokes',
'Id like to hear a punny joke'
]

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

puts sample.sid
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

# Provide actions for the new task
joke_actions = {
"actions" => [
{ "say": "I was going to look for my missing watch, but I could never find the time." },
'actions' => [
{ "say": 'I was going to look for my missing watch, but I could never find the time.' }
]
}

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

puts "Tell-a-joke task has been created!"
puts 'Tell-a-joke task has been created!'
puts task.sid
6 changes: 3 additions & 3 deletions quickstart/ruby/autopilot/query-task/query_task.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

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

puts query.results['task']
6 changes: 3 additions & 3 deletions quickstart/ruby/sms/example-1/send_notifications.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
to = '+15555555555' # Your mobile phone number

client.messages.create(
from: from,
to: to,
body: "Hey friend!"
from: from,
to: to,
body: 'Hey friend!'
)
7 changes: 3 additions & 4 deletions quickstart/ruby/sms/example-2/send_notifications.5.x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
to = '+15555555555' # Your mobile phone number

client.messages.create(
from: from,
to: to,
body: "Hey friend!"
from: from,
to: to,
body: 'Hey friend!'
)

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@client = Twilio::REST::Client.new(account_sid, auth_token)

call = @client.calls.create(
to: "+15558675310",
from: "+15017122661",
url: "http://demo.twilio.com/docs/voice.xml")
puts call.to
to: '+15558675310',
from: '+15017122661',
url: 'http://demo.twilio.com/docs/voice.xml'
)
puts call.to
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
require 'bundler'
Bundler.require()
Bundler.require

def self.get_or_post(url,&block)
get(url,&block)
post(url,&block)
def self.get_or_post(url, &block)
get(url, &block)
post(url, &block)
end

get_or_post '/answer' do

Twilio::TwiML::VoiceResponse.new do |r|
r.say(message: "Thank you for calling! Have a great day.")
end.to_s

end
Twilio::TwiML::VoiceResponse.new do |r|
r.say(message: 'Thank you for calling! Have a great day.')
end.to_s
end
Loading