Class: Versafleet::TasksResource
- Defined in:
- lib/versafleet/resources/tasks.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#allocate(task_id:, sub_account_id:) ⇒ Task
Allocate a Task.
-
#archive(task_id:) ⇒ Task
Archive a Task.
-
#assign(task_id:, task:) ⇒ Task
Assign a Driver to Task.
-
#assign_multiple(task:) ⇒ Object
Assign a Driver to Multiple Tasks.
-
#base_completion_histories(task_id:) ⇒ Task
View Base Task Completion Histories of a Task.
-
#cancel(task_id:) ⇒ Object
Cancel a Task.
-
#complete(task_id:) ⇒ Object
Complete a Task.
-
#completion_histories(task_id:) ⇒ Task
View Task Completion Histories of a Task.
-
#create(task_attributes:) ⇒ Task
Add Task to Job.
-
#incomplete(task_id:) ⇒ Object
Incomplete a Task.
-
#list(**params) ⇒ Collection
List All Tasks.
-
#list_by_state(**params) ⇒ Collection
List All Tasks by State.
-
#retrieve(task_id:) ⇒ Task
Get Task details.
-
#retrieve_by_tracking_id(tracking_id:) ⇒ Task
Get Task details by Tracking ID.
-
#set_state(task_id:, to_state:) ⇒ Object
Set a Task State.
-
#unarchive(task_id:) ⇒ Task
Unarchive a Task.
-
#unassign(task_id:) ⇒ Task
Unssign a Driver from Task.
-
#unassign_multiple(task:) ⇒ Object
Unsssign a Driver from Multiple Tasks.
-
#update(task_id:, task_attributes:) ⇒ Task
Update Task.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Versafleet::Resource
Instance Method Details
#allocate(task_id:, sub_account_id:) ⇒ Task
278 279 280 281 |
# File 'lib/versafleet/resources/tasks.rb', line 278 def allocate(task_id:, sub_account_id:) payload = {task: {allocatee_id: sub_account_id}} Task.new put_request("tasks/#{task_id}/allocate", body: payload).body.dig("task") end |
#archive(task_id:) ⇒ Task
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"})
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"})
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)
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
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
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)
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
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
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")
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")
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
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")
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")
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
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
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]})
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 |