vng 2.3.1 → 3.0.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: 12ad7bada7d4b894eaf18aa17465cd6b892528bfeea3b4d58a65bd95dd749afa
4
- data.tar.gz: 97dcff94cf3c86f56243fd35e6ff33d7d3130b1d9db94f64a873cd5f53d32e6d
3
+ metadata.gz: 3ce0b4bfa1bc71ea60e74d3ded65c3a610a5a9bd02d867fab27d0e59c7272a24
4
+ data.tar.gz: 85345a62558558d22899adcdf1f052d42ef19b61d160dc0d49a87604f1292695
5
5
  SHA512:
6
- metadata.gz: eb73ebcdede819c7ce981d4ee3ee0af7af490e65b1e958318b03528825fe5714bf1d000fb75b3740ff178f0526b3ad22a385734f6c2a2b68ac9ae884b76689b2
7
- data.tar.gz: bf010d4f86acf916ec86f3b2c8b5739c549e1227473ca88964aeec94d4fc8ba7a816db9f65f06be4775ccb50f50b85baf6bc3914a3d1e6601d87a74473b73b17
6
+ metadata.gz: a1d3770ed3fe0ef347ec57deb447af38ac3b93885fee6f20e557a61c7ea788001dd1d01485b4c95b9232ca7ae3e74397aaf382b77a21fb05304a33c20c6dd34a
7
+ data.tar.gz: 53d11a0458c95f71a557531821141ec120b58dafe266952a06149fac84e348c0cd1e0a80d86298dfb242a20bfeb69010f8fad53f9e026fc7cb6418c123bd7666
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [3.0.0] - 2024-12-26
2
+
3
+ - Add Contact.edited_since(timestamp)
4
+
5
+ **Breaking changes**
6
+
7
+ - Remove Contact.all
8
+
9
+ ## [2.4.0] - 2025-01-09
10
+
11
+ - Add Contact.all
12
+
1
13
  ## [2.3.1] - 2025-01-09
2
14
 
3
15
  - Fix mocks for WorkOrder.for_client_id(client_id)
data/lib/vng/contact.rb CHANGED
@@ -5,14 +5,36 @@ module Vng
5
5
  class Contact < Resource
6
6
  PATH = '/api/v1/data/Contacts/'
7
7
 
8
- attr_reader :id, :first_name, :last_name, :email, :phone
8
+ attr_reader :id, :first_name, :last_name, :email, :phone, :client_id, :edited_at
9
9
 
10
- def initialize(id:, first_name:, last_name:, email:, phone:)
10
+ def initialize(id:, first_name:, last_name:, email:, phone:, client_id:, edited_at: nil)
11
11
  @id = id
12
12
  @first_name = first_name
13
13
  @last_name = last_name
14
14
  @email = email
15
15
  @phone = phone
16
+ @client_id = client_id
17
+ @edited_at = edited_at
18
+ end
19
+
20
+ def self.edited_since(timestamp)
21
+ body = { isCompleteObject: 'true', dateStart: timestamp.to_i, dateMode: 2 }
22
+
23
+ data = request path: PATH, body: body, returning: 'Contacts'
24
+
25
+ data.filter_map do |body|
26
+ next unless body['isActive']
27
+
28
+ id = body['objectID']
29
+ first_name = value_for_field body, 127
30
+ last_name = value_for_field body, 128
31
+ email = value_for_field body, 97
32
+ phone = value_for_field body, 96
33
+ client_id = value_for_relation body, 'client'
34
+ edited_at = Time.at Integer(body['dateLastEdited']), in: 'UTC'
35
+
36
+ new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone, client_id: client_id, edited_at: edited_at
37
+ end
16
38
  end
17
39
 
18
40
  def self.create(first_name:, last_name:, email:, phone:, client_id:)
@@ -35,7 +57,7 @@ module Vng
35
57
  email = value_for_field data, 97
36
58
  phone = value_for_field data, 96
37
59
 
38
- new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone
60
+ new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone, client_id: client_id
39
61
  end
40
62
  end
41
63
  end
@@ -121,12 +121,27 @@ module Vng
121
121
  ] }
122
122
  end
123
123
  when '/api/v1/data/Contacts/'
124
- { "Contact"=>{ "objectID"=>"2201007" }, "Fields"=>[
125
- { "fieldID"=>127, "fieldValue"=>"Vng" },
126
- { "fieldID"=>128, "fieldValue"=>"Example" },
127
- { "fieldID"=>97, "fieldValue"=>"vng@example.com" },
128
- { "fieldID"=>96, "fieldValue"=>"8648648640" },
129
- ] }
124
+ if @body[:pageNo].eql? 1
125
+ {"Contacts" => [
126
+ {"objectID" => "2201007", "dateLastEdited" => "1736479080", "isActive" => "true", "Fields" => [
127
+ {"fieldID"=>127, "fieldValue"=>"Vng" },
128
+ {"fieldID"=>128, "fieldValue"=>"Example" },
129
+ {"fieldID"=>97, "fieldValue"=>"vng@example.com" },
130
+ {"fieldID"=>96, "fieldValue"=>"8648648640" },
131
+ ], "Relations" => [
132
+ {"objectID" => 915738, "relationType" => "client", "isActive" => "true"},
133
+ ]}
134
+ ]}
135
+ elsif @body[:pageNo].nil?
136
+ { "Contact"=>{ "objectID"=>"2201007" }, "Fields"=> [
137
+ { "fieldID"=>127, "fieldValue"=>"Vng" },
138
+ { "fieldID"=>128, "fieldValue"=>"Example" },
139
+ { "fieldID"=>97, "fieldValue"=>"vng@example.com" },
140
+ { "fieldID"=>96, "fieldValue"=>"8648648640" },
141
+ ] }
142
+ else
143
+ { }
144
+ end
130
145
  when '/api/v1/data/Locations/'
131
146
  { "Location"=>{ "objectID"=>995681 } }
132
147
  when '/api/v1/data/Assets/'
data/lib/vng/resource.rb CHANGED
@@ -10,10 +10,14 @@ module Vng
10
10
  body = body.merge securityToken: Vng.configuration.security_token
11
11
  end
12
12
 
13
+ # TODO: I have to redo the pagination as a yield block for each page
14
+
13
15
  if returning
14
16
  [].tap do |response|
15
17
  1.step do |page_number|
16
- body = body.merge pageSize: 500, pageNo: page_number
18
+ # ORDER BY edited ASC
19
+ body = body.merge pageSize: 500, pageNo: page_number, sortMode: 3, sortDirection: 0
20
+
17
21
  batch = response_for(path:, body:, query:).fetch(returning, [])
18
22
  break if batch.empty? || page_number > 20
19
23
  response.concat batch
@@ -35,6 +39,14 @@ module Vng
35
39
  field['fieldValue'] if field
36
40
  end
37
41
 
42
+ def self.value_for_relation(data, relation_type)
43
+ relation = data['Relations'].find do |relation|
44
+ relation['relationType'] == relation_type &&
45
+ relation['isActive'] == 'true'
46
+ end
47
+ relation['objectID'] if relation
48
+ end
49
+
38
50
  # @return [String] the Vonigo API host.
39
51
  def self.host
40
52
  Vng.configuration.host
data/lib/vng/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vng
2
- VERSION = '2.3.1'
2
+ VERSION = '3.0.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vng
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-09 00:00:00.000000000 Z
10
+ date: 2025-01-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: simplecov