Class: Twilio::REST::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio-ruby/rest/client.rb

Overview

A client for accessing the Twilio API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil, account_sid = nil, region = nil, http_client = Twilio::HTTP::Client.new) ⇒ 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
# File 'lib/twilio-ruby/rest/client.rb', line 18

def initialize(username=nil, password=nil, =nil, region=nil, http_client=Twilio::HTTP::Client.new)
  @username = username || Twilio.
  @password = password || Twilio.auth_token
  @region = region
  @account_sid =  || @username
  @auth_token = @password
  @auth = [@username, @password]
  @http_client = http_client

  # Domains
  @accounts = nil
  @api = nil
  @authy = nil
  @autopilot = nil
  @chat = nil
  @fax = nil
  @flex_api = nil
  @insights = nil
  @ip_messaging = nil
  @lookups = nil
  @messaging = nil
  @monitor = nil
  @notify = 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
end

Instance Attribute Details

#account_sidObject

Returns the value of attribute account_sid.



14
15
16
# File 'lib/twilio-ruby/rest/client.rb', line 14

def 
  @account_sid
end

#auth_tokenObject

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_clientObject

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

#passwordObject

Returns the value of attribute password.



14
15
16
# File 'lib/twilio-ruby/rest/client.rb', line 14

def password
  @password
end

#regionObject

Returns the value of attribute region.



14
15
16
# File 'lib/twilio-ruby/rest/client.rb', line 14

def region
  @region
end

#usernameObject

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

#accountsObject

Access the Accounts Twilio Domain



105
106
107
# File 'lib/twilio-ruby/rest/client.rb', line 105

def accounts
  @accounts ||= Accounts.new self
end

#addresses(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AddressInstance, Twilio::REST::Api::V2010::AccountContext::AddressList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the Address resource.

Returns:



258
259
260
# File 'lib/twilio-ruby/rest/client.rb', line 258

def addresses(sid=:unset)
  self.api.v2010..addresses(sid)
end

#apiObject

Access the Api Twilio Domain



111
112
113
# File 'lib/twilio-ruby/rest/client.rb', line 111

def api
  @api ||= Api.new self
end

#applications(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ApplicationInstance, Twilio::REST::Api::V2010::AccountContext::ApplicationList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the Application resource.

Returns:



267
268
269
# File 'lib/twilio-ruby/rest/client.rb', line 267

def applications(sid=:unset)
  self.api.v2010..applications(sid)
end

#authorized_connect_apps(connect_app_sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppInstance, Twilio::REST::Api::V2010::AccountContext::AuthorizedConnectAppList

Parameters:

  • connect_app_sid (String) (defaults to: :unset)

    The SID that we assigned to the Connect App.

Returns:



275
276
277
# File 'lib/twilio-ruby/rest/client.rb', line 275

def authorized_connect_apps(connect_app_sid=:unset)
  self.api.v2010..authorized_connect_apps(connect_app_sid)
end

#authyObject

Access the Authy Twilio Domain



117
118
119
# File 'lib/twilio-ruby/rest/client.rb', line 117

def authy
  @authy ||= Authy.new self
end

#autopilotObject

Access the Autopilot Twilio Domain



123
124
125
# File 'lib/twilio-ruby/rest/client.rb', line 123

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

Parameters:

Returns:



285
286
287
# File 'lib/twilio-ruby/rest/client.rb', line 285

def available_phone_numbers(country_code=:unset)
  self.api.v2010..available_phone_numbers(country_code)
end

#balanceTwilio::REST::Api::V2010::AccountContext::BalanceInstance



291
292
293
# File 'lib/twilio-ruby/rest/client.rb', line 291

def balance
  self.api.v2010..balance
end

#calls(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::CallInstance, Twilio::REST::Api::V2010::AccountContext::CallList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify this Call resource.

Returns:



300
301
302
# File 'lib/twilio-ruby/rest/client.rb', line 300

def calls(sid=:unset)
  self.api.v2010..calls(sid)
end

#chatObject

Access the Chat Twilio Domain



129
130
131
# File 'lib/twilio-ruby/rest/client.rb', line 129

def chat
  @chat ||= Chat.new self
end

#conferences(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ConferenceInstance, Twilio::REST::Api::V2010::AccountContext::ConferenceList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify this Conference resource.

Returns:



309
310
311
# File 'lib/twilio-ruby/rest/client.rb', line 309

def conferences(sid=:unset)
  self.api.v2010..conferences(sid)
end

#connect_apps(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ConnectAppInstance, Twilio::REST::Api::V2010::AccountContext::ConnectAppList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the ConnectApp resource.

Returns:



318
319
320
# File 'lib/twilio-ruby/rest/client.rb', line 318

def connect_apps(sid=:unset)
  self.api.v2010..connect_apps(sid)
end

#faxObject

Access the Fax Twilio Domain



135
136
137
# File 'lib/twilio-ruby/rest/client.rb', line 135

def fax
  @fax ||= Fax.new self
end

#flex_apiObject

Access the FlexApi Twilio Domain



141
142
143
# File 'lib/twilio-ruby/rest/client.rb', line 141

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

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify this IncomingPhoneNumber resource.

Returns:



327
328
329
# File 'lib/twilio-ruby/rest/client.rb', line 327

def incoming_phone_numbers(sid=:unset)
  self.api.v2010..incoming_phone_numbers(sid)
end

#insightsObject

Access the Insights Twilio Domain



147
148
149
# File 'lib/twilio-ruby/rest/client.rb', line 147

def insights
  @insights ||= Insights.new self
end

#ip_messagingObject

Access the IpMessaging Twilio Domain



153
154
155
# File 'lib/twilio-ruby/rest/client.rb', line 153

def ip_messaging
  @ip_messaging ||= IpMessaging.new self
end

#keys(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::KeyInstance, Twilio::REST::Api::V2010::AccountContext::KeyList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the Key resource.

Returns:



336
337
338
# File 'lib/twilio-ruby/rest/client.rb', line 336

def keys(sid=:unset)
  self.api.v2010..keys(sid)
end

#lookupsObject

Access the Lookups Twilio Domain



159
160
161
# File 'lib/twilio-ruby/rest/client.rb', line 159

def lookups
  @lookups ||= Lookups.new self
end

#messages(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::MessageInstance, Twilio::REST::Api::V2010::AccountContext::MessageList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the Message resource.

Returns:



345
346
347
# File 'lib/twilio-ruby/rest/client.rb', line 345

def messages(sid=:unset)
  self.api.v2010..messages(sid)
end

#messagingObject

Access the Messaging Twilio Domain



165
166
167
# File 'lib/twilio-ruby/rest/client.rb', line 165

def messaging
  @messaging ||= Messaging.new self
end

#monitorObject

Access the Monitor Twilio Domain



171
172
173
# File 'lib/twilio-ruby/rest/client.rb', line 171

def monitor
  @monitor ||= Monitor.new self
end

#new_keysTwilio::REST::Api::V2010::AccountContext::NewKeyInstance



351
352
353
# File 'lib/twilio-ruby/rest/client.rb', line 351

def new_keys
  self.api.v2010..new_keys
end

#new_signing_keysTwilio::REST::Api::V2010::AccountContext::NewSigningKeyInstance



357
358
359
# File 'lib/twilio-ruby/rest/client.rb', line 357

def new_signing_keys
  self.api.v2010..new_signing_keys
end

#notifications(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::NotificationInstance, Twilio::REST::Api::V2010::AccountContext::NotificationList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the Notification resource.

Returns:



366
367
368
# File 'lib/twilio-ruby/rest/client.rb', line 366

def notifications(sid=:unset)
  self.api.v2010..notifications(sid)
end

#notifyObject

Access the Notify Twilio Domain



177
178
179
# File 'lib/twilio-ruby/rest/client.rb', line 177

def notify
  @notify ||= Notify.new self
end

#outgoing_caller_ids(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdInstance, Twilio::REST::Api::V2010::AccountContext::OutgoingCallerIdList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the OutgoingCallerId resource.

Returns:



375
376
377
# File 'lib/twilio-ruby/rest/client.rb', line 375

def outgoing_caller_ids(sid=:unset)
  self.api.v2010..outgoing_caller_ids(sid)
end

#previewObject

Access the Preview Twilio Domain



183
184
185
# File 'lib/twilio-ruby/rest/client.rb', line 183

def preview
  @preview ||= Preview.new self
end

#pricingObject

Access the Pricing Twilio Domain



189
190
191
# File 'lib/twilio-ruby/rest/client.rb', line 189

def pricing
  @pricing ||= Pricing.new self
end

#proxyObject

Access the Proxy Twilio Domain



195
196
197
# File 'lib/twilio-ruby/rest/client.rb', line 195

def proxy
  @proxy ||= Proxy.new self
end

#queues(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::QueueInstance, Twilio::REST::Api::V2010::AccountContext::QueueList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify this Queue resource.

Returns:



384
385
386
# File 'lib/twilio-ruby/rest/client.rb', line 384

def queues(sid=:unset)
  self.api.v2010..queues(sid)
end

#recordings(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::RecordingInstance, Twilio::REST::Api::V2010::AccountContext::RecordingList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the Recording resource.

Returns:



393
394
395
# File 'lib/twilio-ruby/rest/client.rb', line 393

def recordings(sid=:unset)
  self.api.v2010..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



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
84
85
86
87
88
89
90
91
92
# File 'lib/twilio-ruby/rest/client.rb', line 58

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

#serverlessObject

Access the Serverless Twilio Domain



201
202
203
# File 'lib/twilio-ruby/rest/client.rb', line 201

def serverless
  @serverless ||= Serverless.new self
end

#short_codes(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::ShortCodeInstance, Twilio::REST::Api::V2010::AccountContext::ShortCodeList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify this ShortCode resource.

Returns:



416
417
418
# File 'lib/twilio-ruby/rest/client.rb', line 416

def short_codes(sid=:unset)
  self.api.v2010..short_codes(sid)
end

#signing_keys(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::SigningKeyInstance, Twilio::REST::Api::V2010::AccountContext::SigningKeyList

Parameters:

  • sid (String) (defaults to: :unset)

    The sid

Returns:



401
402
403
# File 'lib/twilio-ruby/rest/client.rb', line 401

def signing_keys(sid=:unset)
  self.api.v2010..signing_keys(sid)
end

#sipTwilio::REST::Api::V2010::AccountContext::SipInstance



407
408
409
# File 'lib/twilio-ruby/rest/client.rb', line 407

def sip
  self.api.v2010..sip
end

#studioObject

Access the Studio Twilio Domain



207
208
209
# File 'lib/twilio-ruby/rest/client.rb', line 207

def studio
  @studio ||= Studio.new self
end

#syncObject

Access the Sync Twilio Domain



213
214
215
# File 'lib/twilio-ruby/rest/client.rb', line 213

def sync
  @sync ||= Sync.new self
end

#taskrouterObject

Access the Taskrouter Twilio Domain



219
220
221
# File 'lib/twilio-ruby/rest/client.rb', line 219

def taskrouter
  @taskrouter ||= Taskrouter.new self
end

#to_sObject

Provide a user friendly representation



449
450
451
# File 'lib/twilio-ruby/rest/client.rb', line 449

def to_s
  "#<Twilio::REST::Client #{@account_sid}>"
end

#tokensTwilio::REST::Api::V2010::AccountContext::TokenInstance



422
423
424
# File 'lib/twilio-ruby/rest/client.rb', line 422

def tokens
  self.api.v2010..tokens
end

#transcriptions(sid = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::TranscriptionInstance, Twilio::REST::Api::V2010::AccountContext::TranscriptionList

Parameters:

  • sid (String) (defaults to: :unset)

    The unique string that that we created to identify the Transcription resource.

Returns:



431
432
433
# File 'lib/twilio-ruby/rest/client.rb', line 431

def transcriptions(sid=:unset)
  self.api.v2010..transcriptions(sid)
end

#trunkingObject

Access the Trunking Twilio Domain



225
226
227
# File 'lib/twilio-ruby/rest/client.rb', line 225

def trunking
  @trunking ||= Trunking.new self
end

#usageTwilio::REST::Api::V2010::AccountContext::UsageInstance



437
438
439
# File 'lib/twilio-ruby/rest/client.rb', line 437

def usage
  self.api.v2010..usage
end

#validate_ssl_certificateObject

Validate the new SSL certificate for the Twilio API



96
97
98
99
100
101
# File 'lib/twilio-ruby/rest/client.rb', line 96

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_requestsTwilio::REST::Api::V2010::AccountContext::ValidationRequestInstance



443
444
445
# File 'lib/twilio-ruby/rest/client.rb', line 443

def validation_requests
  self.api.v2010..validation_requests
end

#verifyObject

Access the Verify Twilio Domain



231
232
233
# File 'lib/twilio-ruby/rest/client.rb', line 231

def verify
  @verify ||= Verify.new self
end

#videoObject

Access the Video Twilio Domain



237
238
239
# File 'lib/twilio-ruby/rest/client.rb', line 237

def video
  @video ||= Video.new self
end

#voiceObject

Access the Voice Twilio Domain



243
244
245
# File 'lib/twilio-ruby/rest/client.rb', line 243

def voice
  @voice ||= Voice.new self
end

#wirelessObject

Access the Wireless Twilio Domain



249
250
251
# File 'lib/twilio-ruby/rest/client.rb', line 249

def wireless
  @wireless ||= Wireless.new self
end