jbr 3.9.0 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 815b57ea81f9bda41efb8b7d09a0767224763b895126a3ee56acabab6266b3fc
4
- data.tar.gz: 127a174761ddb6bc0cc00cb34ffd9e49044152d575f3f5e4f42a030f222023a5
3
+ metadata.gz: 5a315b6ba52c573f0d7fa1a0adec8145578550bd67a136071e7b8a02ea328ea1
4
+ data.tar.gz: 8c338c2f5a13ce4e98c99c2b5c11377274c71908a2b93fc6c114d8fb109ae540
5
5
  SHA512:
6
- metadata.gz: 3be4d269a045c6d9e0629a27922697f93c102259eee21762fcef02b0e5257f1b4ebd05e56812faa47e41b68a94ea440624c02621eaa95a4449db42dda94d62f4
7
- data.tar.gz: d34a6393d787cb20628cf4a18e0c63ffe63bdecaa3cf00e7e84016f8423fca125567549cda5ced525770b07d6354103be476c00d54b21b936e6769a728efe8b8
6
+ metadata.gz: e82a0f7dac54170d4f791a752f7497d0b783dce98f4057c606c3ee1f5fe73c85ef32032eb297e2406b95d82bf531d6ba1cf2f4db8a9de5be1fbef38ac1c1c69b
7
+ data.tar.gz: 82a90ec3316204bb8ccf87c4d4011e249cd7b5d4484697fc30477f553bd4146baa9402bff10f4c6c2f893ce93bc7d06509831ecaf4a7d8a16a60dfad5b0ae67d
data/README.md CHANGED
@@ -111,8 +111,10 @@ job.scheduled_at # => 2026-05-14 23:02:52
111
111
  job.completed_at # => 2026-05-18 11:36:13
112
112
  ```
113
113
 
114
- Or walk the account's jobs, oldest first. Jobber is asked for a page at a time, and only
115
- once the page before it runs out, so `first` costs one request where `to_a` costs as many
114
+ Or walk the account's jobs, oldest first. Either half of the schedule takes how much of it
115
+ you meant a duration, measured from the same now the half is split at and a walk that
116
+ stops at a boundary reads only the pages up to it. Jobber is asked for a page at a time, and
117
+ only once the page before it runs out, so `first` costs one request where `to_a` costs as many
116
118
  as the account has pages. A walk is priced by what its pages carry, and a long one can be
117
119
  refused for it: see [Rate limits](#rate-limits).
118
120
 
@@ -120,6 +122,7 @@ refused for it: see [Rate limits](#rate-limits).
120
122
  jobs = oauth.jobs # => an Enumerable of every job, nothing fetched yet
121
123
  oauth.jobs.past # => the ones dated before now, nothing fetched yet
122
124
  oauth.jobs.upcoming # => the ones dated from now on, nothing fetched yet
125
+ oauth.jobs.past(1.year) # => only as far back as a year, which is fewer pages to read
123
126
  oauth.jobs.past.ids # => %w[Z2lkOi8vS ...], every page of them, and nothing else about them
124
127
 
125
128
  job = jobs.first
@@ -178,6 +181,7 @@ Walk the account's visits, oldest first, the same way as its jobs:
178
181
  visits = oauth.visits # => an Enumerable of every visit, nothing fetched yet
179
182
  oauth.visits.upcoming # => the ones dated from now on, nothing fetched yet
180
183
  oauth.visits.past # => the ones dated before now, nothing fetched yet
184
+ oauth.visits.upcoming(3.months) # => only as far ahead as three months
181
185
  oauth.visits.upcoming.ids # => %w[Z2lkOi8vS ...], every page of them, and nothing else
182
186
 
183
187
  visit = visits.first
data/lib/jbr/listable.rb CHANGED
@@ -19,11 +19,21 @@ module Jbr
19
19
  # starts, and a page is read only once the one before it runs out.
20
20
  def each(&) = walk(page).each(&)
21
21
 
22
+ # @param within [ActiveSupport::Duration, Numeric, nil] how far ahead to look, or nil for
23
+ # as far ahead as the account is scheduled.
22
24
  # @return [Listable] the same list, narrowed to what is scheduled from now on.
23
- def upcoming = narrowed from_now
25
+ def upcoming(within = nil)
26
+ now = Time.now
27
+ narrowed after: now, before: (now + within if within)
28
+ end
24
29
 
30
+ # @param within [ActiveSupport::Duration, Numeric, nil] how far back to look, or nil for
31
+ # as far back as the account goes.
25
32
  # @return [Listable] the same list, narrowed to what started before now.
26
- def past = narrowed until_now
33
+ def past(within = nil)
34
+ now = Time.now
35
+ narrowed before: now, after: (now - within if within)
36
+ end
27
37
 
28
38
  # The ID Jobber files each record under, and nothing else about it: the cheapest question
29
39
  # an account can be walked with, and the one to ask where every record is then read on its
@@ -33,13 +43,26 @@ module Jbr
33
43
 
34
44
  private
35
45
 
36
- def narrowed(filter) = self.class.new(oauth: @oauth, includes: @includes, filter: filter)
37
-
38
46
  # The two halves of a schedule, split at the moment they are asked for rather than per
39
47
  # page: read page by page the boundary would slide, and something could cross it unseen.
40
- def from_now = { startAt: { after: Time.now.iso8601 } }
48
+ # The same moment is the near end of a window, so the far end is measured from it too.
49
+ def narrowed(after: nil, before: nil)
50
+ bounds = { after: after&.iso8601, before: before&.iso8601 }.compact
51
+ self.class.new oauth: @oauth, includes: @includes, filter: { startAt: bounds }
52
+ end
41
53
 
42
- def until_now = { startAt: { before: Time.now.iso8601 } }
54
+ # Whether a moment falls in the stretch of the schedule the list was narrowed to, for
55
+ # anything answering one without asking Jobber. A record with no moment at all is in an
56
+ # open-ended upcoming list, since nothing has started it, and in no window, since a window
57
+ # is a stretch it would have to have fallen in.
58
+ def scheduled?(at)
59
+ return true unless @filter
60
+
61
+ after, before = @filter[:startAt].values_at :after, :before
62
+ return before.nil? unless at
63
+
64
+ (after.nil? || at >= Time.iso8601(after)) && (before.nil? || at <= Time.iso8601(before))
65
+ end
43
66
 
44
67
  # Every record a paged query answers, one at a time, a page read only once the one before
45
68
  # it runs out. The filter is data: narrowed to nothing, the query narrows nothing.
data/lib/jbr/mock/jobs.rb CHANGED
@@ -13,16 +13,7 @@ module Jbr
13
13
  Enumerator.new { |yielder| selected.each { |job| yielder << Mock::Job.new(node: job) } }
14
14
  end
15
15
 
16
- # The half of the schedule the list was narrowed to, from what the app dated each job.
17
- # One it left undated is one nothing has started, so it counts as upcoming.
18
- def selected
19
- return Jbr.mock.jobs unless @filter
20
-
21
- started = @filter.dig(:startAt, :before).present?
22
- Jbr.mock.jobs.select { |job| started?(job) == started }
23
- end
24
-
25
- def started?(job) = job[:scheduled_at] ? job[:scheduled_at] <= Time.now : false
16
+ def selected = Jbr.mock.jobs.select { |job| scheduled? job[:scheduled_at] }
26
17
 
27
18
  # Only a real list is looked through: an app that mocked the list as something raising
28
19
  # was mocking the walk failing, and a lookup is a question of its own.
@@ -11,16 +11,7 @@ module Jbr
11
11
  Enumerator.new { |yielder| selected.each { |it| yielder << Mock::Visit.new(node: it) } }
12
12
  end
13
13
 
14
- # The half of the schedule the list was narrowed to, from what the app dated each visit.
15
- # One it left undated is one nothing has started, so it counts as upcoming.
16
- def selected
17
- return Jbr.mock.visits unless @filter
18
-
19
- started = @filter.dig(:startAt, :before).present?
20
- Jbr.mock.visits.select { |visit| started?(visit) == started }
21
- end
22
-
23
- def started?(visit) = visit[:starts_at] ? visit[:starts_at] <= Time.now : false
14
+ def selected = Jbr.mock.visits.select { |visit| scheduled? visit[:starts_at] }
24
15
 
25
16
  def listed(id) = Jbr.mock.visits.to_a.find { |visit| visit[:id] == id }.to_h
26
17
  end
data/lib/jbr/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # A Ruby client for the Jobber API.
2
2
  module Jbr
3
3
  # The version of this gem.
4
- VERSION = '3.9.0'
4
+ VERSION = '3.10.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo