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, ReservationInstanceMetadata, ReservationList, ReservationListResponse, ReservationPage, ReservationPageMetadata, WorkerChannelContext, WorkerChannelInstance, WorkerChannelInstanceMetadata, WorkerChannelList, WorkerChannelListResponse, WorkerChannelPage, WorkerChannelPageMetadata, WorkerStatisticsContext, WorkerStatisticsInstance, WorkerStatisticsInstanceMetadata, WorkerStatisticsList, WorkerStatisticsListResponse, WorkerStatisticsPage, WorkerStatisticsPageMetadata, WorkersCumulativeStatisticsContext, WorkersCumulativeStatisticsInstance, WorkersCumulativeStatisticsInstanceMetadata, WorkersCumulativeStatisticsList, WorkersCumulativeStatisticsListResponse, WorkersCumulativeStatisticsPage, WorkersCumulativeStatisticsPageMetadata, WorkersRealTimeStatisticsContext, WorkersRealTimeStatisticsInstance, WorkersRealTimeStatisticsInstanceMetadata, WorkersRealTimeStatisticsList, WorkersRealTimeStatisticsListResponse, WorkersRealTimeStatisticsPage, WorkersRealTimeStatisticsPageMetadata

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 update.

  • sid (String)

    The SID of the Worker resource to update.



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 311

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
    @reservations = nil
    @real_time_statistics = nil
    @statistics = nil
    @cumulative_statistics = nil
    @worker_channels = nil
end

Instance Method Details

#cumulative_statisticsWorkersCumulativeStatisticsList, WorkersCumulativeStatisticsContext

Access the cumulative_statistics



537
538
539
540
541
542
543
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 537

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

#delete(if_match: :unset) ⇒ Boolean

Delete the WorkerInstance

Parameters:

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

    The If-Match HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



330
331
332
333
334
335
336
337
338
339
340
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 330

def delete(
  if_match: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'If-Match' => if_match, })
    
    
    

    @version.delete('DELETE', @uri, headers: headers)
end

#delete_with_metadata(if_match: :unset) ⇒ Boolean

Delete the WorkerInstanceMetadata

Parameters:

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

    The If-Match HTTP request header

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 346

def (
  if_match: :unset
)

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'If-Match' => if_match, })
    
    
    
      response = @version.('DELETE', @uri, headers: headers)
      worker_instance = WorkerInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      WorkerInstanceMetadata.new(@version, worker_instance, response.headers, response.status_code)
end

#fetchWorkerInstance

Fetch the WorkerInstance

Returns:



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 367

def fetch

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.fetch('GET', @uri, headers: headers)
    WorkerInstance.new(
        @version,
        payload,
        workspace_sid: @solution[:workspace_sid],
        sid: @solution[:sid],
    )
end

#fetch_with_metadataWorkerInstance

Fetch the WorkerInstanceMetadata

Returns:



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 387

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('GET', @uri, headers: headers)
    worker_instance = WorkerInstance.new(
        @version,
        response.body,
        workspace_sid: @solution[:workspace_sid],
        sid: @solution[:sid],
    )
    WorkerInstanceMetadata.new(
        @version,
        worker_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



573
574
575
576
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 573

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



515
516
517
518
519
520
521
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 515

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

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

Access the reservations

Returns:

Raises:

  • (ArgumentError)


496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 496

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



526
527
528
529
530
531
532
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 526

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

#to_sObject

Provide a user friendly representation



566
567
568
569
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 566

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, if_match: :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](www.twilio.com/docs/taskrouter/api/activity) for more information.

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

    The JSON string that describes the 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 {}.

  • 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 the Worker’s pending reservations. This option is only valid if the Worker’s new [Activity](www.twilio.com/docs/taskrouter/api/activity) resource has its ‘availability` property set to `False`.

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

    The If-Match HTTP request header

Returns:



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 418

def update(
  activity_sid: :unset, 
  attributes: :unset, 
  friendly_name: :unset, 
  reject_pending_reservations: :unset, 
  if_match: :unset
)

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

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'If-Match' => if_match, })
    
    
    
    
    
    payload = @version.update('POST', @uri, data: data, headers: headers)
    WorkerInstance.new(
        @version,
        payload,
        workspace_sid: @solution[:workspace_sid],
        sid: @solution[:sid],
    )
end

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

Update the WorkerInstanceMetadata

Parameters:

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

    The SID of a valid Activity that will describe the Worker’s initial state. See [Activities](www.twilio.com/docs/taskrouter/api/activity) for more information.

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

    The JSON string that describes the 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 {}.

  • 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 the Worker’s pending reservations. This option is only valid if the Worker’s new [Activity](www.twilio.com/docs/taskrouter/api/activity) resource has its ‘availability` property set to `False`.

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

    The If-Match HTTP request header

Returns:



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 456

def (
  activity_sid: :unset, 
  attributes: :unset, 
  friendly_name: :unset, 
  reject_pending_reservations: :unset, 
  if_match: :unset
)

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

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'If-Match' => if_match, })
    
    
    
    
    
    response = @version.('POST', @uri, data: data, headers: headers)
    worker_instance = WorkerInstance.new(
        @version,
        response.body,
        workspace_sid: @solution[:workspace_sid],
        sid: @solution[:sid],
    )
    WorkerInstanceMetadata.new(
        @version,
        worker_instance,
        response.headers,
        response.status_code
    )
end

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

Access the worker_channels

Returns:

Raises:

  • (ArgumentError)


548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb', line 548

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