Class: Twilio::REST::Taskrouter::V1::WorkspaceContext::TaskContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb,
lib/twilio-ruby/rest/taskrouter/v1/workspace/task/reservation.rb

Defined Under Namespace

Classes: ReservationContext, ReservationInstance, ReservationInstanceMetadata, ReservationList, ReservationListResponse, ReservationPage, ReservationPageMetadata

Instance Method Summary collapse

Constructor Details

#initialize(version, workspace_sid, sid) ⇒ TaskContext

Initialize the TaskContext

Parameters:

  • version (Version)

    Version that contains the resource

  • workspace_sid (String)

    The SID of the Workspace with the Task to update.

  • sid (String)

    The SID of the Task resource to update.



350
351
352
353
354
355
356
357
358
359
360
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 350

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

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

    # Dependents
    @reservations = nil
end

Instance Method Details

#delete(if_match: :unset) ⇒ Boolean

Delete the TaskInstance

Parameters:

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



365
366
367
368
369
370
371
372
373
374
375
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 365

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 TaskInstanceMetadata

Parameters:

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



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

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)
      task_instance = TaskInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      TaskInstanceMetadata.new(@version, task_instance, response.headers, response.status_code)
end

#fetchTaskInstance

Fetch the TaskInstance

Returns:



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 402

def fetch

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

#fetch_with_metadataTaskInstance

Fetch the TaskInstanceMetadata

Returns:



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

def 

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

#inspectObject

Provide a detailed, user friendly representation



568
569
570
571
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 568

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

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

Access the reservations

Returns:

Raises:

  • (ArgumentError)


543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 543

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], task_sid: @solution[:sid], )
    end

 @reservations
end

#to_sObject

Provide a user friendly representation



561
562
563
564
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 561

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

#update(attributes: :unset, assignment_status: :unset, reason: :unset, priority: :unset, task_channel: :unset, virtual_start_time: :unset, if_match: :unset) ⇒ TaskInstance

Update the TaskInstance

Parameters:

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

    The JSON string that describes the custom attributes of the task.

  • assignment_status (Status) (defaults to: :unset)
  • reason (String) (defaults to: :unset)

    The reason that the Task was canceled or completed. This parameter is required only if the Task is canceled or completed. Setting this value queues the task for deletion and logs the reason.

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

    The Task’s new priority value. When supplied, the Task takes on the specified priority unless it matches a Workflow Target with a Priority set. Value can be 0 to 2^31^ (2,147,483,647).

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

    When MultiTasking is enabled, specify the TaskChannel with the task to update. Can be the TaskChannel’s SID or its unique_name, such as voice, sms, or default.

  • virtual_start_time (Time) (defaults to: :unset)

    The task’s new virtual start time value. When supplied, the Task takes on the specified virtual start time. Value can’t be in the future or before the year of 1900.

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

    If provided, applies this mutation if (and only if) the [ETag](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).

Returns:



455
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
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 455

def update(
    attributes: :unset, 
    assignment_status: :unset, 
    reason: :unset, 
    priority: :unset, 
    task_channel: :unset, 
    virtual_start_time: :unset, 
    if_match: :unset
)

    data = Twilio::Values.of({
        'Attributes' => attributes,
        'AssignmentStatus' => assignment_status,
        'Reason' => reason,
        'Priority' => priority,
        'TaskChannel' => task_channel,
        'VirtualStartTime' => Twilio.serialize_iso8601_datetime(virtual_start_time),
    })

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

#update_with_metadata(attributes: :unset, assignment_status: :unset, reason: :unset, priority: :unset, task_channel: :unset, virtual_start_time: :unset, if_match: :unset) ⇒ TaskInstance

Update the TaskInstanceMetadata

Parameters:

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

    The JSON string that describes the custom attributes of the task.

  • assignment_status (Status) (defaults to: :unset)
  • reason (String) (defaults to: :unset)

    The reason that the Task was canceled or completed. This parameter is required only if the Task is canceled or completed. Setting this value queues the task for deletion and logs the reason.

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

    The Task’s new priority value. When supplied, the Task takes on the specified priority unless it matches a Workflow Target with a Priority set. Value can be 0 to 2^31^ (2,147,483,647).

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

    When MultiTasking is enabled, specify the TaskChannel with the task to update. Can be the TaskChannel’s SID or its unique_name, such as voice, sms, or default.

  • virtual_start_time (Time) (defaults to: :unset)

    The task’s new virtual start time value. When supplied, the Task takes on the specified virtual start time. Value can’t be in the future or before the year of 1900.

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

    If provided, applies this mutation if (and only if) the [ETag](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP [If-Match header](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match).

Returns:



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb', line 499

def (
  attributes: :unset, 
  assignment_status: :unset, 
  reason: :unset, 
  priority: :unset, 
  task_channel: :unset, 
  virtual_start_time: :unset, 
  if_match: :unset
)

    data = Twilio::Values.of({
        'Attributes' => attributes,
        'AssignmentStatus' => assignment_status,
        'Reason' => reason,
        'Priority' => priority,
        'TaskChannel' => task_channel,
        'VirtualStartTime' => Twilio.serialize_iso8601_datetime(virtual_start_time),
    })

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