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



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
# File 'lib/twilio-ruby/rest/client.rb', line 16

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
  @chat = nil
  @fax = nil
  @ip_messaging = nil
  @lookups = nil
  @monitor = nil
  @notify = nil
  @preview = nil
  @pricing = nil
  @taskrouter = nil
  @trunking = nil
  @video = nil
  @messaging = nil
  @wireless = nil
  @sync = nil
end

Instance Attribute Details

#account_sidObject

Returns the value of attribute account_sid.



12
13
14
# File 'lib/twilio-ruby/rest/client.rb', line 12

def 
  @account_sid
end

#auth_tokenObject

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_clientObject

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

#passwordObject

Returns the value of attribute password.



12
13
14
# File 'lib/twilio-ruby/rest/client.rb', line 12

def password
  @password
end

#regionObject

Returns the value of attribute region.



12
13
14
# File 'lib/twilio-ruby/rest/client.rb', line 12

def region
  @region
end

#usernameObject

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

#accountsObject

Access the Accounts Twilio Domain



85
86
87
# File 'lib/twilio-ruby/rest/client.rb', line 85

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 sid

Returns:



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

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

#apiObject

Access the Api Twilio Domain



91
92
93
# File 'lib/twilio-ruby/rest/client.rb', line 91

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)

    A 34 character string that uniquely identifies this resource.

Returns:



192
193
194
# File 'lib/twilio-ruby/rest/client.rb', line 192

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 unique id of the Connect App that was authorized.

Returns:



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

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

#available_phone_numbers(country_code = :unset) ⇒ Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryInstance, Twilio::REST::Api::V2010::AccountContext::AvailablePhoneNumberCountryList

Parameters:

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

    The ISO Country code to lookup phone numbers for.

Returns:



209
210
211
# File 'lib/twilio-ruby/rest/client.rb', line 209

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

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

Parameters:

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

    A 34 character string that uniquely identifies this resource.

Returns:



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

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

#chatObject

Access the Chat Twilio Domain



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

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)

    A 34 character string that uniquely identifies this conference.

Returns:



227
228
229
# File 'lib/twilio-ruby/rest/client.rb', line 227

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 id of this Connect App.

Returns:



235
236
237
# File 'lib/twilio-ruby/rest/client.rb', line 235

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

#faxObject

Access the Fax Twilio Domain



103
104
105
# File 'lib/twilio-ruby/rest/client.rb', line 103

def fax
  @fax ||= Fax.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)

    A 34 character string that uniquely identifies this resource.

Returns:



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

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

#ip_messagingObject

Access the IpMessaging Twilio Domain



109
110
111
# File 'lib/twilio-ruby/rest/client.rb', line 109

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 sid

Returns:



252
253
254
# File 'lib/twilio-ruby/rest/client.rb', line 252

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

#lookupsObject

Access the Lookups Twilio Domain



115
116
117
# File 'lib/twilio-ruby/rest/client.rb', line 115

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)

    A 34 character string that uniquely identifies this resource.

Returns:



261
262
263
# File 'lib/twilio-ruby/rest/client.rb', line 261

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

#messagingObject

Access the Messaging Twilio Domain



163
164
165
# File 'lib/twilio-ruby/rest/client.rb', line 163

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

#monitorObject

Access the Monitor Twilio Domain



121
122
123
# File 'lib/twilio-ruby/rest/client.rb', line 121

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

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



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

def new_keys
  self.api.v2010..new_keys
end

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



273
274
275
# File 'lib/twilio-ruby/rest/client.rb', line 273

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)

    A 34 character string that uniquely identifies this resource.

Returns:



282
283
284
# File 'lib/twilio-ruby/rest/client.rb', line 282

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

#notifyObject

Access the Notify Twilio Domain



127
128
129
# File 'lib/twilio-ruby/rest/client.rb', line 127

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)

    A 34 character string that uniquely identifies this resource.

Returns:



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

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

#previewObject

Access the Preview Twilio Domain



133
134
135
# File 'lib/twilio-ruby/rest/client.rb', line 133

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

#pricingObject

Access the Pricing Twilio Domain



139
140
141
# File 'lib/twilio-ruby/rest/client.rb', line 139

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

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

Parameters:

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

    A 34 character string that uniquely identifies this queue.

Returns:



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

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)

    A 34 character string that uniquely identifies this resource.

Returns:



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

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



47
48
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
# File 'lib/twilio-ruby/rest/client.rb', line 47

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

Parameters:

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

    A 34 character string that uniquely identifies this resource.

Returns:



331
332
333
# File 'lib/twilio-ruby/rest/client.rb', line 331

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:



316
317
318
# File 'lib/twilio-ruby/rest/client.rb', line 316

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

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



322
323
324
# File 'lib/twilio-ruby/rest/client.rb', line 322

def sip
  self.api.v2010..sip
end

#syncObject

Access the Sync Twilio Domain



175
176
177
# File 'lib/twilio-ruby/rest/client.rb', line 175

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

#taskrouterObject

Access the Taskrouter Twilio Domain



145
146
147
# File 'lib/twilio-ruby/rest/client.rb', line 145

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

#to_sObject

Provide a user friendly representation



364
365
366
# File 'lib/twilio-ruby/rest/client.rb', line 364

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

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



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

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)

    A 34 character string that uniquely identifies this resource.

Returns:



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

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

#trunkingObject

Access the Trunking Twilio Domain



151
152
153
# File 'lib/twilio-ruby/rest/client.rb', line 151

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

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



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

def usage
  self.api.v2010..usage
end

#validation_requestsTwilio::REST::Api::V2010::AccountContext::ValidationRequestInstance



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

def validation_requests
  self.api.v2010..validation_requests
end

#videoObject

Access the Video Twilio Domain



157
158
159
# File 'lib/twilio-ruby/rest/client.rb', line 157

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

#wirelessObject

Access the Wireless Twilio Domain



169
170
171
# File 'lib/twilio-ruby/rest/client.rb', line 169

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