Class: Twilio::REST::Client
- Inherits:
-
Object
- Object
- Twilio::REST::Client
- Defined in:
- lib/twilio-ruby/rest/client.rb
Overview
A client for accessing the Twilio API.
Instance Attribute Summary collapse
-
#account_sid ⇒ Object
Returns the value of attribute account_sid.
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#http_client ⇒ Object
Returns the value of attribute http_client.
-
#password ⇒ Object
Returns the value of attribute password.
-
#region ⇒ Object
Returns the value of attribute region.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#accounts ⇒ Object
Access the Accounts Twilio Domain.
- #addresses(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AddressInstance, Twilio::REST::Api::V2010::AccountContext::AddressList
-
#api ⇒ Object
Access the Api Twilio Domain.
- #applications(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ApplicationInstance, Twilio::REST::Api::V2010::AccountContext::ApplicationList
- #authorized_connect_apps(connect_app_sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppInstance, Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppList
-
#authy ⇒ Object
Access the Authy Twilio Domain.
-
#autopilot ⇒ Object
Access the Autopilot Twilio Domain.
- #available_phone_numbers(country_code = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryInstance, Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryList
- #balance ⇒ Twilio::REST::Api::V2010::AccountContext::BalanceInstance
-
#bulkexports ⇒ Object
Access the Bulkexports Twilio Domain.
- #calls(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::CallInstance, Twilio::REST::Api::V2010::AccountContext::CallList
-
#chat ⇒ Object
Access the Chat Twilio Domain.
- #conferences(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ConferenceInstance, Twilio::REST::Api::V2010::AccountContext::ConferenceList
- #connect_apps(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ConnectAppInstance, Twilio::REST::Api::V2010::AccountContext::ConnectAppList
-
#conversations ⇒ Object
Access the Conversations Twilio Domain.
-
#fax ⇒ Object
Access the Fax Twilio Domain.
-
#flex_api ⇒ Object
Access the FlexApi Twilio Domain.
- #incoming_phone_numbers(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberInstance, Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberList
-
#initialize(username = nil, password = nil, account_sid = nil, region = nil, http_client = nil) ⇒ Client
constructor
Initializes the Twilio Client.
-
#insights ⇒ Object
Access the Insights Twilio Domain.
-
#ip_messaging ⇒ Object
Access the IpMessaging Twilio Domain.
- #keys(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::KeyInstance, Twilio::REST::Api::V2010::AccountContext::KeyList
-
#lookups ⇒ Object
Access the Lookups Twilio Domain.
- #messages(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::MessageInstance, Twilio::REST::Api::V2010::AccountContext::MessageList
-
#messaging ⇒ Object
Access the Messaging Twilio Domain.
-
#monitor ⇒ Object
Access the Monitor Twilio Domain.
- #new_keys ⇒ Twilio::REST::Api::V2010::AccountContext::NewKeyInstance
- #new_signing_keys ⇒ Twilio::REST::Api::V2010::AccountContext::NewSigningKeyInstance
- #notifications(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::NotificationInstance, Twilio::REST::Api::V2010::AccountContext::NotificationList
-
#notify ⇒ Object
Access the Notify Twilio Domain.
-
#numbers ⇒ Object
Access the Numbers Twilio Domain.
- #outgoing_caller_ids(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdInstance, Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdList
-
#preview ⇒ Object
Access the Preview Twilio Domain.
-
#pricing ⇒ Object
Access the Pricing Twilio Domain.
-
#proxy ⇒ Object
Access the Proxy Twilio Domain.
- #queues(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::QueueInstance, Twilio::REST::Api::V2010::AccountContext::QueueList
- #recordings(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::RecordingInstance, Twilio::REST::Api::V2010::AccountContext::RecordingList
-
#request(host, port, method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
Makes a request to the Twilio API using the configured http client Authentication information is automatically added if none is provided.
-
#serverless ⇒ Object
Access the Serverless Twilio Domain.
- #short_codes(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ShortCodeInstance, Twilio::REST::Api::V2010::AccountContext::ShortCodeList
- #signing_keys(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::SigningKeyInstance, Twilio::REST::Api::V2010::AccountContext::SigningKeyList
- #sip ⇒ Twilio::REST::Api::V2010::AccountContext::SipInstance
-
#studio ⇒ Object
Access the Studio Twilio Domain.
-
#supersim ⇒ Object
Access the Supersim Twilio Domain.
-
#sync ⇒ Object
Access the Sync Twilio Domain.
-
#taskrouter ⇒ Object
Access the Taskrouter Twilio Domain.
-
#to_s ⇒ Object
Provide a user friendly representation.
- #tokens ⇒ Twilio::REST::Api::V2010::AccountContext::TokenInstance
- #transcriptions(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::TranscriptionInstance, Twilio::REST::Api::V2010::AccountContext::TranscriptionList
-
#trunking ⇒ Object
Access the Trunking Twilio Domain.
- #usage ⇒ Twilio::REST::Api::V2010::AccountContext::UsageInstance
-
#validate_ssl_certificate ⇒ Object
Validate the new SSL certificate for the Twilio API.
- #validation_requests ⇒ Twilio::REST::Api::V2010::AccountContext::ValidationRequestInstance
-
#verify ⇒ Object
Access the Verify Twilio Domain.
-
#video ⇒ Object
Access the Video Twilio Domain.
-
#voice ⇒ Object
Access the Voice Twilio Domain.
-
#wireless ⇒ Object
Access the Wireless Twilio Domain.
Constructor Details
#initialize(username = nil, password = nil, account_sid = nil, region = nil, http_client = nil) ⇒ Client
Initializes the Twilio Client
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/twilio-ruby/rest/client.rb', line 18 def initialize(username=nil, password=nil, account_sid=nil, region=nil, http_client=nil) @username = username || Twilio.account_sid @password = password || Twilio.auth_token @region = region @account_sid = account_sid || @username @auth_token = @password @auth = [@username, @password] @http_client = http_client || Twilio.http_client || Twilio::HTTP::Client.new # Domains @accounts = nil @api = nil @authy = nil @autopilot = nil @chat = nil @conversations = nil @fax = nil @flex_api = nil @insights = nil @ip_messaging = nil @lookups = nil @messaging = nil @monitor = nil @notify = nil @numbers = nil @preview = nil @pricing = nil @proxy = nil @serverless = nil @studio = nil @sync = nil @taskrouter = nil @trunking = nil @verify = nil @video = nil @voice = nil @wireless = nil @supersim = nil @bulkexports = nil end |
Instance Attribute Details
#account_sid ⇒ Object
Returns the value of attribute account_sid.
14 15 16 |
# File 'lib/twilio-ruby/rest/client.rb', line 14 def account_sid @account_sid end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
14 15 16 |
# File 'lib/twilio-ruby/rest/client.rb', line 14 def auth_token @auth_token end |
#http_client ⇒ Object
Returns the value of attribute http_client.
14 15 16 |
# File 'lib/twilio-ruby/rest/client.rb', line 14 def http_client @http_client end |
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/twilio-ruby/rest/client.rb', line 14 def password @password end |
#region ⇒ Object
Returns the value of attribute region.
14 15 16 |
# File 'lib/twilio-ruby/rest/client.rb', line 14 def region @region end |
#username ⇒ Object
Returns the value of attribute username.
14 15 16 |
# File 'lib/twilio-ruby/rest/client.rb', line 14 def username @username end |
Instance Method Details
#accounts ⇒ Object
Access the Accounts Twilio Domain
109 110 111 |
# File 'lib/twilio-ruby/rest/client.rb', line 109 def accounts @accounts ||= Accounts.new self end |
#addresses(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AddressInstance, Twilio::REST::Api::V2010::AccountContext::AddressList
286 287 288 |
# File 'lib/twilio-ruby/rest/client.rb', line 286 def addresses(sid=:unset) self.api.v2010.account.addresses(sid) end |
#api ⇒ Object
Access the Api Twilio Domain
115 116 117 |
# File 'lib/twilio-ruby/rest/client.rb', line 115 def api @api ||= Api.new self end |
#applications(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ApplicationInstance, Twilio::REST::Api::V2010::AccountContext::ApplicationList
295 296 297 |
# File 'lib/twilio-ruby/rest/client.rb', line 295 def applications(sid=:unset) self.api.v2010.account.applications(sid) end |
#authorized_connect_apps(connect_app_sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppInstance, Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppList
303 304 305 |
# File 'lib/twilio-ruby/rest/client.rb', line 303 def (connect_app_sid=:unset) self.api.v2010.account.(connect_app_sid) end |
#authy ⇒ Object
Access the Authy Twilio Domain
121 122 123 |
# File 'lib/twilio-ruby/rest/client.rb', line 121 def authy @authy ||= Authy.new self end |
#autopilot ⇒ Object
Access the Autopilot Twilio Domain
127 128 129 |
# File 'lib/twilio-ruby/rest/client.rb', line 127 def autopilot @autopilot ||= Autopilot.new self end |
#available_phone_numbers(country_code = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryInstance, Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryList
313 314 315 |
# File 'lib/twilio-ruby/rest/client.rb', line 313 def available_phone_numbers(country_code=:unset) self.api.v2010.account.available_phone_numbers(country_code) end |
#balance ⇒ Twilio::REST::Api::V2010::AccountContext::BalanceInstance
319 320 321 |
# File 'lib/twilio-ruby/rest/client.rb', line 319 def balance self.api.v2010.account.balance end |
#bulkexports ⇒ Object
Access the Bulkexports Twilio Domain
277 278 279 |
# File 'lib/twilio-ruby/rest/client.rb', line 277 def bulkexports @bulkexports ||= Bulkexports.new self end |
#calls(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::CallInstance, Twilio::REST::Api::V2010::AccountContext::CallList
328 329 330 |
# File 'lib/twilio-ruby/rest/client.rb', line 328 def calls(sid=:unset) self.api.v2010.account.calls(sid) end |
#chat ⇒ Object
Access the Chat Twilio Domain
133 134 135 |
# File 'lib/twilio-ruby/rest/client.rb', line 133 def chat @chat ||= Chat.new self end |
#conferences(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ConferenceInstance, Twilio::REST::Api::V2010::AccountContext::ConferenceList
337 338 339 |
# File 'lib/twilio-ruby/rest/client.rb', line 337 def conferences(sid=:unset) self.api.v2010.account.conferences(sid) end |
#connect_apps(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ConnectAppInstance, Twilio::REST::Api::V2010::AccountContext::ConnectAppList
346 347 348 |
# File 'lib/twilio-ruby/rest/client.rb', line 346 def connect_apps(sid=:unset) self.api.v2010.account.connect_apps(sid) end |
#conversations ⇒ Object
Access the Conversations Twilio Domain
139 140 141 |
# File 'lib/twilio-ruby/rest/client.rb', line 139 def conversations @conversations ||= Conversations.new self end |
#fax ⇒ Object
Access the Fax Twilio Domain
145 146 147 |
# File 'lib/twilio-ruby/rest/client.rb', line 145 def fax @fax ||= Fax.new self end |
#flex_api ⇒ Object
Access the FlexApi Twilio Domain
151 152 153 |
# File 'lib/twilio-ruby/rest/client.rb', line 151 def flex_api @flex_api ||= FlexApi.new self end |
#incoming_phone_numbers(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberInstance, Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberList
355 356 357 |
# File 'lib/twilio-ruby/rest/client.rb', line 355 def incoming_phone_numbers(sid=:unset) self.api.v2010.account.incoming_phone_numbers(sid) end |
#insights ⇒ Object
Access the Insights Twilio Domain
157 158 159 |
# File 'lib/twilio-ruby/rest/client.rb', line 157 def insights @insights ||= Insights.new self end |
#ip_messaging ⇒ Object
Access the IpMessaging Twilio Domain
163 164 165 |
# File 'lib/twilio-ruby/rest/client.rb', line 163 def ip_messaging @ip_messaging ||= IpMessaging.new self end |
#keys(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::KeyInstance, Twilio::REST::Api::V2010::AccountContext::KeyList
364 365 366 |
# File 'lib/twilio-ruby/rest/client.rb', line 364 def keys(sid=:unset) self.api.v2010.account.keys(sid) end |
#lookups ⇒ Object
Access the Lookups Twilio Domain
169 170 171 |
# File 'lib/twilio-ruby/rest/client.rb', line 169 def lookups @lookups ||= Lookups.new self end |
#messages(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::MessageInstance, Twilio::REST::Api::V2010::AccountContext::MessageList
373 374 375 |
# File 'lib/twilio-ruby/rest/client.rb', line 373 def (sid=:unset) self.api.v2010.account.(sid) end |
#messaging ⇒ Object
Access the Messaging Twilio Domain
175 176 177 |
# File 'lib/twilio-ruby/rest/client.rb', line 175 def messaging @messaging ||= Messaging.new self end |
#monitor ⇒ Object
Access the Monitor Twilio Domain
181 182 183 |
# File 'lib/twilio-ruby/rest/client.rb', line 181 def monitor @monitor ||= Monitor.new self end |
#new_keys ⇒ Twilio::REST::Api::V2010::AccountContext::NewKeyInstance
379 380 381 |
# File 'lib/twilio-ruby/rest/client.rb', line 379 def new_keys self.api.v2010.account.new_keys end |
#new_signing_keys ⇒ Twilio::REST::Api::V2010::AccountContext::NewSigningKeyInstance
385 386 387 |
# File 'lib/twilio-ruby/rest/client.rb', line 385 def new_signing_keys self.api.v2010.account.new_signing_keys end |
#notifications(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::NotificationInstance, Twilio::REST::Api::V2010::AccountContext::NotificationList
394 395 396 |
# File 'lib/twilio-ruby/rest/client.rb', line 394 def notifications(sid=:unset) self.api.v2010.account.notifications(sid) end |
#notify ⇒ Object
Access the Notify Twilio Domain
187 188 189 |
# File 'lib/twilio-ruby/rest/client.rb', line 187 def notify @notify ||= Notify.new self end |
#numbers ⇒ Object
Access the Numbers Twilio Domain
193 194 195 |
# File 'lib/twilio-ruby/rest/client.rb', line 193 def numbers @numbers ||= Numbers.new self end |
#outgoing_caller_ids(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdInstance, Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdList
403 404 405 |
# File 'lib/twilio-ruby/rest/client.rb', line 403 def outgoing_caller_ids(sid=:unset) self.api.v2010.account.outgoing_caller_ids(sid) end |
#preview ⇒ Object
Access the Preview Twilio Domain
199 200 201 |
# File 'lib/twilio-ruby/rest/client.rb', line 199 def preview @preview ||= Preview.new self end |
#pricing ⇒ Object
Access the Pricing Twilio Domain
205 206 207 |
# File 'lib/twilio-ruby/rest/client.rb', line 205 def pricing @pricing ||= Pricing.new self end |
#proxy ⇒ Object
Access the Proxy Twilio Domain
211 212 213 |
# File 'lib/twilio-ruby/rest/client.rb', line 211 def proxy @proxy ||= Proxy.new self end |
#queues(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::QueueInstance, Twilio::REST::Api::V2010::AccountContext::QueueList
412 413 414 |
# File 'lib/twilio-ruby/rest/client.rb', line 412 def queues(sid=:unset) self.api.v2010.account.queues(sid) end |
#recordings(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::RecordingInstance, Twilio::REST::Api::V2010::AccountContext::RecordingList
421 422 423 |
# File 'lib/twilio-ruby/rest/client.rb', line 421 def recordings(sid=:unset) self.api.v2010.account.recordings(sid) end |
#request(host, port, method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
Makes a request to the Twilio API using the configured http client Authentication information is automatically added if none is provided
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/twilio-ruby/rest/client.rb', line 62 def request(host, port, method, uri, params={}, data={}, headers={}, auth=nil, timeout=nil) auth ||= @auth headers['User-Agent'] = "twilio-ruby/#{Twilio::VERSION}" + " (#{RUBY_ENGINE}/#{RUBY_PLATFORM}" + " #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})" headers['Accept-Charset'] = 'utf-8' if method == 'POST' && !headers['Content-Type'] headers['Content-Type'] = 'application/x-www-form-urlencoded' end unless headers['Accept'] headers['Accept'] = 'application/json' end if !region.nil? head, tail = uri.split('.', 2) if !tail.start_with?(region) uri = [head, region, tail].join('.') end end @http_client.request( host, port, method, uri, params, data, headers, auth, timeout ) end |
#serverless ⇒ Object
Access the Serverless Twilio Domain
217 218 219 |
# File 'lib/twilio-ruby/rest/client.rb', line 217 def serverless @serverless ||= Serverless.new self end |
#short_codes(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ShortCodeInstance, Twilio::REST::Api::V2010::AccountContext::ShortCodeList
444 445 446 |
# File 'lib/twilio-ruby/rest/client.rb', line 444 def short_codes(sid=:unset) self.api.v2010.account.short_codes(sid) end |
#signing_keys(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::SigningKeyInstance, Twilio::REST::Api::V2010::AccountContext::SigningKeyList
429 430 431 |
# File 'lib/twilio-ruby/rest/client.rb', line 429 def signing_keys(sid=:unset) self.api.v2010.account.signing_keys(sid) end |
#sip ⇒ Twilio::REST::Api::V2010::AccountContext::SipInstance
435 436 437 |
# File 'lib/twilio-ruby/rest/client.rb', line 435 def sip self.api.v2010.account.sip end |
#studio ⇒ Object
Access the Studio Twilio Domain
223 224 225 |
# File 'lib/twilio-ruby/rest/client.rb', line 223 def studio @studio ||= Studio.new self end |
#supersim ⇒ Object
Access the Supersim Twilio Domain
271 272 273 |
# File 'lib/twilio-ruby/rest/client.rb', line 271 def supersim @supersim ||= Supersim.new self end |
#sync ⇒ Object
Access the Sync Twilio Domain
229 230 231 |
# File 'lib/twilio-ruby/rest/client.rb', line 229 def sync @sync ||= Sync.new self end |
#taskrouter ⇒ Object
Access the Taskrouter Twilio Domain
235 236 237 |
# File 'lib/twilio-ruby/rest/client.rb', line 235 def taskrouter @taskrouter ||= Taskrouter.new self end |
#to_s ⇒ Object
Provide a user friendly representation
477 478 479 |
# File 'lib/twilio-ruby/rest/client.rb', line 477 def to_s "#<Twilio::REST::Client #{@account_sid}>" end |
#tokens ⇒ Twilio::REST::Api::V2010::AccountContext::TokenInstance
450 451 452 |
# File 'lib/twilio-ruby/rest/client.rb', line 450 def tokens self.api.v2010.account.tokens end |
#transcriptions(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::TranscriptionInstance, Twilio::REST::Api::V2010::AccountContext::TranscriptionList
459 460 461 |
# File 'lib/twilio-ruby/rest/client.rb', line 459 def transcriptions(sid=:unset) self.api.v2010.account.transcriptions(sid) end |
#trunking ⇒ Object
Access the Trunking Twilio Domain
241 242 243 |
# File 'lib/twilio-ruby/rest/client.rb', line 241 def trunking @trunking ||= Trunking.new self end |
#usage ⇒ Twilio::REST::Api::V2010::AccountContext::UsageInstance
465 466 467 |
# File 'lib/twilio-ruby/rest/client.rb', line 465 def usage self.api.v2010.account.usage end |
#validate_ssl_certificate ⇒ Object
Validate the new SSL certificate for the Twilio API
100 101 102 103 104 105 |
# File 'lib/twilio-ruby/rest/client.rb', line 100 def validate_ssl_certificate response = request('api.twilio.com', '8443', 'GET', 'https://api.twilio.com:8443/.json') if response.status_code < 200 || response.status_code >= 300 raise RestError.new 'Unexpected response from certificate endpoint', response end end |
#validation_requests ⇒ Twilio::REST::Api::V2010::AccountContext::ValidationRequestInstance
471 472 473 |
# File 'lib/twilio-ruby/rest/client.rb', line 471 def validation_requests self.api.v2010.account.validation_requests end |
#verify ⇒ Object
Access the Verify Twilio Domain
247 248 249 |
# File 'lib/twilio-ruby/rest/client.rb', line 247 def verify @verify ||= Verify.new self end |
#video ⇒ Object
Access the Video Twilio Domain
253 254 255 |
# File 'lib/twilio-ruby/rest/client.rb', line 253 def video @video ||= Video.new self end |