Class: Versafleet::TasksResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/versafleet/resources/tasks.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Versafleet::Resource

Instance Method Details

#allocate(task_id:, sub_account_id:) ⇒ Task

Allocate a Task

Examples:

client.tasks.allocate(task_id: 123, sub_account_id: 211)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

  • sub_account_id (Integer)

    Transporter ID

Returns:



278
279
280
281
# File 'lib/versafleet/resources/tasks.rb', line 278

def allocate(task_id:, sub_account_id:)
  payload = {task: {allocatee_id: }}
  Task.new put_request("tasks/#{task_id}/allocate", body: payload).body.dig("task")
end

#archive(task_id:) ⇒ Task

Archive a Task

Examples:

client.tasks.archive(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

Returns:



221
222
223
# File 'lib/versafleet/resources/tasks.rb', line 221

def archive(task_id:)
  Task.new put_request("tasks/#{task_id}/archive", body: {}).body.dig("task")
end

#assign(task_id:, task:) ⇒ Task

Assign a Driver to Task

Examples:

client.tasks.assign(task_id: 123, task: {driver_id: 12, vehicle_id: 3, remarks: "Notes"})

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

  • task (Hash)

    Driver and Vehicle details

Returns:



110
111
112
113
# File 'lib/versafleet/resources/tasks.rb', line 110

def assign(task_id:, task:)
  payload = {task: task}
  Task.new put_request("tasks/#{task_id}/assign", body: payload).body.dig("task")
end

#assign_multiple(task:) ⇒ Object

Assign a Driver to Multiple Tasks

Examples:

client.tasks.assign_multiple(task: {ids: [12,21], driver_id: 11, vehicle_id: 2, remarks: "Notes"})

VersaFleet API

Parameters:

  • task (Hash)

    Task IDs, Driver and Vehicle details



124
125
126
127
# File 'lib/versafleet/resources/tasks.rb', line 124

def assign_multiple(task:)
  payload = {task: task}
  put_request("tasks/assign", body: payload).body
end

#base_completion_histories(task_id:) ⇒ Task

View Base Task Completion Histories of a Task

Examples:

client.tasks.base_completion_histories(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

Returns:



263
264
265
# File 'lib/versafleet/resources/tasks.rb', line 263

def base_completion_histories(task_id:)
  Task.new get_request("tasks/#{task_id}/base_task_completion_histories").body
end

#cancel(task_id:) ⇒ Object

Cancel a Task

Examples:

client.tasks.cancel(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID



166
167
168
# File 'lib/versafleet/resources/tasks.rb', line 166

def cancel(task_id:)
  put_request("tasks/#{task_id}/cancel", body: {}).body
end

#complete(task_id:) ⇒ Object

Complete a Task

Examples:

client.tasks.complete(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID



179
180
181
# File 'lib/versafleet/resources/tasks.rb', line 179

def complete(task_id:)
  put_request("tasks/#{task_id}/set_successful", body: {}).body
end

#completion_histories(task_id:) ⇒ Task

View Task Completion Histories of a Task

Examples:

client.tasks.completion_histories(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

Returns:



249
250
251
# File 'lib/versafleet/resources/tasks.rb', line 249

def completion_histories(task_id:)
  Task.new get_request("tasks/#{task_id}/task_completion_histories").body
end

#create(task_attributes:) ⇒ Task

Add Task to Job

Examples:

client.tasks.create(task_attributes: {})

VersaFleet API

Parameters:

  • task_attributes (Hash)

    Task request payload

Returns:



93
94
95
96
97
# File 'lib/versafleet/resources/tasks.rb', line 93

def create(task_attributes:)
  # TODO: Add support for allocate_id
  payload = {task_attributes: task_attributes}
  Task.new post_request("tasks", body: payload).body.dig("task")
end

#incomplete(task_id:) ⇒ Object

Incomplete a Task

Examples:

client.tasks.incomplete(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID



192
193
194
# File 'lib/versafleet/resources/tasks.rb', line 192

def incomplete(task_id:)
  put_request("tasks/#{task_id}/set_failed", body: {}).body
end

#list(**params) ⇒ Collection

List All Tasks

Examples:

client.tasks.list
# set per page to 20
client.tasks.list(per_page: 20)
# set specific date
client.tasks.list(date: "2021-01-01")

VersaFleet API

Parameters:

  • params (Hash)

    the filter query

Returns:



17
18
19
20
# File 'lib/versafleet/resources/tasks.rb', line 17

def list(**params)
  response = get_request("tasks", params: params)
  Collection.from_response(response, key: "tasks", type: Task)
end

#list_by_state(**params) ⇒ Collection

List All Tasks by State

Examples:

client.tasks.list_by_state
# tasks by state
client.tasks.list_by_state(state: "completed")

VersaFleet API

Parameters:

  • params (Hash)

    the filter query

Returns:



34
35
36
37
# File 'lib/versafleet/resources/tasks.rb', line 34

def list_by_state(**params)
  response = get_request("tasks/by_state", params: params)
  Collection.from_response(response, key: "tasks", type: Task)
end

#retrieve(task_id:) ⇒ Task

Get Task details

Examples:

client.tasks.retrieve(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

Returns:



49
50
51
# File 'lib/versafleet/resources/tasks.rb', line 49

def retrieve(task_id:)
  Task.new get_request("tasks/#{task_id}").body.dig("task")
end

#retrieve_by_tracking_id(tracking_id:) ⇒ Task

Get Task details by Tracking ID

Examples:

client.tasks.retrieve_by_tracking_id(tracking_id: "1234567891100")

VersaFleet API

Parameters:

  • tracking_id (String)

    Tracking ID

Returns:



63
64
65
# File 'lib/versafleet/resources/tasks.rb', line 63

def retrieve_by_tracking_id(tracking_id:)
  Task.new post_request("tasks/#{tracking_id}/track", body: {}).body.dig("task")
end

#set_state(task_id:, to_state:) ⇒ Object

Set a Task State

Examples:

client.tasks.set_state(task_id: 123, to_state: "waiting_for_acknowledgement")

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

  • to_state (String)

    Task state



206
207
208
209
# File 'lib/versafleet/resources/tasks.rb', line 206

def set_state(task_id:, to_state:)
  payload = {to_state: to_state}
  put_request("tasks/#{task_id}/state", body: payload).body
end

#unarchive(task_id:) ⇒ Task

Unarchive a Task

Examples:

client.tasks.unarchive(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

Returns:



235
236
237
# File 'lib/versafleet/resources/tasks.rb', line 235

def unarchive(task_id:)
  Task.new put_request("tasks/#{task_id}/unarchive", body: {}).body.dig("task")
end

#unassign(task_id:) ⇒ Task

Unssign a Driver from Task

Examples:

client.tasks.unassign(task_id: 123)

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

Returns:



139
140
141
# File 'lib/versafleet/resources/tasks.rb', line 139

def unassign(task_id:)
  Task.new put_request("tasks/#{task_id}/unassign", body: {}).body.dig("task")
end

#unassign_multiple(task:) ⇒ Object

Unsssign a Driver from Multiple Tasks

Examples:

client.tasks.unassign_multiple(task: {ids: [123,213]})

VersaFleet API

Parameters:

  • task (Hash)

    Task IDs



152
153
154
155
# File 'lib/versafleet/resources/tasks.rb', line 152

def unassign_multiple(task:)
  payload = {task: task}
  put_request("tasks/unassign", body: payload).body
end

#update(task_id:, task_attributes:) ⇒ Task

Update Task

Examples:

client.tasks.update(task_id: 123, task_attributes: {})

VersaFleet API

Parameters:

  • task_id (Integer)

    Task ID

  • task_attributes (Hash)

    Task request payload

Returns:



78
79
80
81
# File 'lib/versafleet/resources/tasks.rb', line 78

def update(task_id:, task_attributes:)
  payload = {task_attributes: task_attributes}
  Task.new put_request("tasks/#{task_id}", body: payload).body.dig("task")
end