Class: Versafleet::JobsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/versafleet/resources/jobs.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

#cancel(job_id:) ⇒ Object

Cancel a Job

Examples:

client.jobs.cancel(job_id: 123)

VersaFleet API

Parameters:

  • job_id (Integer)

    Job ID



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

def cancel(job_id:)
  put_request("v2/jobs/#{job_id}/cancel", body: {}).body
end

#create(**attributes) ⇒ Job

Create a Job

Examples:

# see the VersaFleet API for the request body reference
client.jobs.create(job: {})

VersaFleet API

Parameters:

  • attributes (Hash)

    Request body

Returns:



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

def create(**attributes)
  Job.new post_request("v2/jobs", body: attributes).body.dig("job")
end

#list(**params) ⇒ Collection

List All Jobs

Examples:

client.jobs.list
# set per page to 20
client.jobs.list(per_page: 20)
# move to page 2
client.jobs.list(page: 2, per_page: 20)
# filter by Customer ID
client.jobs.list(customer_id: 1231)

VersaFleet API

Parameters:

  • params (Hash)

    the filter query

Returns:



19
20
21
22
# File 'lib/versafleet/resources/jobs.rb', line 19

def list(**params)
  response = get_request("v2/jobs", params: params)
  Collection.from_response(response, key: "jobs", type: Job)
end

#list_tasks(job_id:) ⇒ Collection

List Tasks of Job

Examples:

client.jobs.list_tasks(job_id: 123)

VersaFleet API

Parameters:

  • job_id (Integer)

    Job ID

Returns:



92
93
94
95
# File 'lib/versafleet/resources/jobs.rb', line 92

def list_tasks(job_id:)
  response = get_request("v2/jobs/#{job_id}/tasks")
  Collection.from_response(response, key: "tasks", type: Task)
end

#retrieve(job_id:) ⇒ Job

Get Job details

Examples:

client.jobs.retrieve(job_id: 123)

VersaFleet API

Parameters:

  • job_id (Integer)

    Job ID

Returns:



65
66
67
# File 'lib/versafleet/resources/jobs.rb', line 65

def retrieve(job_id:)
  Job.new get_request("v2/jobs/#{job_id}").body.dig("job")
end

#update(job_id:, **attributes) ⇒ Job

Update Job

Examples:

# see the VersaFleet API for the request body reference
client.jobs.update(job_id: 123, job: {})

VersaFleet API

Parameters:

  • job_id (Integer)

    Job ID

  • attributes (Hash)

    Request body

Returns:



51
52
53
# File 'lib/versafleet/resources/jobs.rb', line 51

def update(job_id:, **attributes)
  Job.new put_request("v2/jobs/#{job_id}", body: attributes).body.dig("job")
end