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
- #available_phone_numbers(country_code = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryInstance, Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryList
- #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
-
#fax ⇒ Object
Access the Fax 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 = Twilio::HTTP::Client.new) ⇒ Client
constructor
Initializes the Twilio Client.
-
#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.
- #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.
- #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.
-
#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
- #validation_requests ⇒ Twilio::REST::Api::V2010::AccountContext::ValidationRequestInstance
-
#video ⇒ Object
Access the Video Twilio Domain.
-
#wireless ⇒ Object
Access the Wireless Twilio Domain.
Constructor Details
#initialize(username = nil, password = nil, account_sid = nil, region = nil, http_client = Twilio::HTTP::Client.new) ⇒ Client
Initializes the Twilio Client
16 17 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 |
# File 'lib/twilio-ruby/rest/client.rb', line 16 def initialize(username=nil, password=nil, account_sid=nil, region=nil, http_client=Twilio::HTTP::Client.new) @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 # Domains @accounts = nil @api = nil @chat = nil @fax = nil @ip_messaging = nil @lookups = nil @monitor = nil @notify = nil @preview = nil @pricing = nil @proxy = nil @taskrouter = nil @trunking = nil @video = nil @messaging = nil @wireless = nil @sync = nil @studio = nil end |
Instance Attribute Details
#account_sid ⇒ Object
Returns the value of attribute account_sid.
12 13 14 |
# File 'lib/twilio-ruby/rest/client.rb', line 12 def account_sid @account_sid end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
12 13 14 |
# File 'lib/twilio-ruby/rest/client.rb', line 12 def auth_token @auth_token end |
#http_client ⇒ Object
Returns the value of attribute http_client.
12 13 14 |
# File 'lib/twilio-ruby/rest/client.rb', line 12 def http_client @http_client end |
#password ⇒ Object
Returns the value of attribute password.
12 13 14 |
# File 'lib/twilio-ruby/rest/client.rb', line 12 def password @password end |
#region ⇒ Object
Returns the value of attribute region.
12 13 14 |
# File 'lib/twilio-ruby/rest/client.rb', line 12 def region @region end |
#username ⇒ Object
Returns the value of attribute username.
12 13 14 |
# File 'lib/twilio-ruby/rest/client.rb', line 12 def username @username end |
Instance Method Details
#accounts ⇒ Object
Access the Accounts Twilio Domain
87 88 89 |
# File 'lib/twilio-ruby/rest/client.rb', line 87 def accounts @accounts ||= Accounts.new self end |
#addresses(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AddressInstance, Twilio::REST::Api::V2010::AccountContext::AddressList
197 198 199 |
# File 'lib/twilio-ruby/rest/client.rb', line 197 def addresses(sid=:unset) self.api.v2010.account.addresses(sid) end |
#api ⇒ Object
Access the Api Twilio Domain
93 94 95 |
# File 'lib/twilio-ruby/rest/client.rb', line 93 def api @api ||= Api.new self end |
#applications(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ApplicationInstance, Twilio::REST::Api::V2010::AccountContext::ApplicationList
206 207 208 |
# File 'lib/twilio-ruby/rest/client.rb', line 206 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
215 216 217 |
# File 'lib/twilio-ruby/rest/client.rb', line 215 def (connect_app_sid=:unset) self.api.v2010.account.(connect_app_sid) end |
#available_phone_numbers(country_code = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryInstance, Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryList
223 224 225 |
# File 'lib/twilio-ruby/rest/client.rb', line 223 def available_phone_numbers(country_code=:unset) self.api.v2010.account.available_phone_numbers(country_code) end |
#calls(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::CallInstance, Twilio::REST::Api::V2010::AccountContext::CallList
232 233 234 |
# File 'lib/twilio-ruby/rest/client.rb', line 232 def calls(sid=:unset) self.api.v2010.account.calls(sid) end |
#chat ⇒ Object
Access the Chat Twilio Domain
99 100 101 |
# File 'lib/twilio-ruby/rest/client.rb', line 99 def chat @chat ||= Chat.new self end |
#conferences(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ConferenceInstance, Twilio::REST::Api::V2010::AccountContext::ConferenceList
241 242 243 |
# File 'lib/twilio-ruby/rest/client.rb', line 241 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
249 250 251 |
# File 'lib/twilio-ruby/rest/client.rb', line 249 def connect_apps(sid=:unset) self.api.v2010.account.connect_apps(sid) end |
#fax ⇒ Object
Access the Fax Twilio Domain
105 106 107 |
# File 'lib/twilio-ruby/rest/client.rb', line 105 def fax @fax ||= Fax.new self end |
#incoming_phone_numbers(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberInstance, Twilio::REST::Api::V2010::AccountContext::IncomingPhoneNumberList
258 259 260 |
# File 'lib/twilio-ruby/rest/client.rb', line 258 def incoming_phone_numbers(sid=:unset) self.api.v2010.account.incoming_phone_numbers(sid) end |
#ip_messaging ⇒ Object
Access the IpMessaging Twilio Domain
111 112 113 |
# File 'lib/twilio-ruby/rest/client.rb', line 111 def ip_messaging @ip_messaging ||= IpMessaging.new self end |
#keys(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::KeyInstance, Twilio::REST::Api::V2010::AccountContext::KeyList
267 268 269 |
# File 'lib/twilio-ruby/rest/client.rb', line 267 def keys(sid=:unset) self.api.v2010.account.keys(sid) end |
#lookups ⇒ Object
Access the Lookups Twilio Domain
117 118 119 |
# File 'lib/twilio-ruby/rest/client.rb', line 117 def lookups @lookups ||= Lookups.new self end |
#messages(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::MessageInstance, Twilio::REST::Api::V2010::AccountContext::MessageList
276 277 278 |
# File 'lib/twilio-ruby/rest/client.rb', line 276 def (sid=:unset) self.api.v2010.account.(sid) end |
#messaging ⇒ Object
Access the Messaging Twilio Domain
171 172 173 |
# File 'lib/twilio-ruby/rest/client.rb', line 171 def messaging @messaging ||= Messaging.new self end |
#monitor ⇒ Object
Access the Monitor Twilio Domain
123 124 125 |
# File 'lib/twilio-ruby/rest/client.rb', line 123 def monitor @monitor ||= Monitor.new self end |
#new_keys ⇒ Twilio::REST::Api::V2010::AccountContext::NewKeyInstance
282 283 284 |
# File 'lib/twilio-ruby/rest/client.rb', line 282 def new_keys self.api.v2010.account.new_keys end |
#new_signing_keys ⇒ Twilio::REST::Api::V2010::AccountContext::NewSigningKeyInstance
288 289 290 |
# File 'lib/twilio-ruby/rest/client.rb', line 288 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
297 298 299 |
# File 'lib/twilio-ruby/rest/client.rb', line 297 def notifications(sid=:unset) self.api.v2010.account.notifications(sid) end |
#notify ⇒ Object
Access the Notify Twilio Domain
129 130 131 |
# File 'lib/twilio-ruby/rest/client.rb', line 129 def notify @notify ||= Notify.new self end |
#outgoing_caller_ids(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdInstance, Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdList
306 307 308 |
# File 'lib/twilio-ruby/rest/client.rb', line 306 def outgoing_caller_ids(sid=:unset) self.api.v2010.account.outgoing_caller_ids(sid) end |
#preview ⇒ Object
Access the Preview Twilio Domain
135 136 137 |
# File 'lib/twilio-ruby/rest/client.rb', line 135 def preview @preview ||= Preview.new self end |
#pricing ⇒ Object
Access the Pricing Twilio Domain
141 142 143 |
# File 'lib/twilio-ruby/rest/client.rb', line 141 def pricing @pricing ||= Pricing.new self end |
#proxy ⇒ Object
Access the Proxy Twilio Domain
147 148 149 |
# File 'lib/twilio-ruby/rest/client.rb', line 147 def proxy @proxy ||= Proxy.new self end |
#queues(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::QueueInstance, Twilio::REST::Api::V2010::AccountContext::QueueList
314 315 316 |
# File 'lib/twilio-ruby/rest/client.rb', line 314 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
323 324 325 |
# File 'lib/twilio-ruby/rest/client.rb', line 323 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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/twilio-ruby/rest/client.rb', line 49 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 |
#short_codes(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ShortCodeInstance, Twilio::REST::Api::V2010::AccountContext::ShortCodeList
346 347 348 |
# File 'lib/twilio-ruby/rest/client.rb', line 346 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
331 332 333 |
# File 'lib/twilio-ruby/rest/client.rb', line 331 def signing_keys(sid=:unset) self.api.v2010.account.signing_keys(sid) end |
#sip ⇒ Twilio::REST::Api::V2010::AccountContext::SipInstance
337 338 339 |
# File 'lib/twilio-ruby/rest/client.rb', line 337 def sip self.api.v2010.account.sip end |
#studio ⇒ Object
Access the Studio Twilio Domain
189 190 191 |
# File 'lib/twilio-ruby/rest/client.rb', line 189 def studio @studio ||= Studio.new self end |
#sync ⇒ Object
Access the Sync Twilio Domain
183 184 185 |
# File 'lib/twilio-ruby/rest/client.rb', line 183 def sync @sync ||= Sync.new self end |
#taskrouter ⇒ Object
Access the Taskrouter Twilio Domain
153 154 155 |
# File 'lib/twilio-ruby/rest/client.rb', line 153 def taskrouter @taskrouter ||= Taskrouter.new self end |
#to_s ⇒ Object
Provide a user friendly representation
379 380 381 |
# File 'lib/twilio-ruby/rest/client.rb', line 379 def to_s "#<Twilio::REST::Client #{@account_sid}>" end |
#tokens ⇒ Twilio::REST::Api::V2010::AccountContext::TokenInstance
352 353 354 |
# File 'lib/twilio-ruby/rest/client.rb', line 352 def tokens self.api.v2010.account.tokens end |
#transcriptions(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::TranscriptionInstance, Twilio::REST::Api::V2010::AccountContext::TranscriptionList
361 362 363 |
# File 'lib/twilio-ruby/rest/client.rb', line 361 def transcriptions(sid=:unset) self.api.v2010.account.transcriptions(sid) end |
#trunking ⇒ Object
Access the Trunking Twilio Domain
159 160 161 |
# File 'lib/twilio-ruby/rest/client.rb', line 159 def trunking @trunking ||= Trunking.new self end |
#usage ⇒ Twilio::REST::Api::V2010::AccountContext::UsageInstance
367 368 369 |
# File 'lib/twilio-ruby/rest/client.rb', line 367 def usage self.api.v2010.account.usage end |
#validation_requests ⇒ Twilio::REST::Api::V2010::AccountContext::ValidationRequestInstance
373 374 375 |
# File 'lib/twilio-ruby/rest/client.rb', line 373 def validation_requests self.api.v2010.account.validation_requests end |
#video ⇒ Object
Access the Video Twilio Domain
165 166 167 |
# File 'lib/twilio-ruby/rest/client.rb', line 165 def video @video ||= Video.new self end |
#wireless ⇒ Object
Access the Wireless Twilio Domain
177 178 179 |
# File 'lib/twilio-ruby/rest/client.rb', line 177 def wireless @wireless ||= Wireless.new self end |