Class: Jbr::Visit
Overview
One stop at a property: when the work on a job is scheduled to happen.
Direct Known Subclasses
Constant Summary collapse
- CLIENT_FIELDS =
What Jobber calls each field of the client the work is for, against what a caller reads.
{ id: :id, firstName: :first_name, lastName: :last_name, email: :email }
- UPCOMING =
The query that reads a page of visits starting after a moment, oldest first. Forty a page, not a hundred: Jobber prices a query by its page size and refuses the wider one.
<<~GRAPHQL query($after: String, $from: ISO8601DateTime!) { visits(first: 40, after: $after, filter: { startAt: { after: $from } }) { nodes { id title startAt endAt allDay clientConfirmed job { id } client { #{CLIENT_FIELDS.keys.join ' '} #{Phone::SELECTION} } property { id address { #{Property::SELECTION} } } } pageInfo { hasNextPage endCursor } } } GRAPHQL
Instance Method Summary collapse
-
#address ⇒ Hash
Where the work happens, in the fields Property carries.
-
#all_day? ⇒ Boolean?
Whether the visit takes the whole day rather than an hour of it.
-
#client ⇒ Hash
Who the work is for, in the fields a client is created with.
-
#client_confirmed? ⇒ Boolean?
Whether the client has confirmed the visit.
-
#ends_at ⇒ Time?
The visit end time.
-
#id ⇒ String?
The Jobber ID of the visit.
-
#initialize(oauth:, node: {}) ⇒ Visit
constructor
A new instance of Visit.
-
#job_id ⇒ String?
The ID of the job the visit belongs to.
-
#property_id ⇒ String?
The ID of the property the work happens at.
-
#starts_at ⇒ Time?
The visit start time.
-
#title ⇒ String?
What the visit is called.
-
#upcoming ⇒ Enumerator<Visit>
The visits scheduled from now on, oldest first.
Constructor Details
#initialize(oauth:, node: {}) ⇒ Visit
Returns a new instance of Visit.
25 26 27 28 |
# File 'lib/jbr/visit.rb', line 25 def initialize(oauth:, node: {}) super oauth: oauth @node = node end |
Instance Method Details
#address ⇒ Hash
Where the work happens, in the fields Property carries.
66 |
# File 'lib/jbr/visit.rb', line 66 def address = Property.fields_from @node.dig('property', 'address') |
#all_day? ⇒ Boolean?
Returns whether the visit takes the whole day rather than an hour of it.
49 |
# File 'lib/jbr/visit.rb', line 49 def all_day? = @node['allDay'] |
#client ⇒ Hash
Who the work is for, in the fields a client is created with.
59 60 61 62 |
# File 'lib/jbr/visit.rb', line 59 def client fields = CLIENT_FIELDS.to_h { |jobber, ours| [ ours, @node.dig('client', jobber.to_s) ] } fields.merge(phone: Phone.from(@node.dig('client', 'phones'))).compact end |
#client_confirmed? ⇒ Boolean?
Returns whether the client has confirmed the visit.
52 |
# File 'lib/jbr/visit.rb', line 52 def client_confirmed? = @node['clientConfirmed'] |
#ends_at ⇒ Time?
Returns the visit end time.
74 75 76 |
# File 'lib/jbr/visit.rb', line 74 def ends_at Time.iso8601(@node['endAt']) if @node['endAt'] end |
#id ⇒ String?
Returns the Jobber ID of the visit.
40 |
# File 'lib/jbr/visit.rb', line 40 def id = @node['id'] |
#job_id ⇒ String?
Returns the ID of the job the visit belongs to.
46 |
# File 'lib/jbr/visit.rb', line 46 def job_id = @node.dig 'job', 'id' |
#property_id ⇒ String?
Returns the ID of the property the work happens at.
55 |
# File 'lib/jbr/visit.rb', line 55 def property_id = @node.dig 'property', 'id' |
#starts_at ⇒ Time?
Returns the visit start time.
69 70 71 |
# File 'lib/jbr/visit.rb', line 69 def starts_at Time.iso8601(@node['startAt']) if @node['startAt'] end |
#title ⇒ String?
Returns what the visit is called.
43 |
# File 'lib/jbr/visit.rb', line 43 def title = @node['title'] |
#upcoming ⇒ Enumerator<Visit>
The visits scheduled from now on, oldest first. Nothing is read until the enumerator is walked, and a page is read only once the one before it runs out.
33 34 35 36 37 |
# File 'lib/jbr/visit.rb', line 33 def upcoming Enumerator.new do |yielder| nodes.each { |node| yielder << self.class.new(oauth: @oauth, node: node) } end end |