Class: Twilio::REST::Taskrouter::V1::WorkspaceContext::WorkerContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb,
lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/reservation.rb,
lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/worker_channel.rb,
lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/worker_statistics.rb,
lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/workers_real_time_statistics.rb,
lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/workers_cumulative_statistics.rb

Defined Under Namespace

Classes: ReservationContext, ReservationInstance, ReservationList, ReservationPage, WorkerChannelContext, WorkerChannelInstance, WorkerChannelList, WorkerChannelPage, WorkerStatisticsContext, WorkerStatisticsInstance, WorkerStatisticsList, WorkerStatisticsPage, WorkersCumulativeStatisticsContext, WorkersCumulativeStatisticsInstance, WorkersCumulativeStatisticsList, WorkersCumulativeStatisticsPage, WorkersRealTimeStatisticsContext, WorkersRealTimeStatisticsInstance, WorkersRealTimeStatisticsList, WorkersRealTimeStatisticsPage

Instance Method Summary collapse

Constructor Details

#initialize(version, workspace_sid, sid) ⇒ WorkerContext

Initialize the WorkerContext

Parameters:

  • version (Version)

    Version that contains the resource

  • workspace_sid (String)

    The SID of the Workspace with the Worker to fetch.

  • sid (String)

    The SID of the Worker resource to fetch.


261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 261

def initialize(version, workspace_sid, sid)
  super(version)

  # Path Solution
  @solution = {workspace_sid: workspace_sid, sid: sid, }
  @uri = "/Workspaces/#{@solution[:workspace_sid]}/Workers/#{@solution[:sid]}"

  # Dependents
  @real_time_statistics = nil
  @cumulative_statistics = nil
  @statistics = nil
  @reservations = nil
  @worker_channels = nil
end

Instance Method Details

#cumulative_statisticsWorkersCumulativeStatisticsList, WorkersCumulativeStatisticsContext

Access the cumulative_statistics


342
343
344
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 342

def cumulative_statistics
  WorkersCumulativeStatisticsContext.new(@version, @solution[:workspace_sid], )
end

#deleteBoolean

Delete the WorkerInstance

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise


326
327
328
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 326

def delete
   @version.delete('DELETE', @uri)
end

#fetchWorkerInstance

Fetch the WorkerInstance

Returns:


279
280
281
282
283
284
285
286
287
288
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 279

def fetch
  payload = @version.fetch('GET', @uri)

  WorkerInstance.new(
      @version,
      payload,
      workspace_sid: @solution[:workspace_sid],
      sid: @solution[:sid],
  )
end

#inspectObject

Provide a detailed, user friendly representation


407
408
409
410
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 407

def inspect
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Taskrouter.V1.WorkerContext #{context}>"
end

#real_time_statisticsWorkersRealTimeStatisticsList, WorkersRealTimeStatisticsContext

Access the real_time_statistics


334
335
336
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 334

def real_time_statistics
  WorkersRealTimeStatisticsContext.new(@version, @solution[:workspace_sid], )
end

#reservations(sid = :unset) ⇒ ReservationList, ReservationContext

Access the reservations

Returns:

Raises:

  • (ArgumentError)

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 358

def reservations(sid=:unset)
  raise ArgumentError, 'sid cannot be nil' if sid.nil?

  if sid != :unset
    return ReservationContext.new(@version, @solution[:workspace_sid], @solution[:sid], sid, )
  end

  unless @reservations
    @reservations = ReservationList.new(
        @version,
        workspace_sid: @solution[:workspace_sid],
        worker_sid: @solution[:sid],
    )
  end

  @reservations
end

#statisticsWorkerStatisticsList, WorkerStatisticsContext

Access the statistics


350
351
352
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 350

def statistics
  WorkerStatisticsContext.new(@version, @solution[:workspace_sid], @solution[:sid], )
end

#to_sObject

Provide a user friendly representation


400
401
402
403
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 400

def to_s
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Taskrouter.V1.WorkerContext #{context}>"
end

#update(activity_sid: :unset, attributes: :unset, friendly_name: :unset, reject_pending_reservations: :unset) ⇒ WorkerInstance

Update the WorkerInstance

Parameters:

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

    The SID of a valid Activity that will describe the Worker's initial state. See Activities for more information.

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

    The JSON string that describes the Worker. For example: `{ “email”: “[email protected]”, “phone”: “+5095551234” }`. This data is passed to the `assignment_callback_url` when TaskRouter assigns a Task to the Worker. Defaults to {}.

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

    A descriptive string that you create to describe the Worker. It can be up to 64 characters long.

  • reject_pending_reservations (Boolean) (defaults to: :unset)

    Whether to reject pending reservations.

Returns:


305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 305

def update(activity_sid: :unset, attributes: :unset, friendly_name: :unset, reject_pending_reservations: :unset)
  data = Twilio::Values.of({
      'ActivitySid' => activity_sid,
      'Attributes' => attributes,
      'FriendlyName' => friendly_name,
      'RejectPendingReservations' => reject_pending_reservations,
  })

  payload = @version.update('POST', @uri, data: data)

  WorkerInstance.new(
      @version,
      payload,
      workspace_sid: @solution[:workspace_sid],
      sid: @solution[:sid],
  )
end

#worker_channels(sid = :unset) ⇒ WorkerChannelList, WorkerChannelContext

Access the worker_channels

Returns:

Raises:

  • (ArgumentError)

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 380

def worker_channels(sid=:unset)
  raise ArgumentError, 'sid cannot be nil' if sid.nil?

  if sid != :unset
    return WorkerChannelContext.new(@version, @solution[:workspace_sid], @solution[:sid], sid, )
  end

  unless @worker_channels
    @worker_channels = WorkerChannelList.new(
        @version,
        workspace_sid: @solution[:workspace_sid],
        worker_sid: @solution[:sid],
    )
  end

  @worker_channels
end