Class: Restcomm::REST::TaskRouterClient
- Inherits:
-
BaseClient
- Object
- BaseClient
- Restcomm::REST::TaskRouterClient
- Defined in:
- lib/restcomm-ruby/rest/client.rb
Constant Summary collapse
- API_VERSION =
'v1'- DEFAULTS =
{ host: '192.168.1.8', port: 80, use_ssl: false, ssl_verify_peer: false, ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem', timeout: 30, proxy_addr: nil, proxy_port: nil, proxy_user: nil, proxy_pass: nil, retry_limit: 1 }
Constants inherited from BaseClient
Instance Attribute Summary collapse
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
-
#workspace_sid ⇒ Object
readonly
Returns the value of attribute workspace_sid.
-
#workspaces ⇒ Object
readonly
Returns the value of attribute workspaces.
Attributes inherited from BaseClient
#account_sid, #last_request, #last_response
Instance Method Summary collapse
-
#initialize(*args) ⇒ TaskRouterClient
constructor
Instantiate a new HTTP TaskRouter client to talk to Restcomm.
-
#inspect ⇒ Object
:nodoc:.
-
#method ⇒ Object
Define #get, #put, #post and #delete helper methods for sending HTTP requests to Restcomm.
-
#method_missing(method_name, *args, &block) ⇒ Object
Delegate workspace methods from the client.
- #respond_to?(method_name, include_private = false) ⇒ Boolean
-
#task_queue_statistics(task_queue_sid, *args) ⇒ Object
Get statistics of a task queue.
-
#task_queues_statistics(*args) ⇒ Object
Get statistics of task queues.
-
#worker_statistics(worker_sid, *args) ⇒ Object
Get statistics of a worker.
-
#workers_statistics(*args) ⇒ Object
Get statistics of workers.
-
#workflow_statistics(workflow_sid, *args) ⇒ Object
Get statistics of a workflow.
-
#workspace_statistics(*args) ⇒ Object
Get statistics of a workspace.
Methods included from Utils
Methods included from Util
Constructor Details
#initialize(*args) ⇒ TaskRouterClient
Instantiate a new HTTP TaskRouter client to talk to Restcomm. The parameters account_sid, auth_token and +workspace_sid are required, unless you have configured them already using the block configure syntax, and used to generate the HTTP basic auth header in each request. The options parameter is a hash of connection configuration options. the following keys are supported:
host: 'taskrouter.restcomm.com'
The domain to which you’d like the client to make HTTP requests. Useful for testing. Defaults to ‘api.restcomm.com’.
port: 443
The port on which to connect to the above domain. Defaults to 443 and should be left that way except in testing environments.
use_ssl: true
Declare whether ssl should be used for connections to the above domain. Defaults to true and should be left alone except when testing.
ssl_verify_peer: true
Declare whether to verify the host’s ssl cert when setting up the connection to the above domain. Defaults to true, but can be turned off to avoid ssl certificate verification failures in environments without the necessary ca certificates.
ssl_ca_file: '/path/to/ca/file'
Specify the path to the certificate authority bundle you’d like to use to verify Restcomm’s SSL certificate on each request. If not specified, a certificate bundle extraced from Firefox is packaged with the gem and used by default.
timeout: 30
Set the time in seconds to wait before timing out the HTTP request. Defaults to 30 seconds. If you aren’t fetching giant pages of call or SMS logs you can safely decrease this to something like 3 seconds or lower. In paricular if you are sending SMS you can set this to 1 second or less and swallow the exception if you don’t care about the response.
proxy_addr: 'proxy.host.domain'
The domain of a proxy through which you’d like the client to make HTTP requests. Defaults to nil.
proxy_port: 3128
The port on which to connect to the above proxy. Defaults to nil.
proxy_user: 'username'
The user name to use for authentication with the proxy. Defaults to nil.
proxy_pass: 'password'
The password to use for authentication with the proxy. Defaults to nil.
retry_limit: 1
The number of times to retry a request that has failed before throwing an exception. Defaults to one.
428 429 430 431 432 433 434 |
# File 'lib/restcomm-ruby/rest/client.rb', line 428 def initialize(*args) @workspace_sid = args[2] if @workspace_sid.nil? raise ArgumentError, 'Workspace SID is required' end super(*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Delegate workspace methods from the client. This saves having to call client.workspace every time for resources on the default workspace.
465 466 467 468 469 470 471 |
# File 'lib/restcomm-ruby/rest/client.rb', line 465 def method_missing(method_name, *args, &block) if workspace.respond_to?(method_name) workspace.send(method_name, *args, &block) else super end end |
Instance Attribute Details
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
360 361 362 |
# File 'lib/restcomm-ruby/rest/client.rb', line 360 def workspace @workspace end |
#workspace_sid ⇒ Object (readonly)
Returns the value of attribute workspace_sid.
360 361 362 |
# File 'lib/restcomm-ruby/rest/client.rb', line 360 def workspace_sid @workspace_sid end |
#workspaces ⇒ Object (readonly)
Returns the value of attribute workspaces.
360 361 362 |
# File 'lib/restcomm-ruby/rest/client.rb', line 360 def workspaces @workspaces end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
457 458 459 |
# File 'lib/restcomm-ruby/rest/client.rb', line 457 def inspect # :nodoc: "<Restcomm::REST::TaskRouterClient @account_sid=#{@account_sid}>" end |
#method ⇒ Object
Define #get, #put, #post and #delete helper methods for sending HTTP requests to Restcomm. You shouldn’t need to use these methods directly, but they can be useful for debugging. Each method returns a hash obtained from parsing the JSON object in the response body.
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/restcomm-ruby/rest/client.rb', line 441 [:get, :put, :post, :delete].each do |method| method_class = Net::HTTP.const_get method.to_s.capitalize define_method method do |path, *args| params = restify args[0]; params = {} if params.empty? unless args[1] # build the full path unless already given path = path.dup path << "?#{url_encode(params)}" if method == :get && !params.empty? end request = method_class.new path, HTTP_HEADERS request.basic_auth @account_sid, @auth_token request.form_data = params if [:post, :put].include? method connect_and_send request end end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
473 474 475 476 477 478 479 |
# File 'lib/restcomm-ruby/rest/client.rb', line 473 def respond_to?(method_name, include_private=false) if workspace.respond_to?(method_name, include_private) true else super end end |
#task_queue_statistics(task_queue_sid, *args) ⇒ Object
Get statistics of a task queue.
483 484 485 486 487 488 489 490 |
# File 'lib/restcomm-ruby/rest/client.rb', line 483 def task_queue_statistics(task_queue_sid, *args) # :doc: if task_queue_sid.nil? raise ArgumentError, 'Task queue SID is required' end path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/#{task_queue_sid}/Statistics" response = get path, args, true Restcomm::REST::TaskRouter::TaskQueueStatistics.new path, self, response end |
#task_queues_statistics(*args) ⇒ Object
Get statistics of task queues.
494 495 496 497 498 |
# File 'lib/restcomm-ruby/rest/client.rb', line 494 def task_queues_statistics(*args) # :doc: path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/Statistics" stats = Restcomm::REST::TaskRouter::TaskQueuesStatistics.new path, self stats.list args, true end |
#worker_statistics(worker_sid, *args) ⇒ Object
Get statistics of a worker.
502 503 504 505 506 507 508 509 |
# File 'lib/restcomm-ruby/rest/client.rb', line 502 def worker_statistics(worker_sid, *args) # :doc: if worker_sid.nil? raise ArgumentError, 'Worker SID is required' end path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/#{worker_sid}/Statistics" response = get path, args, true Restcomm::REST::TaskRouter::WorkerStatistics.new path, self, response end |
#workers_statistics(*args) ⇒ Object
Get statistics of workers.
513 514 515 516 517 |
# File 'lib/restcomm-ruby/rest/client.rb', line 513 def workers_statistics(*args) # :doc: path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/Statistics" response = get path, args, true Restcomm::REST::TaskRouter::WorkersStatistics.new path, self, response end |
#workflow_statistics(workflow_sid, *args) ⇒ Object
Get statistics of a workflow.
521 522 523 524 525 526 527 528 |
# File 'lib/restcomm-ruby/rest/client.rb', line 521 def workflow_statistics(workflow_sid, *args) # :doc: if workflow_sid.nil? raise ArgumentError, 'Workflow SID is required' end path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workflows/#{workflow_sid}/Statistics" response = get path, args, true Restcomm::REST::TaskRouter::WorkflowStatistics.new path, self, response end |
#workspace_statistics(*args) ⇒ Object
Get statistics of a workspace.
532 533 534 535 536 |
# File 'lib/restcomm-ruby/rest/client.rb', line 532 def workspace_statistics(*args) # :doc: path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Statistics" response = get path, args, true Restcomm::REST::TaskRouter::WorkspaceStatistics.new path, self, response end |