-
Notifications
You must be signed in to change notification settings - Fork 0
UpgradeGuide
There are a lot of good reasons to use the new twilio-ruby api, as demonstrated in the README and other documentation. But if you are interested in upgrading to the twilio-ruby library while making minimal changes to your code, read on.
There's really just one change you need to make if you have been using the twiliolib ruby gem and want to upgrade. The twilio-ruby library's Client object supports the old #request(uri, method, params) method, so you just have to replace the Twilio::RestAccount class name with Twilio::REST::Client.
Using the old twiliolib code, you probably wrote something like the following:
require 'twiliolib'
# Twilio AccountSid and AuthToken
ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
account = Twilio::RestAccount.new(ACCOUNT_SID, ACCOUNT_TOKEN)With the new twilio-ruby library, everything works if you just replace the clas name:
require 'twilio-ruby'
# Twilio AccountSid and AuthToken
ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
account = Twilio::REST::Client.new(ACCOUNT_SID, ACCOUNT_TOKEN)You shouldn't need to change any other parts of your code. For instance, this will still work (adapted from the twiliolib REST examples):
# ===========================================================================
# 1. Initiate a new outbound call to 415-555-1212
# uses a HTTP POST
CALLER_ID = 4159354455
API_VERSION = '2010-04-01'
d = {
'From' => CALLER_ID,
'To' => '415-555-1212',
'Url' => 'http://demo.twilio.com/welcome',
}
resp = account.request("/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/Calls",
'POST', d)
resp.error! unless resp.kind_of? Net::HTTPSuccess
puts "code: %s\nbody: %s" % [resp.code, resp.body]