twilio-ruby 3.15.2 → 3.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55ea3eb8f942cafe675c70aad8fa1ff5bf3836bf
4
- data.tar.gz: b2dfc49ca27752b0e6bc87f8e7c5fc9095251627
3
+ metadata.gz: e89894997e17d49541145a1f4ca4a95e2960e8f5
4
+ data.tar.gz: 4f0e819ab0fe41e01c0e7823178180cc565ac573
5
5
  SHA512:
6
- metadata.gz: 7df8d0e86f338607a6696a0defeda6283a5055870feccf48f15f47754a92e7e32a42961d9c7acdce974595511e1f1831034251f27aadfd0514eb41daea0b6489
7
- data.tar.gz: a9e7eeea7956069958f186b2c62811283680db576cb0479b1b835c31826a94804f9aa1ce622d42661ef73a30f9c980b3e390dfbbe98f88f597b2c215c0c52fe1
6
+ metadata.gz: 24e2db1a0a70571578cb9916cf7888b82e4970282b0d6b3761d6b814a8091fa1e76ee358b735c247611e8d38e916c84508fb7e5d6ebba801b1daa80521dc494e
7
+ data.tar.gz: 84f0fda6bf321cf575d7fb28ec42a24b58f9191b4fbaae5322e776bc2047d78b833f3d4c5f5379f15f5c75bc1deb4ec91bd46289743458c4408d7c175829a545
data/CHANGES.md CHANGED
@@ -1,6 +1,14 @@
1
1
  twilio-ruby changelog
2
2
  =====================
3
3
 
4
+ Version 3.16.0
5
+ --------------
6
+
7
+ Released March 31, 2015
8
+
9
+ - Add support for new Twilio Lookups API
10
+ - Update LICENSE wording
11
+
4
12
  Version 3.15.2
5
13
  --------------
6
14
 
data/lib/twilio-ruby.rb CHANGED
@@ -49,6 +49,7 @@ require 'twilio-ruby/rest/task_router/workflow_statistics'
49
49
  require 'twilio-ruby/rest/task_router/workflows'
50
50
  require 'twilio-ruby/rest/task_router/workspaces'
51
51
  require 'twilio-ruby/rest/task_router/workspace_statistics'
52
+ require 'twilio-ruby/rest/lookups/phone_numbers'
52
53
  require 'twilio-ruby/rest/media'
53
54
  require 'twilio-ruby/rest/messages'
54
55
  require 'twilio-ruby/rest/applications'
@@ -78,6 +79,8 @@ require 'twilio-ruby/rest/notifications'
78
79
  require 'twilio-ruby/rest/addresses'
79
80
  require 'twilio-ruby/rest/addresses/dependent_phone_numbers'
80
81
  require 'twilio-ruby/rest/client'
82
+ require 'twilio-ruby/rest/task_router_client'
83
+ require 'twilio-ruby/rest/lookups_client'
81
84
  require 'rack/twilio_webhook_authentication'
82
85
 
83
86
  module Twilio
@@ -0,0 +1,140 @@
1
+ module Twilio
2
+ module REST
3
+ class BaseClient
4
+ include Twilio::Util
5
+ include Twilio::REST::Utils
6
+
7
+ HTTP_HEADERS = {
8
+ 'Accept' => 'application/json',
9
+ 'Accept-Charset' => 'utf-8',
10
+ 'User-Agent' => "twilio-ruby/#{Twilio::VERSION}" \
11
+ " (#{RUBY_ENGINE}/#{RUBY_PLATFORM}" \
12
+ " #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})"
13
+ }
14
+
15
+ DEFAULTS = {
16
+ host: 'api.twilio.com',
17
+ port: 443,
18
+ use_ssl: true,
19
+ ssl_verify_peer: true,
20
+ ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem',
21
+ timeout: 30,
22
+ proxy_addr: nil,
23
+ proxy_port: nil,
24
+ proxy_user: nil,
25
+ proxy_pass: nil,
26
+ retry_limit: 1
27
+ }
28
+
29
+ attr_reader :account_sid, :last_request, :last_response
30
+
31
+ def initialize(*args)
32
+ options = args.last.is_a?(Hash) ? args.pop : {}
33
+ @config = get_defaults.merge! options
34
+
35
+ @account_sid = args[0] || Twilio.account_sid
36
+ @auth_token = args[1] || Twilio.auth_token
37
+ if @account_sid.nil? || @auth_token.nil?
38
+ raise ArgumentError, 'Account SID and auth token are required'
39
+ end
40
+
41
+ set_up_connection
42
+ set_up_subresources
43
+ end
44
+
45
+ ##
46
+ # Define #get, #put, #post and #delete helper methods for sending HTTP
47
+ # requests to Twilio. You shouldn't need to use these methods directly,
48
+ # but they can be useful for debugging. Each method returns a hash
49
+ # obtained from parsing the JSON object in the response body.
50
+ [:get, :put, :post, :delete].each do |method|
51
+ method_class = Net::HTTP.const_get method.to_s.capitalize
52
+ define_method method do |path, *args|
53
+ params = twilify(args[0])
54
+ params = {} if params.empty?
55
+ # build the full path unless already given
56
+ path = build_full_path(path, params, method) unless args[1]
57
+ request = method_class.new(path, HTTP_HEADERS)
58
+ request.basic_auth(@account_sid, @auth_token)
59
+ request.form_data = params if [:post, :put].include?(method)
60
+ connect_and_send(request)
61
+ end
62
+ end
63
+
64
+ protected
65
+
66
+ ##
67
+ # Get the default config values.
68
+ def get_defaults
69
+ # To be overridden
70
+ DEFAULTS
71
+ end
72
+
73
+ ##
74
+ # Builds up full request path
75
+ # Needs implementation in child classes
76
+ def build_full_path(path, params, method)
77
+ raise NotImplementedError
78
+ end
79
+
80
+ ##
81
+ # Set up and cache a Net::HTTP object to use when making requests. This is
82
+ # a private method documented for completeness.
83
+ def set_up_connection # :doc:
84
+ connection_class = Net::HTTP::Proxy @config[:proxy_addr],
85
+ @config[:proxy_port], @config[:proxy_user], @config[:proxy_pass]
86
+ @connection = connection_class.new @config[:host], @config[:port]
87
+ set_up_ssl
88
+ @connection.open_timeout = @config[:timeout]
89
+ @connection.read_timeout = @config[:timeout]
90
+ end
91
+
92
+ ##
93
+ # Set up the ssl properties of the <tt>@connection</tt> Net::HTTP object.
94
+ # This is a private method documented for completeness.
95
+ def set_up_ssl # :doc:
96
+ @connection.use_ssl = @config[:use_ssl]
97
+ if @config[:ssl_verify_peer]
98
+ @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
99
+ @connection.ca_file = @config[:ssl_ca_file]
100
+ else
101
+ @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
102
+ end
103
+ end
104
+
105
+ ##
106
+ # Set up sub resources attributes.
107
+ def set_up_subresources # :doc:
108
+ # To be overridden
109
+ end
110
+
111
+ ##
112
+ # Send an HTTP request using the cached <tt>@connection</tt> object and
113
+ # return the JSON response body parsed into a hash. Also save the raw
114
+ # Net::HTTP::Request and Net::HTTP::Response objects as
115
+ # <tt>@last_request</tt> and <tt>@last_response</tt> to allow for
116
+ # inspection later.
117
+ def connect_and_send(request) # :doc:
118
+ @last_request = request
119
+ retries_left = @config[:retry_limit]
120
+ begin
121
+ response = @connection.request request
122
+ @last_response = response
123
+ if response.kind_of? Net::HTTPServerError
124
+ raise Twilio::REST::ServerError
125
+ end
126
+ rescue Exception
127
+ raise if request.class == Net::HTTP::Post
128
+ if retries_left > 0 then retries_left -= 1; retry else raise end
129
+ end
130
+ if response.body and !response.body.empty?
131
+ object = MultiJson.load response.body
132
+ end
133
+ if response.kind_of? Net::HTTPClientError
134
+ raise Twilio::REST::RequestError.new object['message'], object['code']
135
+ end
136
+ object
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,116 +1,6 @@
1
+ require 'twilio-ruby/rest/base_client'
1
2
  module Twilio
2
3
  module REST
3
- class BaseClient
4
- include Twilio::Util
5
- include Twilio::REST::Utils
6
-
7
- HTTP_HEADERS = {
8
- 'Accept' => 'application/json',
9
- 'Accept-Charset' => 'utf-8',
10
- 'User-Agent' => "twilio-ruby/#{Twilio::VERSION}" \
11
- " (#{RUBY_ENGINE}/#{RUBY_PLATFORM}" \
12
- " #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})"
13
- }
14
-
15
- DEFAULTS = {
16
- host: 'api.twilio.com',
17
- port: 443,
18
- use_ssl: true,
19
- ssl_verify_peer: true,
20
- ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem',
21
- timeout: 30,
22
- proxy_addr: nil,
23
- proxy_port: nil,
24
- proxy_user: nil,
25
- proxy_pass: nil,
26
- retry_limit: 1
27
- }
28
-
29
- attr_reader :account_sid, :last_request, :last_response
30
-
31
- def initialize(*args)
32
- options = args.last.is_a?(Hash) ? args.pop : {}
33
- @config = get_defaults.merge! options
34
-
35
- @account_sid = args[0] || Twilio.account_sid
36
- @auth_token = args[1] || Twilio.auth_token
37
- if @account_sid.nil? || @auth_token.nil?
38
- raise ArgumentError, 'Account SID and auth token are required'
39
- end
40
-
41
- set_up_connection
42
- set_up_subresources
43
- end
44
-
45
- protected
46
-
47
- ##
48
- # Get the default config values.
49
- def get_defaults
50
- # To be overridden
51
- DEFAULTS
52
- end
53
-
54
- ##
55
- # Set up and cache a Net::HTTP object to use when making requests. This is
56
- # a private method documented for completeness.
57
- def set_up_connection # :doc:
58
- connection_class = Net::HTTP::Proxy @config[:proxy_addr],
59
- @config[:proxy_port], @config[:proxy_user], @config[:proxy_pass]
60
- @connection = connection_class.new @config[:host], @config[:port]
61
- set_up_ssl
62
- @connection.open_timeout = @config[:timeout]
63
- @connection.read_timeout = @config[:timeout]
64
- end
65
-
66
- ##
67
- # Set up the ssl properties of the <tt>@connection</tt> Net::HTTP object.
68
- # This is a private method documented for completeness.
69
- def set_up_ssl # :doc:
70
- @connection.use_ssl = @config[:use_ssl]
71
- if @config[:ssl_verify_peer]
72
- @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
73
- @connection.ca_file = @config[:ssl_ca_file]
74
- else
75
- @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
76
- end
77
- end
78
-
79
- ##
80
- # Set up sub resources attributes.
81
- def set_up_subresources # :doc:
82
- # To be overridden
83
- end
84
-
85
- ##
86
- # Send an HTTP request using the cached <tt>@connection</tt> object and
87
- # return the JSON response body parsed into a hash. Also save the raw
88
- # Net::HTTP::Request and Net::HTTP::Response objects as
89
- # <tt>@last_request</tt> and <tt>@last_response</tt> to allow for
90
- # inspection later.
91
- def connect_and_send(request) # :doc:
92
- @last_request = request
93
- retries_left = @config[:retry_limit]
94
- begin
95
- response = @connection.request request
96
- @last_response = response
97
- if response.kind_of? Net::HTTPServerError
98
- raise Twilio::REST::ServerError
99
- end
100
- rescue Exception
101
- raise if request.class == Net::HTTP::Post
102
- if retries_left > 0 then retries_left -= 1; retry else raise end
103
- end
104
- if response.body and !response.body.empty?
105
- object = MultiJson.load response.body
106
- end
107
- if response.kind_of? Net::HTTPClientError
108
- raise Twilio::REST::RequestError.new object['message'], object['code']
109
- end
110
- object
111
- end
112
- end
113
-
114
4
  ##
115
5
  # The Twilio::REST::Client class caches authentication parameters and
116
6
  # exposes methods to make HTTP requests to Twilio's REST API. However, you
@@ -237,26 +127,6 @@ module Twilio
237
127
  "<Twilio::REST::Client @account_sid=#{@account_sid}>"
238
128
  end
239
129
 
240
- ##
241
- # Define #get, #put, #post and #delete helper methods for sending HTTP
242
- # requests to Twilio. You shouldn't need to use these methods directly,
243
- # but they can be useful for debugging. Each method returns a hash
244
- # obtained from parsing the JSON object in the response body.
245
- [:get, :put, :post, :delete].each do |method|
246
- method_class = Net::HTTP.const_get method.to_s.capitalize
247
- define_method method do |path, *args|
248
- params = twilify args[0]; params = {} if params.empty?
249
- unless args[1] # build the full path unless already given
250
- path = "#{path}.json"
251
- path << "?#{url_encode(params)}" if method == :get && !params.empty?
252
- end
253
- request = method_class.new path, HTTP_HEADERS
254
- request.basic_auth @account_sid, @auth_token
255
- request.form_data = params if [:post, :put].include? method
256
- connect_and_send request
257
- end
258
- end
259
-
260
130
  ##
261
131
  # Delegate account methods from the client. This saves having to call
262
132
  # <tt>client.account</tt> every time for resources on the default
@@ -285,217 +155,14 @@ module Twilio
285
155
  @accounts = Twilio::REST::Accounts.new "/#{API_VERSION}/Accounts", self
286
156
  @account = @accounts.get @account_sid
287
157
  end
288
- end
289
-
290
- class TaskRouterClient < BaseClient
291
- API_VERSION = 'v1'
292
-
293
- DEFAULTS = {
294
- host: 'taskrouter.twilio.com',
295
- port: 443,
296
- use_ssl: true,
297
- ssl_verify_peer: true,
298
- ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem',
299
- timeout: 30,
300
- proxy_addr: nil,
301
- proxy_port: nil,
302
- proxy_user: nil,
303
- proxy_pass: nil,
304
- retry_limit: 1
305
- }
306
-
307
- attr_reader :workspace, :workspace_sid, :workspaces
308
158
 
309
159
  ##
310
- # Instantiate a new HTTP TaskRouter client to talk to Twilio. The parameters
311
- # +account_sid+, +auth_token+ and +workspace_sid are required, unless you
312
- # have configured them already using the block configure syntax, and used
313
- # to generate the HTTP basic auth header in each request. The +options+
314
- # parameter is a hash of connection configuration options. the following
315
- # keys are supported:
316
- #
317
- # === <tt>host: 'taskrouter.twilio.com'</tt>
318
- #
319
- # The domain to which you'd like the client to make HTTP requests. Useful
320
- # for testing. Defaults to 'api.twilio.com'.
321
- #
322
- # === <tt>port: 443</tt>
323
- #
324
- # The port on which to connect to the above domain. Defaults to 443 and
325
- # should be left that way except in testing environments.
326
- #
327
- # === <tt>use_ssl: true</tt>
328
- #
329
- # Declare whether ssl should be used for connections to the above domain.
330
- # Defaults to true and should be left alone except when testing.
331
- #
332
- # === <tt>ssl_verify_peer: true</tt>
333
- #
334
- # Declare whether to verify the host's ssl cert when setting up the
335
- # connection to the above domain. Defaults to true, but can be turned off
336
- # to avoid ssl certificate verification failures in environments without
337
- # the necessary ca certificates.
338
- #
339
- # === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
340
- #
341
- # Specify the path to the certificate authority bundle you'd like to use
342
- # to verify Twilio's SSL certificate on each request. If not specified, a
343
- # certificate bundle extraced from Firefox is packaged with the gem and
344
- # used by default.
345
- #
346
- # === <tt>timeout: 30</tt>
347
- #
348
- # Set the time in seconds to wait before timing out the HTTP request.
349
- # Defaults to 30 seconds. If you aren't fetching giant pages of call or
350
- # SMS logs you can safely decrease this to something like 3 seconds or
351
- # lower. In paricular if you are sending SMS you can set this to 1 second
352
- # or less and swallow the exception if you don't care about the response.
353
- #
354
- # === <tt>proxy_addr: 'proxy.host.domain'</tt>
355
- #
356
- # The domain of a proxy through which you'd like the client to make HTTP
357
- # requests. Defaults to nil.
358
- #
359
- # === <tt>proxy_port: 3128</tt>
360
- #
361
- # The port on which to connect to the above proxy. Defaults to nil.
362
- #
363
- # === <tt>proxy_user: 'username'</tt>
364
- #
365
- # The user name to use for authentication with the proxy. Defaults to nil.
366
- #
367
- # === <tt>proxy_pass: 'password'</tt>
368
- #
369
- # The password to use for authentication with the proxy. Defaults to nil.
370
- #
371
- # === <tt>retry_limit: 1</tt>
372
- #
373
- # The number of times to retry a request that has failed before throwing
374
- # an exception. Defaults to one.
375
- def initialize(*args)
376
- @workspace_sid = args[2]
377
- if @workspace_sid.nil?
378
- raise ArgumentError, 'Workspace SID is required'
379
- end
380
- super(*args)
381
- end
382
-
383
- ##
384
- # Define #get, #put, #post and #delete helper methods for sending HTTP
385
- # requests to Twilio. You shouldn't need to use these methods directly,
386
- # but they can be useful for debugging. Each method returns a hash
387
- # obtained from parsing the JSON object in the response body.
388
- [:get, :put, :post, :delete].each do |method|
389
- method_class = Net::HTTP.const_get method.to_s.capitalize
390
- define_method method do |path, *args|
391
- params = twilify args[0]; params = {} if params.empty?
392
- unless args[1] # build the full path unless already given
393
- path = path.dup
394
- path << "?#{url_encode(params)}" if method == :get && !params.empty?
395
- end
396
- request = method_class.new path, HTTP_HEADERS
397
- request.basic_auth @account_sid, @auth_token
398
- request.form_data = params if [:post, :put].include? method
399
- connect_and_send request
400
- end
401
- end
402
-
403
- def inspect # :nodoc:
404
- "<Twilio::REST::TaskRouterClient @account_sid=#{@account_sid}>"
405
- end
406
-
407
- ##
408
- # Delegate workspace methods from the client. This saves having to call
409
- # <tt>client.workspace</tt> every time for resources on the default
410
- # workspace.
411
- def method_missing(method_name, *args, &block)
412
- if workspace.respond_to?(method_name)
413
- workspace.send(method_name, *args, &block)
414
- else
415
- super
416
- end
160
+ # Builds up full request path
161
+ def build_full_path(path, params, method)
162
+ path = "#{path}.json"
163
+ path << "?#{url_encode(params)}" if method == :get && !params.empty?
164
+ path
417
165
  end
418
-
419
- def respond_to?(method_name, include_private=false)
420
- if workspace.respond_to?(method_name, include_private)
421
- true
422
- else
423
- super
424
- end
425
- end
426
-
427
- ##
428
- # Get statistics of a task queue.
429
- def task_queue_statistics(task_queue_sid, *args) # :doc:
430
- if task_queue_sid.nil?
431
- raise ArgumentError, 'Task queue SID is required'
432
- end
433
- path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/#{task_queue_sid}/Statistics"
434
- response = get path, args, true
435
- Twilio::REST::TaskRouter::TaskQueueStatistics.new path, self, response
436
- end
437
-
438
- ##
439
- # Get statistics of task queues.
440
- def task_queues_statistics(*args) # :doc:
441
- path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/Statistics"
442
- stats = Twilio::REST::TaskRouter::TaskQueuesStatistics.new path, self
443
- stats.list args, true
444
- end
445
-
446
- ##
447
- # Get statistics of a worker.
448
- def worker_statistics(worker_sid, *args) # :doc:
449
- if worker_sid.nil?
450
- raise ArgumentError, 'Worker SID is required'
451
- end
452
- path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/#{worker_sid}/Statistics"
453
- response = get path, args, true
454
- Twilio::REST::TaskRouter::WorkerStatistics.new path, self, response
455
- end
456
-
457
- ##
458
- # Get statistics of workers.
459
- def workers_statistics(*args) # :doc:
460
- path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/Statistics"
461
- response = get path, args, true
462
- Twilio::REST::TaskRouter::WorkersStatistics.new path, self, response
463
- end
464
-
465
- ##
466
- # Get statistics of a workflow.
467
- def workflow_statistics(workflow_sid, *args) # :doc:
468
- if workflow_sid.nil?
469
- raise ArgumentError, 'Workflow SID is required'
470
- end
471
- path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workflows/#{workflow_sid}/Statistics"
472
- response = get path, args, true
473
- Twilio::REST::TaskRouter::WorkflowStatistics.new path, self, response
474
- end
475
-
476
- ##
477
- # Get statistics of a workspace.
478
- def workspace_statistics(*args) # :doc:
479
- path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Statistics"
480
- response = get path, args, true
481
- Twilio::REST::TaskRouter::WorkspaceStatistics.new path, self, response
482
- end
483
-
484
- protected
485
-
486
- ##
487
- # Get the default config values.
488
- def get_defaults
489
- DEFAULTS
490
- end
491
-
492
- ##
493
- # Set up +workspace+ and +workspaces+ attributes.
494
- def set_up_subresources # :doc:
495
- @workspaces = Twilio::REST::TaskRouter::Workspaces.new "/#{API_VERSION}/Workspaces", self
496
- @workspace = @workspaces.get @workspace_sid
497
- end
498
-
499
166
  end
500
167
  end
501
168
  end
@@ -0,0 +1,8 @@
1
+ module Twilio
2
+ module REST
3
+ module Lookups
4
+ class PhoneNumbers < Twilio::REST::NextGenListResource; end
5
+ class PhoneNumber < InstanceResource; end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,117 @@
1
+ require 'twilio-ruby/rest/base_client'
2
+ module Twilio
3
+ module REST
4
+ class LookupsClient < BaseClient
5
+ API_VERSION = 'v1'
6
+
7
+ DEFAULTS = {
8
+ host: 'lookups.twilio.com',
9
+ port: 443,
10
+ use_ssl: true,
11
+ ssl_verify_peer: true,
12
+ ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem',
13
+ timeout: 30,
14
+ proxy_addr: nil,
15
+ proxy_port: nil,
16
+ proxy_user: nil,
17
+ proxy_pass: nil,
18
+ retry_limit: 1
19
+ }
20
+
21
+ attr_reader :phone_numbers
22
+
23
+ ##
24
+ # Instantiate a new HTTP Lookups client to talk to Twilio. The parameters
25
+ # +account_sid+, +auth_token+ and +workspace_sid are required, unless you
26
+ # have configured them already using the block configure syntax, and used
27
+ # to generate the HTTP basic auth header in each request. The +options+
28
+ # parameter is a hash of connection configuration options. the following
29
+ # keys are supported:
30
+ #
31
+ # === <tt>host: 'lookups.twilio.com'</tt>
32
+ #
33
+ # The domain to which you'd like the client to make HTTP requests. Useful
34
+ # for testing. Defaults to 'lookups.twilio.com'.
35
+ #
36
+ # === <tt>port: 443</tt>
37
+ #
38
+ # The port on which to connect to the above domain. Defaults to 443 and
39
+ # should be left that way except in testing environments.
40
+ #
41
+ # === <tt>use_ssl: true</tt>
42
+ #
43
+ # Declare whether ssl should be used for connections to the above domain.
44
+ # Defaults to true and should be left alone except when testing.
45
+ #
46
+ # === <tt>ssl_verify_peer: true</tt>
47
+ #
48
+ # Declare whether to verify the host's ssl cert when setting up the
49
+ # connection to the above domain. Defaults to true, but can be turned off
50
+ # to avoid ssl certificate verification failures in environments without
51
+ # the necessary ca certificates.
52
+ #
53
+ # === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
54
+ #
55
+ # Specify the path to the certificate authority bundle you'd like to use
56
+ # to verify Twilio's SSL certificate on each request. If not specified, a
57
+ # certificate bundle extraced from Firefox is packaged with the gem and
58
+ # used by default.
59
+ #
60
+ # === <tt>timeout: 30</tt>
61
+ #
62
+ # Set the time in seconds to wait before timing out the HTTP request.
63
+ # Defaults to 30 seconds. If you aren't fetching giant pages of call or
64
+ # SMS logs you can safely decrease this to something like 3 seconds or
65
+ # lower. In paricular if you are sending SMS you can set this to 1 second
66
+ # or less and swallow the exception if you don't care about the response.
67
+ #
68
+ # === <tt>proxy_addr: 'proxy.host.domain'</tt>
69
+ #
70
+ # The domain of a proxy through which you'd like the client to make HTTP
71
+ # requests. Defaults to nil.
72
+ #
73
+ # === <tt>proxy_port: 3128</tt>
74
+ #
75
+ # The port on which to connect to the above proxy. Defaults to nil.
76
+ #
77
+ # === <tt>proxy_user: 'username'</tt>
78
+ #
79
+ # The user name to use for authentication with the proxy. Defaults to nil.
80
+ #
81
+ # === <tt>proxy_pass: 'password'</tt>
82
+ #
83
+ # The password to use for authentication with the proxy. Defaults to nil.
84
+ #
85
+ # === <tt>retry_limit: 1</tt>
86
+ #
87
+ # The number of times to retry a request that has failed before throwing
88
+ # an exception. Defaults to one.
89
+ def inspect # :nodoc:
90
+ "<Twilio::REST::LookupsClient @account_sid=#{@account_sid}>"
91
+ end
92
+
93
+ protected
94
+
95
+ ##
96
+ # Get the default config values.
97
+ def get_defaults
98
+ DEFAULTS
99
+ end
100
+
101
+ ##
102
+ # Set up +phone_numbers+ attribute.
103
+ def set_up_subresources # :doc:
104
+ @phone_numbers = Twilio::REST::Lookups::PhoneNumbers.new "/#{API_VERSION}/PhoneNumbers", self
105
+ end
106
+
107
+ ##
108
+ # Builds up full request path
109
+ def build_full_path(path, params, method)
110
+ path = path.dup
111
+ path << "?#{url_encode(params)}" if method == :get && !params.empty?
112
+ path
113
+ end
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,203 @@
1
+ require 'twilio-ruby/rest/base_client'
2
+ module Twilio
3
+ module REST
4
+ class TaskRouterClient < BaseClient
5
+ API_VERSION = 'v1'
6
+
7
+ DEFAULTS = {
8
+ host: 'taskrouter.twilio.com',
9
+ port: 443,
10
+ use_ssl: true,
11
+ ssl_verify_peer: true,
12
+ ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem',
13
+ timeout: 30,
14
+ proxy_addr: nil,
15
+ proxy_port: nil,
16
+ proxy_user: nil,
17
+ proxy_pass: nil,
18
+ retry_limit: 1
19
+ }
20
+
21
+ attr_reader :workspace, :workspace_sid, :workspaces
22
+
23
+ ##
24
+ # Instantiate a new HTTP TaskRouter client to talk to Twilio. The parameters
25
+ # +account_sid+, +auth_token+ and +workspace_sid are required, unless you
26
+ # have configured them already using the block configure syntax, and used
27
+ # to generate the HTTP basic auth header in each request. The +options+
28
+ # parameter is a hash of connection configuration options. the following
29
+ # keys are supported:
30
+ #
31
+ # === <tt>host: 'taskrouter.twilio.com'</tt>
32
+ #
33
+ # The domain to which you'd like the client to make HTTP requests. Useful
34
+ # for testing. Defaults to 'api.twilio.com'.
35
+ #
36
+ # === <tt>port: 443</tt>
37
+ #
38
+ # The port on which to connect to the above domain. Defaults to 443 and
39
+ # should be left that way except in testing environments.
40
+ #
41
+ # === <tt>use_ssl: true</tt>
42
+ #
43
+ # Declare whether ssl should be used for connections to the above domain.
44
+ # Defaults to true and should be left alone except when testing.
45
+ #
46
+ # === <tt>ssl_verify_peer: true</tt>
47
+ #
48
+ # Declare whether to verify the host's ssl cert when setting up the
49
+ # connection to the above domain. Defaults to true, but can be turned off
50
+ # to avoid ssl certificate verification failures in environments without
51
+ # the necessary ca certificates.
52
+ #
53
+ # === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
54
+ #
55
+ # Specify the path to the certificate authority bundle you'd like to use
56
+ # to verify Twilio's SSL certificate on each request. If not specified, a
57
+ # certificate bundle extraced from Firefox is packaged with the gem and
58
+ # used by default.
59
+ #
60
+ # === <tt>timeout: 30</tt>
61
+ #
62
+ # Set the time in seconds to wait before timing out the HTTP request.
63
+ # Defaults to 30 seconds. If you aren't fetching giant pages of call or
64
+ # SMS logs you can safely decrease this to something like 3 seconds or
65
+ # lower. In paricular if you are sending SMS you can set this to 1 second
66
+ # or less and swallow the exception if you don't care about the response.
67
+ #
68
+ # === <tt>proxy_addr: 'proxy.host.domain'</tt>
69
+ #
70
+ # The domain of a proxy through which you'd like the client to make HTTP
71
+ # requests. Defaults to nil.
72
+ #
73
+ # === <tt>proxy_port: 3128</tt>
74
+ #
75
+ # The port on which to connect to the above proxy. Defaults to nil.
76
+ #
77
+ # === <tt>proxy_user: 'username'</tt>
78
+ #
79
+ # The user name to use for authentication with the proxy. Defaults to nil.
80
+ #
81
+ # === <tt>proxy_pass: 'password'</tt>
82
+ #
83
+ # The password to use for authentication with the proxy. Defaults to nil.
84
+ #
85
+ # === <tt>retry_limit: 1</tt>
86
+ #
87
+ # The number of times to retry a request that has failed before throwing
88
+ # an exception. Defaults to one.
89
+ def initialize(*args)
90
+ @workspace_sid = args[2]
91
+ if @workspace_sid.nil?
92
+ raise ArgumentError, 'Workspace SID is required'
93
+ end
94
+ super(*args)
95
+ end
96
+
97
+ def inspect # :nodoc:
98
+ "<Twilio::REST::TaskRouterClient @account_sid=#{@account_sid}>"
99
+ end
100
+
101
+ ##
102
+ # Delegate workspace methods from the client. This saves having to call
103
+ # <tt>client.workspace</tt> every time for resources on the default
104
+ # workspace.
105
+ def method_missing(method_name, *args, &block)
106
+ if workspace.respond_to?(method_name)
107
+ workspace.send(method_name, *args, &block)
108
+ else
109
+ super
110
+ end
111
+ end
112
+
113
+ def respond_to?(method_name, include_private=false)
114
+ if workspace.respond_to?(method_name, include_private)
115
+ true
116
+ else
117
+ super
118
+ end
119
+ end
120
+
121
+ ##
122
+ # Get statistics of a task queue.
123
+ def task_queue_statistics(task_queue_sid, *args) # :doc:
124
+ if task_queue_sid.nil?
125
+ raise ArgumentError, 'Task queue SID is required'
126
+ end
127
+ path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/#{task_queue_sid}/Statistics"
128
+ response = get path, args, true
129
+ Twilio::REST::TaskRouter::TaskQueueStatistics.new path, self, response
130
+ end
131
+
132
+ ##
133
+ # Get statistics of task queues.
134
+ def task_queues_statistics(*args) # :doc:
135
+ path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/Statistics"
136
+ stats = Twilio::REST::TaskRouter::TaskQueuesStatistics.new path, self
137
+ stats.list args, true
138
+ end
139
+
140
+ ##
141
+ # Get statistics of a worker.
142
+ def worker_statistics(worker_sid, *args) # :doc:
143
+ if worker_sid.nil?
144
+ raise ArgumentError, 'Worker SID is required'
145
+ end
146
+ path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/#{worker_sid}/Statistics"
147
+ response = get path, args, true
148
+ Twilio::REST::TaskRouter::WorkerStatistics.new path, self, response
149
+ end
150
+
151
+ ##
152
+ # Get statistics of workers.
153
+ def workers_statistics(*args) # :doc:
154
+ path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/Statistics"
155
+ response = get path, args, true
156
+ Twilio::REST::TaskRouter::WorkersStatistics.new path, self, response
157
+ end
158
+
159
+ ##
160
+ # Get statistics of a workflow.
161
+ def workflow_statistics(workflow_sid, *args) # :doc:
162
+ if workflow_sid.nil?
163
+ raise ArgumentError, 'Workflow SID is required'
164
+ end
165
+ path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workflows/#{workflow_sid}/Statistics"
166
+ response = get path, args, true
167
+ Twilio::REST::TaskRouter::WorkflowStatistics.new path, self, response
168
+ end
169
+
170
+ ##
171
+ # Get statistics of a workspace.
172
+ def workspace_statistics(*args) # :doc:
173
+ path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Statistics"
174
+ response = get path, args, true
175
+ Twilio::REST::TaskRouter::WorkspaceStatistics.new path, self, response
176
+ end
177
+
178
+ protected
179
+
180
+ ##
181
+ # Get the default config values.
182
+ def get_defaults
183
+ DEFAULTS
184
+ end
185
+
186
+ ##
187
+ # Set up +workspace+ and +workspaces+ attributes.
188
+ def set_up_subresources # :doc:
189
+ @workspaces = Twilio::REST::TaskRouter::Workspaces.new "/#{API_VERSION}/Workspaces", self
190
+ @workspace = @workspaces.get @workspace_sid
191
+ end
192
+
193
+ ##
194
+ # Builds up full request path
195
+ def build_full_path(path, params, method)
196
+ path = path.dup
197
+ path << "?#{url_encode(params)}" if method == :get && !params.empty?
198
+ path
199
+ end
200
+
201
+ end
202
+ end
203
+ end
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '3.15.2'
2
+ VERSION = '3.16.0'
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::Lookups::PhoneNumbers do
4
+ it 'creates a phone_number object' do
5
+ client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
6
+ expect(client).to respond_to(:phone_numbers)
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.15.2
4
+ version: 3.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Benton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -139,6 +139,7 @@ files:
139
139
  - lib/twilio-ruby/rest/available_phone_numbers/local.rb
140
140
  - lib/twilio-ruby/rest/available_phone_numbers/mobile.rb
141
141
  - lib/twilio-ruby/rest/available_phone_numbers/toll_free.rb
142
+ - lib/twilio-ruby/rest/base_client.rb
142
143
  - lib/twilio-ruby/rest/call_feedback.rb
143
144
  - lib/twilio-ruby/rest/call_feedback_summary.rb
144
145
  - lib/twilio-ruby/rest/calls.rb
@@ -153,6 +154,8 @@ files:
153
154
  - lib/twilio-ruby/rest/incoming_phone_numbers/toll_free.rb
154
155
  - lib/twilio-ruby/rest/instance_resource.rb
155
156
  - lib/twilio-ruby/rest/list_resource.rb
157
+ - lib/twilio-ruby/rest/lookups/phone_numbers.rb
158
+ - lib/twilio-ruby/rest/lookups_client.rb
156
159
  - lib/twilio-ruby/rest/media.rb
157
160
  - lib/twilio-ruby/rest/messages.rb
158
161
  - lib/twilio-ruby/rest/next_gen_list_resource.rb
@@ -185,6 +188,7 @@ files:
185
188
  - lib/twilio-ruby/rest/task_router/workflows.rb
186
189
  - lib/twilio-ruby/rest/task_router/workspace_statistics.rb
187
190
  - lib/twilio-ruby/rest/task_router/workspaces.rb
191
+ - lib/twilio-ruby/rest/task_router_client.rb
188
192
  - lib/twilio-ruby/rest/tokens.rb
189
193
  - lib/twilio-ruby/rest/transcriptions.rb
190
194
  - lib/twilio-ruby/rest/usage.rb
@@ -208,6 +212,7 @@ files:
208
212
  - spec/rest/client_spec.rb
209
213
  - spec/rest/conference_spec.rb
210
214
  - spec/rest/instance_resource_spec.rb
215
+ - spec/rest/lookups/phone_number_spec.rb
211
216
  - spec/rest/message_spec.rb
212
217
  - spec/rest/numbers_spec.rb
213
218
  - spec/rest/queue_spec.rb
@@ -268,6 +273,7 @@ test_files:
268
273
  - spec/rest/client_spec.rb
269
274
  - spec/rest/conference_spec.rb
270
275
  - spec/rest/instance_resource_spec.rb
276
+ - spec/rest/lookups/phone_number_spec.rb
271
277
  - spec/rest/message_spec.rb
272
278
  - spec/rest/numbers_spec.rb
273
279
  - spec/rest/queue_spec.rb