jbr 1.0.8 → 1.2.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 +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/jbr/client.rb +44 -3
- data/lib/jbr/event.rb +5 -0
- data/lib/jbr/request.rb +9 -3
- data/lib/jbr/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68463c13bcdbb8a69d415d79426415cab50a27d805c96132859c0301e3eab8b2
|
|
4
|
+
data.tar.gz: f134a69e00d4cf3a6b0382701a05c81de434f5a246555d8f8955c97512806ced
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba24574d4b690e6b22019414dd17c0a63ab07f5f7239667da987fc6f6b0f7c0b809ca863b64e52e62408c2f887c18c591450499d949c01cb3b805fbd29ed90eb
|
|
7
|
+
data.tar.gz: 40bd20b0fbe0315613a2fd883ceb906f48f5e088ac53b1bc631a453c795a0bc71a0a4c0dc7f59fd8ca91611707055cb877adecfbefeceb41224204d3045d2c3f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
## [1.2.0] - 2026-06-09
|
|
2
|
+
|
|
3
|
+
- [New] Create a Property with a Request if needed
|
|
4
|
+
|
|
5
|
+
## [1.1.0] - 2026-05-27
|
|
6
|
+
|
|
7
|
+
- [New] Add Jbr::Event.params_for
|
|
8
|
+
|
|
1
9
|
## [1.0.8] - 2026-05-26
|
|
2
10
|
|
|
3
|
-
- [New] Add Jbr.client_id and Jbr.client_secret
|
|
11
|
+
- [New] Add Jbr::OAuth.client_id and Jbr::OAuth.client_secret
|
|
4
12
|
|
|
5
13
|
## [1.0.7] - 2026-05-26
|
|
6
14
|
|
data/lib/jbr/client.rb
CHANGED
|
@@ -2,16 +2,32 @@ module Jbr
|
|
|
2
2
|
class Client < Resource
|
|
3
3
|
LOOKUP = <<~GRAPHQL.freeze
|
|
4
4
|
query($searchTerm: String!) {
|
|
5
|
-
clientPhones(searchTerm: $searchTerm) { nodes {
|
|
5
|
+
clientPhones(first: 1, searchTerm: $searchTerm) { nodes {
|
|
6
|
+
client { id updatedAt clientProperties { nodes { id address { street city province postalCode } }} }
|
|
7
|
+
} }
|
|
6
8
|
}
|
|
7
9
|
GRAPHQL
|
|
8
10
|
|
|
9
11
|
CREATE = <<~GRAPHQL.freeze
|
|
10
12
|
mutation($input: ClientCreateInput!) {
|
|
11
|
-
clientCreate(input: $input) {
|
|
13
|
+
clientCreate(input: $input) {
|
|
14
|
+
client { id clientProperties(first: 1) { nodes { id } } }
|
|
15
|
+
userErrors { message }
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
GRAPHQL
|
|
14
19
|
|
|
20
|
+
CREATE_PROPERTY = <<~GRAPHQL.freeze
|
|
21
|
+
mutation propertyCreateMutation($clientId: EncodedId!, $input: PropertyCreateInput!) {
|
|
22
|
+
propertyCreate(clientId: $clientId, input: $input) {
|
|
23
|
+
properties { id }
|
|
24
|
+
userErrors { message }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
GRAPHQL
|
|
28
|
+
|
|
29
|
+
attr_reader :property_id
|
|
30
|
+
|
|
15
31
|
# Create a client instance with the provided attributes.
|
|
16
32
|
# @return [Client] itself
|
|
17
33
|
# @param params [Hash] the attributes of the client
|
|
@@ -35,20 +51,45 @@ module Jbr
|
|
|
35
51
|
recent = (output.dig('clientPhones', 'nodes') || []).max_by do |clients|
|
|
36
52
|
clients.dig('client', 'updatedAt') || ''
|
|
37
53
|
end
|
|
38
|
-
|
|
54
|
+
return unless recent
|
|
55
|
+
|
|
56
|
+
@id = recent.dig 'client', 'id'
|
|
57
|
+
|
|
58
|
+
properties = recent.dig('client', 'clientProperties', 'nodes') || []
|
|
59
|
+
existing_property = properties.find do |property|
|
|
60
|
+
extract_address_from(@create_params[:address]).stringify_keys == property['address']
|
|
61
|
+
end
|
|
62
|
+
@property_id = if existing_property
|
|
63
|
+
existing_property['id']
|
|
64
|
+
else
|
|
65
|
+
property = @oauth.query CREATE_PROPERTY, variables: { clientId: @id, input: { properties: [ { address: extract_address_from(@create_params[:address]) }] } }
|
|
66
|
+
(property&.dig('propertyCreate', 'properties')&.first || {})['id']
|
|
67
|
+
end
|
|
68
|
+
true
|
|
39
69
|
end
|
|
40
70
|
|
|
41
71
|
def create
|
|
42
72
|
output = @oauth.query CREATE, variables: { input: input }
|
|
43
73
|
@id = output.dig 'clientCreate', 'client', 'id'
|
|
74
|
+
|
|
75
|
+
properties = output.dig 'clientCreate', 'client', 'clientProperties', 'nodes'
|
|
76
|
+
@property_id = (properties.first || {})['id']
|
|
44
77
|
end
|
|
45
78
|
|
|
46
79
|
def input
|
|
47
80
|
{ firstName: @create_params[:first_name],
|
|
48
81
|
lastName: @create_params[:last_name],
|
|
82
|
+
properties: ([{ address: extract_address_from(@create_params[:address]) }] if @create_params[:address].present?),
|
|
49
83
|
phones: [{ number: @create_params[:phone], primary: true }],
|
|
50
84
|
emails: ([{ address: @create_params[:email], primary: true }] if @create_params[:email].present?)
|
|
51
85
|
}.compact
|
|
52
86
|
end
|
|
87
|
+
|
|
88
|
+
def extract_address_from(fields = {})
|
|
89
|
+
{
|
|
90
|
+
street1: fields[:street], city: fields[:city],
|
|
91
|
+
province: fields[:state], postalCode: fields[:zip]
|
|
92
|
+
}.compact
|
|
93
|
+
end
|
|
53
94
|
end
|
|
54
95
|
end
|
data/lib/jbr/event.rb
CHANGED
|
@@ -13,5 +13,10 @@ module Jbr
|
|
|
13
13
|
|
|
14
14
|
# @return [String] unique identifier of the event account.
|
|
15
15
|
def account_id = @params.dig :data, :webHookEvent, :accountId
|
|
16
|
+
|
|
17
|
+
# @return [Hash] the shape of the payload sent by Jobber to the callback URL.
|
|
18
|
+
def self.params_for(item_id:, account_id:)
|
|
19
|
+
{ data: { webHookEvent: { itemId: item_id, accountId: account_id } } }
|
|
20
|
+
end
|
|
16
21
|
end
|
|
17
22
|
end
|
data/lib/jbr/request.rb
CHANGED
|
@@ -2,7 +2,7 @@ module Jbr
|
|
|
2
2
|
class Request < Resource
|
|
3
3
|
CREATE = <<~GRAPHQL.freeze
|
|
4
4
|
mutation($input: RequestCreateInput!) {
|
|
5
|
-
requestCreate(input: $input) { request { id } userErrors { message } }
|
|
5
|
+
requestCreate(input: $input) { request { id property { id } } userErrors { message } }
|
|
6
6
|
}
|
|
7
7
|
GRAPHQL
|
|
8
8
|
|
|
@@ -18,8 +18,14 @@ module Jbr
|
|
|
18
18
|
# @option params [String] :title the reason why the lead is created
|
|
19
19
|
# @option params [String] :instructions a comment about the lead
|
|
20
20
|
def create(params = {})
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
client = @oauth.clients.create_with(params).find_or_create_by(phone: params[:phone])
|
|
22
|
+
@client_id = client.id
|
|
23
|
+
@property_id = client.property_id
|
|
24
|
+
|
|
25
|
+
input = {
|
|
26
|
+
clientId: @client_id, title: params[:title], propertyId: @property_id,
|
|
27
|
+
assessment: { instructions: params[:instructions] }
|
|
28
|
+
}
|
|
23
29
|
output = @oauth.query CREATE, variables: { input: input }
|
|
24
30
|
@id = output.dig 'requestCreate', 'request', 'id'
|
|
25
31
|
self
|
data/lib/jbr/version.rb
CHANGED