class Twilio::REST::Taskrouter::V1::WorkspaceContext::WorkerList
Public Class Methods
Initialize the WorkerList
@param [Version] version Version
that contains the resource @param [String] workspace_sid The SID of the Workspace that contains the Worker. @return [WorkerList] WorkerList
Twilio::REST::ListResource::new
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 20 def initialize(version, workspace_sid: nil) 21 super(version) 22 23 # Path Solution 24 @solution = {workspace_sid: workspace_sid} 25 @uri = "/Workspaces/#{@solution[:workspace_sid]}/Workers" 26 27 # Components 28 @statistics = nil 29 end
Public Instance Methods
Create the WorkerInstance
@param [String] friendly_name A descriptive string that you create to describe
the new Worker. It can be up to 64 characters long.
@param [String] activity_sid The SID of a valid Activity that will describe the
new Worker's initial state. See {Activities}[https://www.twilio.com/docs/taskrouter/api/activity] for more information. If not provided, the new Worker's initial state is the `default_activity_sid` configured on the Workspace.
@param [String] attributes A valid JSON string that describes the new Worker.
For example: `{ "email": "Bob@example.com", "phone": "+5095551234" }`. This data is passed to the `assignment_callback_url` when TaskRouter assigns a Task to the Worker. Defaults to {}.
@return [WorkerInstance] Created WorkerInstance
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 199 def create(friendly_name: nil, activity_sid: :unset, attributes: :unset) 200 data = Twilio::Values.of({ 201 'FriendlyName' => friendly_name, 202 'ActivitySid' => activity_sid, 203 'Attributes' => attributes, 204 }) 205 206 payload = @version.create('POST', @uri, data: data) 207 208 WorkerInstance.new(@version, payload, workspace_sid: @solution[:workspace_sid], ) 209 end
When passed a block, yields WorkerInstance
records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 120 def each 121 limits = @version.read_limits 122 123 page = self.page(page_size: limits[:page_size], ) 124 125 @version.stream(page, 126 limit: limits[:limit], 127 page_limit: limits[:page_limit]).each {|x| yield x} 128 end
Retrieve a single page of WorkerInstance
records from the API. Request
is executed immediately. @param [String] target_url API-generated URL for the requested results page @return [Page] Page
of WorkerInstance
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 177 def get_page(target_url) 178 response = @version.domain.request( 179 'GET', 180 target_url 181 ) 182 WorkerPage.new(@version, response, @solution) 183 end
Lists WorkerInstance
records from the API as a list. Unlike stream(), this operation is eager and will load `limit` records into memory before returning. @param [String] activity_name The `activity_name` of the Worker resources to
read.
@param [String] activity_sid The `activity_sid` of the Worker resources to read. @param [String] available Whether to return only Worker resources that are
available or unavailable. Can be `true`, `1`, or `yes` to return Worker resources that are available, and `false`, or any value returns the Worker resources that are not available.
@param [String] friendly_name The `friendly_name` of the Worker resources to
read.
@param [String] target_workers_expression Filter by Workers that would match an
expression on a TaskQueue. This is helpful for debugging which Workers would match a potential queue.
@param [String] task_queue_name The `friendly_name` of the TaskQueue that the
Workers to read are eligible for.
@param [String] task_queue_sid The SID of the TaskQueue that the Workers to read
are eligible for.
@param [Integer] limit Upper limit for the number of records to return. stream()
guarantees to never return more than limit. Default is no limit
@param [Integer] page_size Number of records to fetch per request, when
not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)
@return [Array] Array of up to limit results
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 58 def list(activity_name: :unset, activity_sid: :unset, available: :unset, friendly_name: :unset, target_workers_expression: :unset, task_queue_name: :unset, task_queue_sid: :unset, limit: nil, page_size: nil) 59 self.stream( 60 activity_name: activity_name, 61 activity_sid: activity_sid, 62 available: available, 63 friendly_name: friendly_name, 64 target_workers_expression: target_workers_expression, 65 task_queue_name: task_queue_name, 66 task_queue_sid: task_queue_sid, 67 limit: limit, 68 page_size: page_size 69 ).entries 70 end
Retrieve a single page of WorkerInstance
records from the API. Request
is executed immediately. @param [String] activity_name The `activity_name` of the Worker resources to
read.
@param [String] activity_sid The `activity_sid` of the Worker resources to read. @param [String] available Whether to return only Worker resources that are
available or unavailable. Can be `true`, `1`, or `yes` to return Worker resources that are available, and `false`, or any value returns the Worker resources that are not available.
@param [String] friendly_name The `friendly_name` of the Worker resources to
read.
@param [String] target_workers_expression Filter by Workers that would match an
expression on a TaskQueue. This is helpful for debugging which Workers would match a potential queue.
@param [String] task_queue_name The `friendly_name` of the TaskQueue that the
Workers to read are eligible for.
@param [String] task_queue_sid The SID of the TaskQueue that the Workers to read
are eligible for.
@param [String] page_token PageToken provided by the API @param [Integer] page_number Page
Number, this value is simply for client state @param [Integer] page_size Number of records to return, defaults to 50 @return [Page] Page
of WorkerInstance
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 153 def page(activity_name: :unset, activity_sid: :unset, available: :unset, friendly_name: :unset, target_workers_expression: :unset, task_queue_name: :unset, task_queue_sid: :unset, page_token: :unset, page_number: :unset, page_size: :unset) 154 params = Twilio::Values.of({ 155 'ActivityName' => activity_name, 156 'ActivitySid' => activity_sid, 157 'Available' => available, 158 'FriendlyName' => friendly_name, 159 'TargetWorkersExpression' => target_workers_expression, 160 'TaskQueueName' => task_queue_name, 161 'TaskQueueSid' => task_queue_sid, 162 'PageToken' => page_token, 163 'Page' => page_number, 164 'PageSize' => page_size, 165 }) 166 167 response = @version.page('GET', @uri, params: params) 168 169 WorkerPage.new(@version, response, @solution) 170 end
Access the statistics @return [WorkersStatisticsContext] WorkersStatisticsContext
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 214 def statistics 215 return WorkersStatisticsContext.new(@version, @solution[:workspace_sid], ) 216 end
Streams WorkerInstance
records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached. @param [String] activity_name The `activity_name` of the Worker resources to
read.
@param [String] activity_sid The `activity_sid` of the Worker resources to read. @param [String] available Whether to return only Worker resources that are
available or unavailable. Can be `true`, `1`, or `yes` to return Worker resources that are available, and `false`, or any value returns the Worker resources that are not available.
@param [String] friendly_name The `friendly_name` of the Worker resources to
read.
@param [String] target_workers_expression Filter by Workers that would match an
expression on a TaskQueue. This is helpful for debugging which Workers would match a potential queue.
@param [String] task_queue_name The `friendly_name` of the TaskQueue that the
Workers to read are eligible for.
@param [String] task_queue_sid The SID of the TaskQueue that the Workers to read
are eligible for.
@param [Integer] limit Upper limit for the number of records to return. stream()
guarantees to never return more than limit. Default is no limit.
@param [Integer] page_size Number of records to fetch per request, when
not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)
@return [Enumerable] Enumerable that will yield up to limit results
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 99 def stream(activity_name: :unset, activity_sid: :unset, available: :unset, friendly_name: :unset, target_workers_expression: :unset, task_queue_name: :unset, task_queue_sid: :unset, limit: nil, page_size: nil) 100 limits = @version.read_limits(limit, page_size) 101 102 page = self.page( 103 activity_name: activity_name, 104 activity_sid: activity_sid, 105 available: available, 106 friendly_name: friendly_name, 107 target_workers_expression: target_workers_expression, 108 task_queue_name: task_queue_name, 109 task_queue_sid: task_queue_sid, 110 page_size: limits[:page_size], 111 ) 112 113 @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) 114 end
Provide a user friendly representation
# File lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb 220 def to_s 221 '#<Twilio.Taskrouter.V1.WorkerList>' 222 end