class Twilio::REST::Client
A client for accessing the Twilio
API.
Attributes
Public Class Methods
# 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
@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
@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
@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
@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 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
Access the Bulkexports
Twilio
Domain
# File lib/twilio-ruby/rest/client.rb 344 def bulkexports 345 @bulkexports ||= Bulkexports.new self 346 end
@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
@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
@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
Access the Conversations
Twilio
Domain
# File lib/twilio-ruby/rest/client.rb 188 def conversations 189 @conversations ||= Conversations.new self 190 end
Access the FrontlineApi
Twilio
Domain
# File lib/twilio-ruby/rest/client.rb 212 def frontline_api 213 @frontline_api ||= FrontlineApi.new self 214 end
@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
Access the IpMessaging
Twilio
Domain
# File lib/twilio-ruby/rest/client.rb 224 def ip_messaging 225 @ip_messaging ||= IpMessaging.new self 226 end
@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
@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
@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
@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
@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
@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
@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
@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
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
Access the Serverless
Twilio
Domain
# File lib/twilio-ruby/rest/client.rb 278 def serverless 279 @serverless ||= Serverless.new self 280 end
@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
@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
@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
Access the Taskrouter
Twilio
Domain
# File lib/twilio-ruby/rest/client.rb 296 def taskrouter 297 @taskrouter ||= Taskrouter.new self 298 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/client.rb 544 def to_s 545 "#<Twilio::REST::Client #{@account_sid}>" 546 end
@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
@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
@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 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
@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