jbr 2.1.0 → 2.3.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: 6938d7f413fe243d95247911154afacb7ec9098710f784b9032bbf5bf3d60e37
4
- data.tar.gz: 7b1b8c0f7b3b339ec96dd1f3343b75528a2a78755c752a0f779218746953b541
3
+ metadata.gz: 3bfdb96b9790f402fd9176cc2acbe42fec07d4a23e9b06b7f217297e2bfb6fcd
4
+ data.tar.gz: a09d5f78a7c996a1e6bf912b09ba1ee30c4f6805ac40b626848e79bb544104bd
5
5
  SHA512:
6
- metadata.gz: 9f4b95151294dc8d1119bc51d5fe63544ca66a0d7073b65e1de0e6b315e9d7cffea572d21567aa05c94a9df5692e0460aa454f531e1a86967209b6e3f81c2d11
7
- data.tar.gz: f1b7ed20d0eddab211e5a0ca5a68fbf6bfd25762ba20ccde8d76349e6a1fa986bc6dbc3cc062cced2947a8617fdd69cec3e33dcf8031158c24294fd0f8aaaff2
6
+ metadata.gz: 941d93dd184d08aadfd4b4c454bed5945e28b9bd2600b8e3798515656286c4806effa7995d06f47fa37d43974925c629cb77c13528dd21264cbf1e77e2e8717d
7
+ data.tar.gz: 4b31eb73766e34a1aa60d9d7f0b0c4725257cb90f8e2ea1d28792b65fec581b30b43b03878c11328edd7e96cb0fef11b5e0b0a1fab827133fe12b2e69d17c436
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [2.3.0] - 2026-08-07
2
+
3
+ - [Breaking change] A client's phone is the number Jobber holds as reachable rather than
4
+ the string on the record: the primary before the rest, one that takes texts before one
5
+ that does not, and the first of those the North American plan recognizes, ten digits
6
+ without the country code. A client with no such number now answers nil
7
+
8
+ ## [2.2.0] - 2026-08-07
9
+
10
+ - [New] Carry the client a visit is for -- id, first name, last name, phone and email --
11
+ and the ID of the property it happens at, so an app can file a visit against the people
12
+ and places it already knows
13
+
1
14
  ## [2.1.0] - 2026-08-07
2
15
 
3
16
  - [New] Fetch the visits an account has scheduled from now on, with oauth.visits.upcoming.
data/README.md CHANGED
@@ -98,6 +98,10 @@ visit = visits.first
98
98
  visit.id # => 'Z2lkOi8vS'
99
99
  visit.title # => 'Furnace tune-up'
100
100
  visit.job_id # => 'Z2lkOi8vS'
101
+ visit.property_id # => 'Z2lkOi8vS'
102
+ visit.client # => { id: 'Z2lkOi8vS', first_name: 'Jane', last_name: 'Doe',
103
+ # phone: '5553335555', email: 'jane@example.com' }
104
+ # phone is the reachable North American number, ten digits, or nil
101
105
  visit.address # => { street: '1 Main St', city: 'Raleigh', state: 'NC', zip: '27601',
102
106
  # latitude: 35.77, longitude: -78.63 }
103
107
  visit.starts_at # => 2026-08-09 14:00:00
@@ -171,6 +175,7 @@ Mock successfully fetching upcoming visits:
171
175
 
172
176
  ```ruby
173
177
  Jbr.mock.visits = [ { id: 'visit-01', title: 'Furnace tune-up', job_id: 'job-01',
178
+ property_id: 'property-01', client: { id: 'client-01', first_name: 'Jane' },
174
179
  address: { street: '1 Main St', city: 'Raleigh', state: 'NC', zip: '27601' },
175
180
  starts_at: Date.tomorrow.noon, ends_at: Date.tomorrow.end_of_day,
176
181
  all_day: false, client_confirmed: true } ]
@@ -15,6 +15,10 @@ module Jbr
15
15
 
16
16
  def job_id = @node[:job_id]
17
17
 
18
+ def property_id = @node[:property_id]
19
+
20
+ def client = @node.fetch :client, {}
21
+
18
22
  def address = @node.fetch :address, {}
19
23
 
20
24
  def all_day? = @node[:all_day]
data/lib/jbr/phone.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Jbr
2
+ # The numbers on a client's file, and which of them the client is reached on.
3
+ class Phone
4
+ # What Jobber is asked for wherever a client is read: the number, and what ranks it.
5
+ SELECTION = 'phones { normalizedPhoneNumber smsAllowed primary }'
6
+
7
+ # Ten digits whose area code and exchange open with 2 through 9, behind the E.164 +1.
8
+ NORTH_AMERICAN = /\A\+1([2-9]\d{2}[2-9]\d{6})\z/
9
+
10
+ # The number to reach a client on, without its country code.
11
+ # @param phones [Array<Hash>, nil] the numbers as Jobber answered them.
12
+ # @return [String, nil] the ten digits to call, or nil where none can be dialed.
13
+ def self.from(phones)
14
+ # The index breaks a tie because sort_by does not: two equally ranked numbers would
15
+ # otherwise swap between runs, and the client would answer a different phone each time.
16
+ ranked = Array(phones).each_with_index.sort_by do |phone, index|
17
+ [ phone['primary'] ? 0 : 1, phone['smsAllowed'] ? 0 : 1, index ]
18
+ end
19
+ numbers = ranked.lazy.map { |phone, _| phone['normalizedPhoneNumber'].to_s }
20
+ numbers.filter_map { |number| number[NORTH_AMERICAN, 1] }.first
21
+ end
22
+ end
23
+ 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 = '2.1.0'
4
+ VERSION = '2.3.0'
5
5
  end
data/lib/jbr/visit.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  module Jbr
2
2
  # One stop at a property: when the work on a job is scheduled to happen.
3
3
  class Visit < Resource
4
+ # What Jobber calls each field of the client the work is for, against what a caller reads.
5
+ CLIENT_FIELDS = { id: :id, firstName: :first_name, lastName: :last_name, email: :email }
6
+
4
7
  # The query that reads a page of visits starting after a moment, oldest first. Forty a
5
8
  # page, not a hundred: Jobber prices a query by its page size and refuses the wider one.
6
9
  UPCOMING = <<~GRAPHQL
@@ -9,7 +12,8 @@ module Jbr
9
12
  nodes {
10
13
  id title startAt endAt allDay clientConfirmed
11
14
  job { id }
12
- property { address { #{Property::SELECTION} } }
15
+ client { #{CLIENT_FIELDS.keys.join ' '} #{Phone::SELECTION} }
16
+ property { id address { #{Property::SELECTION} } }
13
17
  }
14
18
  pageInfo { hasNextPage endCursor }
15
19
  }
@@ -47,6 +51,16 @@ module Jbr
47
51
  # @return [Boolean, nil] whether the client has confirmed the visit.
48
52
  def client_confirmed? = @node['clientConfirmed']
49
53
 
54
+ # @return [String, nil] the ID of the property the work happens at.
55
+ def property_id = @node.dig 'property', 'id'
56
+
57
+ # Who the work is for, in the fields a client is created with.
58
+ # @return [Hash] any of :id, :first_name, :last_name, :phone and :email.
59
+ def client
60
+ fields = CLIENT_FIELDS.to_h { |jobber, ours| [ ours, @node.dig('client', jobber.to_s) ] }
61
+ fields.merge(phone: Phone.from(@node.dig('client', 'phones'))).compact
62
+ end
63
+
50
64
  # Where the work happens, in the fields {Property} carries.
51
65
  # @return [Hash] any of :street, :city, :state, :zip, :latitude and :longitude.
52
66
  def address = Property.fields_from @node.dig('property', 'address')
data/lib/jbr.rb CHANGED
@@ -14,7 +14,8 @@ require 'jbr/request'
14
14
  require 'jbr/oauth'
15
15
 
16
16
  require 'jbr/account'
17
- # Property comes before Client and Visit: their queries read its fields as they load.
17
+ # Phone and Property come before Client and Visit: their queries read these as they load.
18
+ require 'jbr/phone'
18
19
  require 'jbr/property'
19
20
  require 'jbr/client'
20
21
  require 'jbr/invoice'
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: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
@@ -111,6 +111,7 @@ files:
111
111
  - lib/jbr/mock/visit.rb
112
112
  - lib/jbr/mocking.rb
113
113
  - lib/jbr/oauth.rb
114
+ - lib/jbr/phone.rb
114
115
  - lib/jbr/property.rb
115
116
  - lib/jbr/quote.rb
116
117
  - lib/jbr/request.rb