Class: Versafleet::JobsResource
- Defined in:
- lib/versafleet/resources/jobs.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#cancel(job_id:) ⇒ Object
Cancel a Job.
-
#create(**attributes) ⇒ Job
Create a Job.
-
#list(**params) ⇒ Collection
List All Jobs.
-
#list_tasks(job_id:) ⇒ Collection
List Tasks of Job.
-
#retrieve(job_id:) ⇒ Job
Get Job details.
-
#update(job_id:, **attributes) ⇒ Job
Update Job.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Versafleet::Resource
Instance Method Details
#cancel(job_id:) ⇒ Object
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: {})
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)
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
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
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: {})
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 |