jbr 3.4.0 → 3.5.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: dc29abcfab78a836ad4c098926a10986bf90ec1d53a62ddcce2c6e1da47e9772
4
- data.tar.gz: 4a807c61b3173205f6e53c47f71bbee28fceaa21930c7f2cb0797663c1e53920
3
+ metadata.gz: 0f0002106d5864e3b0224d1a454f67813be100c2fca6abd411417f81ac913e53
4
+ data.tar.gz: 1e7998f2402eea55768b060ddc4057a7d513c29741b419fa5ade852caaf71a7a
5
5
  SHA512:
6
- metadata.gz: 5cabf6ed4fe94c9d71205788acf0fc0464d87fcea88e316c02acf99d509b891df9e24b912ce525053741388591e704106911ec19c3504d30121b01b22a9bcc5e
7
- data.tar.gz: 23b0588c84c8042d2b40d396ca34a7c1c34f77d20b566685cdc4ca5f1333d9482ae6779eb310de25f370449b6826b6e1331bc458e58e57e5d4a652dc03442696
6
+ metadata.gz: 6b7ce3628d2828f50173f6e41bccf9e6cb3dd2c9197dc7bcf0b30e814f49e5e27db25641835e0b8c174cd9c6e6e96daae74b16c3f532e67cf7fb6b45f466035c
7
+ data.tar.gz: 1cf960b5042097b943e62dd9ced8ab0e4adf0a084f8ca6143ea48b38c9e2510fae13b21d0576c9165916af7a85d587726d6ed34875c34a32bbe019c83632f662
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## [3.5.0] - 2026-08-17
2
+
3
+ - [Fix] A walk of jobs carrying their line items was refused outright: `Throttled`. Jobber
4
+ prices a query by the page it asks for and prices an *unbounded* connection at its own
5
+ maximum, so `lineItems` on a page of 40 jobs was charged as though every job carried the
6
+ largest job's worth of lines. The connection is bounded at 20 now, and a page of jobs is 20
7
+ rather than 40 — half the page is half the query, and a walk loses nothing by reading twice
8
+ as many. A job with more than 20 lines is summarized by its first 20
9
+ - [Fix] Jobber's own failures reach a caller as `Jbr::Error`, which is what this gem has
10
+ always said they would. `GraphQL::Error` was escaping instead, so an app that rescued
11
+ `Jbr::Error` — as the README tells it to — was not catching a throttle, a 500 or an
12
+ unreadable answer, and had its own job blow up rather than hearing that Jobber said no
13
+ - [Fix] A refusal for cost says what the cost was: `Throttled (cost 12400, 9500 of 10000
14
+ available, restoring 500/s)` rather than `Throttled`. Without the numbers there is no
15
+ telling a query too big to ever run from a bucket that needed another second
16
+ - [Change] A refused query prices the next one. Jobber reports the bucket when it says no as
17
+ readily as when it answers, and the throttle was only reading it on the way through — so a
18
+ walk that hit the ceiling then asked again immediately, at the same size, and was refused
19
+ again
20
+
1
21
  ## [3.4.0] - 2026-08-17
2
22
 
3
23
  - [New] `line_items` on a job: what the work actually was, where the title is only what
data/README.md CHANGED
@@ -126,9 +126,10 @@ line.to_s # => '3 Bathroom Faucet Installation (Professional installation of a n
126
126
  # faucet)', and without the parenthesis where nobody described it
127
127
  ```
128
128
 
129
- Every line Jobber holds is in the list, in the order it holds them and whatever each is
130
- quantified at. One it holds no quantity for reads as its name alone. Ask for nothing and
131
- nothing arrives, so `oauth.jobs.first.line_items` is empty where the query never named them.
129
+ Every line Jobber holds is in the list, up to twenty of them, in the order it holds them and
130
+ whatever each is quantified at. One it holds no quantity for reads as its name alone. Ask for
131
+ nothing and nothing arrives, so `oauth.jobs.first.line_items` is empty where the query never
132
+ named them.
132
133
 
133
134
  ### Invoices
134
135
 
@@ -205,6 +206,12 @@ done about either — every request waits for itself:
205
206
  A request that follows no other waits for nothing, so a single `find` is as quick as it ever
206
207
  was. Only a walk long enough to be a problem is slowed, and only by as much as it must be.
207
208
 
209
+ Where Jobber refuses for cost anyway, the `Jbr::Error` raised says what the query would have
210
+ cost against what was available — `Throttled (cost 12400, 9500 of 10000 available, restoring
211
+ 500/s)` — so a query too big to ever run reads apart from a bucket that needed a moment. Every
212
+ connection this gem asks for is bounded, because Jobber prices an unbounded one at its own
213
+ maximum: twenty lines to a job, and twenty jobs or visits to a page.
214
+
208
215
  ### Events
209
216
 
210
217
  Parse the payload of a Jobber event webhook:
@@ -23,13 +23,27 @@ module GraphQL
23
23
  raise Unauthorized, response.body if response.code == '401'
24
24
  raise Error, response.body unless response.is_a? Net::HTTPSuccess
25
25
  body = JSON.parse(response.body)
26
- errors = body['errors']
27
- raise Error, errors.map { |error| error['message'] }.join('; ') if errors.present?
26
+ # Before the refusal, not after it: an endpoint that reports what it will still answer
27
+ # reports it when it says no, which is when a caller most needs to know.
28
28
  yield body['extensions'] if block_given?
29
+ raise Error, refusal(body) if body['errors'].present?
29
30
  body.fetch('data')
30
31
  end
31
32
 
32
33
  private
34
+
35
+ # What the endpoint refused, and — where it priced the refusal — what the query would have
36
+ # cost against what was available. `Throttled` on its own leaves a caller unable to tell a
37
+ # query too big to ever run from a bucket that only needed a moment.
38
+ def refusal(body)
39
+ message = body['errors'].map { |error| error['message'] }.join '; '
40
+ cost = body['extensions'].to_h['cost'].to_h
41
+ status = cost['throttleStatus'].to_h
42
+ return message if status.empty?
43
+
44
+ "#{message} (cost #{cost['requestedQueryCost']}, #{status['currentlyAvailable']} of " \
45
+ "#{status['maximumAvailable']} available, restoring #{status['restoreRate']}/s)"
46
+ end
33
47
  def request_headers
34
48
  { 'Authorization' => "Bearer #{@token}", 'Content-Type' => 'application/json' }.merge @headers
35
49
  end
data/lib/jbr/jobs.rb CHANGED
@@ -29,12 +29,14 @@ module Jbr
29
29
 
30
30
  private
31
31
 
32
- # Forty a page, not a hundred: Jobber prices a query by its page size and refuses the
33
- # wider one, and what an includes brings back is charged for on top.
32
+ # Twenty a page, not forty and not a hundred: Jobber prices a query by its page size, and
33
+ # what an includes brings back is charged for on top of every row of it — so a page of jobs
34
+ # carrying their lines, their property and its client priced past what a bucket holds. Half
35
+ # the page costs half the query and loses nothing, since a walk simply reads more pages.
34
36
  def page
35
37
  <<~GRAPHQL
36
38
  query($after: String, $filter: JobFilterAttributes) {
37
- jobs(first: 40, after: $after, filter: $filter) {
39
+ jobs(first: 20, after: $after, filter: $filter) {
38
40
  nodes { #{FIELDS} #{selections} }
39
41
  pageInfo { hasNextPage endCursor }
40
42
  }
data/lib/jbr/line_item.rb CHANGED
@@ -5,8 +5,13 @@ module Jbr
5
5
  # What Jobber calls each field of a line.
6
6
  FIELDS = %w[quantity name description]
7
7
 
8
+ # The most lines to read off one record. Bounded because Jobber prices a connection by the
9
+ # page it is asked for and prices an unbounded one at its own maximum, so the lines of a
10
+ # page of jobs were charged for as though every job had the largest job's worth of them.
11
+ PAGE = 20
12
+
8
13
  # What to ask for wherever a record lists the lines it is made of.
9
- SELECTION = "lineItems { nodes { #{FIELDS.join ' '} } }"
14
+ SELECTION = "lineItems(first: #{PAGE}) { nodes { #{FIELDS.join ' '} } }"
10
15
 
11
16
  # @param nodes [Array<Hash>, nil] the lines as Jobber answered them, if it answered any.
12
17
  # @return [Array<LineItem>] one per line, in the order Jobber holds them.
data/lib/jbr/oauth.rb CHANGED
@@ -41,6 +41,11 @@ module Jbr
41
41
  client.query(statement, variables: variables) { |extensions| throttle.read extensions }
42
42
  rescue GraphQL::Unauthorized
43
43
  refresh ? retry : {}
44
+ rescue GraphQL::Error => error
45
+ # The transport's own class never leaves the gem: a caller told to rescue `Jbr::Error`
46
+ # was not catching a throttle, a 500 or an unreadable answer, and had its own job blow
47
+ # up instead of hearing that Jobber would not answer.
48
+ raise Error, error.message
44
49
  end
45
50
 
46
51
  # Delete a token. If the token is invalid, do nothing.
data/lib/jbr/throttle.rb CHANGED
@@ -21,7 +21,9 @@ module Jbr
21
21
  def read(extensions)
22
22
  cost = extensions.to_h['cost'].to_h
23
23
  status = cost['throttleStatus'].to_h
24
- @cost = cost['actualQueryCost'].to_f
24
+ # What a refused query would have cost is what it costs: Jobber prices it either way,
25
+ # and only an answered one reports an actual.
26
+ @cost = (cost['actualQueryCost'] || cost['requestedQueryCost']).to_f
25
27
  @available = status['currentlyAvailable'].to_f
26
28
  @restore_rate = status['restoreRate'].to_f
27
29
  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.4.0'
4
+ VERSION = '3.5.0'
5
5
  end
data/lib/jbr/visits.rb CHANGED
@@ -18,12 +18,12 @@ module Jbr
18
18
 
19
19
  private
20
20
 
21
- # Forty a page, not a hundred: Jobber prices a query by its page size and refuses the
22
- # wider one, and what an includes brings back is charged for on top.
21
+ # Twenty a page, the same as jobs: Jobber prices a query by its page size, and what an
22
+ # includes brings back is charged for on top of every row of it.
23
23
  def page
24
24
  <<~GRAPHQL
25
25
  query($after: String, $filter: VisitFilterAttributes) {
26
- visits(first: 40, after: $after, filter: $filter) {
26
+ visits(first: 20, after: $after, filter: $filter) {
27
27
  nodes { #{FIELDS} #{selections} }
28
28
  pageInfo { hasNextPage endCursor }
29
29
  }
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.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo