Class: Jbr::Job

Inherits:
Resource show all
Defined in:
lib/jbr/job.rb

Overview

Work a Jobber user accepted and scheduled.

Direct Known Subclasses

Mock::Job

Constant Summary collapse

FIND =

The query that reads one job, its quote and its two timestamps.

<<~GRAPHQL
  query($id: EncodedId!) {
    job(id: $id) { id quote { id } startAt completedAt }
  }
GRAPHQL

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Jbr::Resource

Instance Attribute Details

#quote_idString? (readonly)

Returns the ID of the quote the job was won with.

Returns:

  • (String, nil)

    the ID of the quote the job was won with.



12
13
14
# File 'lib/jbr/job.rb', line 12

def quote_id
  @quote_id
end

Instance Method Details

#completed_atTime

Returns the job completed time.

Returns:

  • (Time)

    the job completed time



33
34
35
# File 'lib/jbr/job.rb', line 33

def completed_at
  Time.iso8601(@completed_at) if @completed_at
end

#find(id) ⇒ Job?

Returns itself, or nil when Jobber has no such job.

Parameters:

  • id (String)

    the Jobber ID of the job.

Returns:

  • (Job, nil)

    itself, or nil when Jobber has no such job.



16
17
18
19
20
21
22
23
24
25
# File 'lib/jbr/job.rb', line 16

def find(id)
  output = @oauth.query FIND, variables: { id: id  }
  return unless job = output['job']

  @id = job['id']
  @quote_id = job.dig 'quote', 'id'
  @scheduled_at = job['startAt']
  @completed_at = job['completedAt']
  self
end

#scheduled_atTime

Returns the job scheduled time.

Returns:

  • (Time)

    the job scheduled time



28
29
30
# File 'lib/jbr/job.rb', line 28

def scheduled_at
  Time.iso8601(@scheduled_at) if @scheduled_at
end