class Twilio::REST::Client

A client for accessing the Twilio API.

Attributes

account_sid[RW]
auth_token[RW]
edge[RW]
http_client[RW]
logger[RW]
password[RW]
region[RW]
username[RW]

Public Class Methods

new(username=nil, password=nil, account_sid=nil, region=nil, http_client=nil, logger=nil) click to toggle source

Initializes the Twilio Client

   # File lib/twilio-ruby/rest/client.rb
20 def initialize(username=nil, password=nil, account_sid=nil, region=nil, http_client=nil, logger=nil)
21   @username = username || Twilio.account_sid
22   @password = password || Twilio.auth_token
23   @region = region || Twilio.region
24   @edge = Twilio.edge
25   @account_sid = account_sid || @username
26   @auth_token = @password
27   @auth = [@username, @password]
28   @http_client = http_client || Twilio.http_client || Twilio::HTTP::Client.new
29   @logger = logger || Twilio.logger
30 
31   # Domains
32   @accounts = nil
33   @api = nil
34   @autopilot = nil
35   @chat = nil
36   @conversations = nil
37   @events = nil
38   @fax = nil
39   @flex_api = nil
40   @frontline_api = nil
41   @insights = nil
42   @ip_messaging = nil
43   @lookups = nil
44   @messaging = nil
45   @monitor = nil
46   @notify = nil
47   @numbers = nil
48   @preview = nil
49   @pricing = nil
50   @proxy = nil
51   @serverless = nil
52   @studio = nil
53   @sync = nil
54   @taskrouter = nil
55   @trunking = nil
56   @trusthub = nil
57   @verify = nil
58   @video = nil
59   @voice = nil
60   @wireless = nil
61   @supersim = nil
62   @bulkexports = nil
63 end

Public Instance Methods

accounts() click to toggle source

Access the Accounts Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
164 def accounts
165   @accounts ||= Accounts.new self
166 end
addresses(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

Address resource.

@return [Twilio::REST::Api::V2010::AccountContext::AddressInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::AddressList]

    # File lib/twilio-ruby/rest/client.rb
353 def addresses(sid=:unset)
354   self.api.v2010.account.addresses(sid)
355 end
api() click to toggle source

Access the Api Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
170 def api
171   @api ||= Api.new self
172 end
applications(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

Application resource.

@return [Twilio::REST::Api::V2010::AccountContext::ApplicationInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::ApplicationList]

    # File lib/twilio-ruby/rest/client.rb
362 def applications(sid=:unset)
363   self.api.v2010.account.applications(sid)
364 end
authorized_connect_apps(connect_app_sid=:unset) click to toggle source

@param [String] connect_app_sid The SID that we assigned to the Connect App. @return [Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppInstance] if connect_app_sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppList]

    # File lib/twilio-ruby/rest/client.rb
370 def authorized_connect_apps(connect_app_sid=:unset)
371   self.api.v2010.account.authorized_connect_apps(connect_app_sid)
372 end
autopilot() click to toggle source

Access the Autopilot Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
176 def autopilot
177   @autopilot ||= Autopilot.new self
178 end
available_phone_numbers(country_code=:unset) click to toggle source

@param [String] country_code The

{ISO-3166-1}[https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2] country code of
the country.

@return [Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryInstance] if country_code was passed. @return [Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryList]

    # File lib/twilio-ruby/rest/client.rb
380 def available_phone_numbers(country_code=:unset)
381   self.api.v2010.account.available_phone_numbers(country_code)
382 end
balance() click to toggle source

@return [Twilio::REST::Api::V2010::AccountContext::BalanceInstance]

    # File lib/twilio-ruby/rest/client.rb
386 def balance
387   self.api.v2010.account.balance
388 end
build_uri(uri) click to toggle source

Build the final request uri

    # File lib/twilio-ruby/rest/client.rb
126 def build_uri(uri)
127   if @region.nil? and @edge.nil?
128     return uri
129   end
130 
131   parsed_url = URI(uri)
132   pieces = parsed_url.host.split('.')
133   product = pieces[0]
134   domain = pieces[-2, 2]
135   new_edge = @edge
136   new_region = @region
137 
138   if pieces.length == 4
139     new_region ||= pieces[1]
140   elsif pieces.length == 5
141     new_edge ||= pieces[1]
142     new_region ||= pieces[2]
143   end
144 
145   if !new_edge.nil? && new_region.nil?
146     new_region = @@default_region
147   end
148 
149   parsed_url.host = [product, new_edge, new_region, domain].select {|item| !item.nil?}.join('.')
150   parsed_url.to_s
151 end
bulkexports() click to toggle source

Access the Bulkexports Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
344 def bulkexports
345   @bulkexports ||= Bulkexports.new self
346 end
calls(sid=:unset) click to toggle source

@param [String] sid The unique string that we created to identify this Call

resource.

@return [Twilio::REST::Api::V2010::AccountContext::CallInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::CallList]

    # File lib/twilio-ruby/rest/client.rb
395 def calls(sid=:unset)
396   self.api.v2010.account.calls(sid)
397 end
chat() click to toggle source

Access the Chat Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
182 def chat
183   @chat ||= Chat.new self
184 end
conferences(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify this

Conference resource.

@return [Twilio::REST::Api::V2010::AccountContext::ConferenceInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::ConferenceList]

    # File lib/twilio-ruby/rest/client.rb
404 def conferences(sid=:unset)
405   self.api.v2010.account.conferences(sid)
406 end
connect_apps(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

ConnectApp resource.

@return [Twilio::REST::Api::V2010::AccountContext::ConnectAppInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::ConnectAppList]

    # File lib/twilio-ruby/rest/client.rb
413 def connect_apps(sid=:unset)
414   self.api.v2010.account.connect_apps(sid)
415 end
conversations() click to toggle source

Access the Conversations Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
188 def conversations
189   @conversations ||= Conversations.new self
190 end
events() click to toggle source

Access the Events Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
194 def events
195   @events ||= Events.new self
196 end
fax() click to toggle source

Access the Fax Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
200 def fax
201   @fax ||= Fax.new self
202 end
flex_api() click to toggle source

Access the FlexApi Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
206 def flex_api
207   @flex_api ||= FlexApi.new self
208 end
frontline_api() click to toggle source

Access the FrontlineApi Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
212 def frontline_api
213   @frontline_api ||= FrontlineApi.new self
214 end
incoming_phone_numbers(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify this

IncomingPhoneNumber resource.

@return [Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberList]

    # File lib/twilio-ruby/rest/client.rb
422 def incoming_phone_numbers(sid=:unset)
423   self.api.v2010.account.incoming_phone_numbers(sid)
424 end
insights() click to toggle source

Access the Insights Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
218 def insights
219   @insights ||= Insights.new self
220 end
ip_messaging() click to toggle source

Access the IpMessaging Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
224 def ip_messaging
225   @ip_messaging ||= IpMessaging.new self
226 end
keys(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the Key

resource.

@return [Twilio::REST::Api::V2010::AccountContext::KeyInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::KeyList]

    # File lib/twilio-ruby/rest/client.rb
431 def keys(sid=:unset)
432   self.api.v2010.account.keys(sid)
433 end
lookups() click to toggle source

Access the Lookups Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
230 def lookups
231   @lookups ||= Lookups.new self
232 end
messages(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

Message resource.

@return [Twilio::REST::Api::V2010::AccountContext::MessageInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::MessageList]

    # File lib/twilio-ruby/rest/client.rb
440 def messages(sid=:unset)
441   self.api.v2010.account.messages(sid)
442 end
messaging() click to toggle source

Access the Messaging Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
236 def messaging
237   @messaging ||= Messaging.new self
238 end
monitor() click to toggle source

Access the Monitor Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
242 def monitor
243   @monitor ||= Monitor.new self
244 end
new_keys() click to toggle source

@return [Twilio::REST::Api::V2010::AccountContext::NewKeyInstance]

    # File lib/twilio-ruby/rest/client.rb
446 def new_keys
447   self.api.v2010.account.new_keys
448 end
new_signing_keys() click to toggle source

@return [Twilio::REST::Api::V2010::AccountContext::NewSigningKeyInstance]

    # File lib/twilio-ruby/rest/client.rb
452 def new_signing_keys
453   self.api.v2010.account.new_signing_keys
454 end
notifications(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

Notification resource.

@return [Twilio::REST::Api::V2010::AccountContext::NotificationInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::NotificationList]

    # File lib/twilio-ruby/rest/client.rb
461 def notifications(sid=:unset)
462   self.api.v2010.account.notifications(sid)
463 end
notify() click to toggle source

Access the Notify Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
248 def notify
249   @notify ||= Notify.new self
250 end
numbers() click to toggle source

Access the Numbers Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
254 def numbers
255   @numbers ||= Numbers.new self
256 end
outgoing_caller_ids(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

OutgoingCallerId resource.

@return [Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdList]

    # File lib/twilio-ruby/rest/client.rb
470 def outgoing_caller_ids(sid=:unset)
471   self.api.v2010.account.outgoing_caller_ids(sid)
472 end
preview() click to toggle source

Access the Preview Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
260 def preview
261   @preview ||= Preview.new self
262 end
pricing() click to toggle source

Access the Pricing Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
266 def pricing
267   @pricing ||= Pricing.new self
268 end
proxy() click to toggle source

Access the Proxy Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
272 def proxy
273   @proxy ||= Proxy.new self
274 end
queues(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify this

Queue resource.

@return [Twilio::REST::Api::V2010::AccountContext::QueueInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::QueueList]

    # File lib/twilio-ruby/rest/client.rb
479 def queues(sid=:unset)
480   self.api.v2010.account.queues(sid)
481 end
recordings(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

Recording resource.

@return [Twilio::REST::Api::V2010::AccountContext::RecordingInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::RecordingList]

    # File lib/twilio-ruby/rest/client.rb
488 def recordings(sid=:unset)
489   self.api.v2010.account.recordings(sid)
490 end
request(host, port, method, uri, params={}, data={}, headers={}, auth=nil, timeout=nil) click to toggle source

Makes a request to the Twilio API using the configured http client Authentication information is automatically added if none is provided

    # File lib/twilio-ruby/rest/client.rb
 68 def request(host, port, method, uri, params={}, data={}, headers={}, auth=nil, timeout=nil)
 69   auth ||= @auth
 70 
 71   headers['User-Agent'] = "twilio-ruby/#{Twilio::VERSION}" +
 72                           " (#{RUBY_ENGINE}/#{RUBY_PLATFORM}" +
 73                           " #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})"
 74   headers['Accept-Charset'] = 'utf-8'
 75 
 76   if method == 'POST' && !headers['Content-Type']
 77     headers['Content-Type'] = 'application/x-www-form-urlencoded'
 78   end
 79 
 80   unless headers['Accept']
 81     headers['Accept'] = 'application/json'
 82   end
 83 
 84   uri = build_uri(uri)
 85 
 86   if @logger
 87     @logger.debug("--BEGIN Twilio API Request--")
 88     @logger.debug("Request Method: <#{method}>")
 89 
 90     headers.each do |key, value|
 91       unless key.downcase == 'authorization'
 92         @logger.debug("#{key}:#{value}")
 93       end
 94     end
 95 
 96     url = URI(uri)
 97     @logger.debug("Host:#{url.host}")
 98     @logger.debug("Path:#{url.path}")
 99     @logger.debug("Query:#{url.query}")
100     @logger.debug("Request Params:#{params}")
101   end
102 
103   response = @http_client.request(
104     host,
105     port,
106     method,
107     uri,
108     params,
109     data,
110     headers,
111     auth,
112     timeout
113   )
114 
115   if @logger
116     @logger.debug("Response Status Code:#{response.status_code}")
117     @logger.debug("Response Headers:#{response.headers}")
118     @logger.debug("--END TWILIO API REQUEST--")
119   end
120 
121   response
122 end
serverless() click to toggle source

Access the Serverless Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
278 def serverless
279   @serverless ||= Serverless.new self
280 end
short_codes(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify this

ShortCode resource.

@return [Twilio::REST::Api::V2010::AccountContext::ShortCodeInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::ShortCodeList]

    # File lib/twilio-ruby/rest/client.rb
511 def short_codes(sid=:unset)
512   self.api.v2010.account.short_codes(sid)
513 end
signing_keys(sid=:unset) click to toggle source

@param [String] sid The sid @return [Twilio::REST::Api::V2010::AccountContext::SigningKeyInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::SigningKeyList]

    # File lib/twilio-ruby/rest/client.rb
496 def signing_keys(sid=:unset)
497   self.api.v2010.account.signing_keys(sid)
498 end
sip() click to toggle source

@return [Twilio::REST::Api::V2010::AccountContext::SipInstance]

    # File lib/twilio-ruby/rest/client.rb
502 def sip
503   self.api.v2010.account.sip
504 end
studio() click to toggle source

Access the Studio Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
284 def studio
285   @studio ||= Studio.new self
286 end
supersim() click to toggle source

Access the Supersim Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
338 def supersim
339   @supersim ||= Supersim.new self
340 end
sync() click to toggle source

Access the Sync Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
290 def sync
291   @sync ||= Sync.new self
292 end
taskrouter() click to toggle source

Access the Taskrouter Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
296 def taskrouter
297   @taskrouter ||= Taskrouter.new self
298 end
to_s() click to toggle source

Provide a user friendly representation

    # File lib/twilio-ruby/rest/client.rb
544 def to_s
545   "#<Twilio::REST::Client #{@account_sid}>"
546 end
tokens() click to toggle source

@return [Twilio::REST::Api::V2010::AccountContext::TokenInstance]

    # File lib/twilio-ruby/rest/client.rb
517 def tokens
518   self.api.v2010.account.tokens
519 end
transcriptions(sid=:unset) click to toggle source

@param [String] sid The unique string that that we created to identify the

Transcription resource.

@return [Twilio::REST::Api::V2010::AccountContext::TranscriptionInstance] if sid was passed. @return [Twilio::REST::Api::V2010::AccountContext::TranscriptionList]

    # File lib/twilio-ruby/rest/client.rb
526 def transcriptions(sid=:unset)
527   self.api.v2010.account.transcriptions(sid)
528 end
trunking() click to toggle source

Access the Trunking Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
302 def trunking
303   @trunking ||= Trunking.new self
304 end
trusthub() click to toggle source

Access the Trusthub Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
308 def trusthub
309   @trusthub ||= Trusthub.new self
310 end
usage() click to toggle source

@return [Twilio::REST::Api::V2010::AccountContext::UsageInstance]

    # File lib/twilio-ruby/rest/client.rb
532 def usage
533   self.api.v2010.account.usage
534 end
validate_ssl_certificate() click to toggle source

Validate the new SSL certificate for the Twilio API

    # File lib/twilio-ruby/rest/client.rb
155 def validate_ssl_certificate
156   response = request('api.twilio.com', '8443', 'GET', 'https://api.twilio.com:8443/.json')
157   if response.status_code < 200 || response.status_code >= 300
158     raise RestError.new 'Unexpected response from certificate endpoint', response
159   end
160 end
validation_requests() click to toggle source

@return [Twilio::REST::Api::V2010::AccountContext::ValidationRequestInstance]

    # File lib/twilio-ruby/rest/client.rb
538 def validation_requests
539   self.api.v2010.account.validation_requests
540 end
verify() click to toggle source

Access the Verify Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
314 def verify
315   @verify ||= Verify.new self
316 end
video() click to toggle source

Access the Video Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
320 def video
321   @video ||= Video.new self
322 end
voice() click to toggle source

Access the Voice Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
326 def voice
327   @voice ||= Voice.new self
328 end
wireless() click to toggle source

Access the Wireless Twilio Domain

    # File lib/twilio-ruby/rest/client.rb
332 def wireless
333   @wireless ||= Wireless.new self
334 end