vng 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12ad7bada7d4b894eaf18aa17465cd6b892528bfeea3b4d58a65bd95dd749afa
4
- data.tar.gz: 97dcff94cf3c86f56243fd35e6ff33d7d3130b1d9db94f64a873cd5f53d32e6d
3
+ metadata.gz: eaf5c18372847d998d4e0d4c25e7bfe79ce17a11df1e573c66771cd963b3cb0a
4
+ data.tar.gz: 3cb76db925bd75bc8568607e3375ee18c6ed41f1c689b0624e2fc6de642e4be2
5
5
  SHA512:
6
- metadata.gz: eb73ebcdede819c7ce981d4ee3ee0af7af490e65b1e958318b03528825fe5714bf1d000fb75b3740ff178f0526b3ad22a385734f6c2a2b68ac9ae884b76689b2
7
- data.tar.gz: bf010d4f86acf916ec86f3b2c8b5739c549e1227473ca88964aeec94d4fc8ba7a816db9f65f06be4775ccb50f50b85baf6bc3914a3d1e6601d87a74473b73b17
6
+ metadata.gz: 527b1ced6a89489422f020b7745b6b38026d8b8187c9f3fd36abd9b55fffc21f9247a7af492c957419fe48bef126a0a3bc2894304fc23ebdb77e950446de9109
7
+ data.tar.gz: 86024f32fa8d9c432225d7b0a655336e5894e0ebfc13c11b4f39f18ce5cb9df2836ca06cb056135a86f7e52253f096cc2a0607a305d38241e4992799d87e6a00
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [2.4.0] - 2025-01-09
2
+
3
+ - Add Contact.all
4
+
1
5
  ## [2.3.1] - 2025-01-09
2
6
 
3
7
  - Fix mocks for WorkOrder.for_client_id(client_id)
data/lib/vng/contact.rb CHANGED
@@ -5,14 +5,34 @@ 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
9
9
 
10
- def initialize(id:, first_name:, last_name:, email:, phone:)
10
+ def initialize(id:, first_name:, last_name:, email:, phone:, client_id:)
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
+ end
18
+
19
+ def self.all # TODO: add (edited_after: param)
20
+ body = { isCompleteObject: 'true' }
21
+
22
+ data = request path: PATH, body: body, returning: 'Contacts'
23
+
24
+ data.filter_map do |body|
25
+ next unless body['isActive']
26
+
27
+ id = body['objectID']
28
+ first_name = value_for_field body, 127
29
+ last_name = value_for_field body, 128
30
+ email = value_for_field body, 97
31
+ phone = value_for_field body, 96
32
+ client_id = value_for_relation body, 'client'
33
+
34
+ new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone, client_id: client_id
35
+ end
16
36
  end
17
37
 
18
38
  def self.create(first_name:, last_name:, email:, phone:, client_id:)
@@ -35,7 +55,7 @@ module Vng
35
55
  email = value_for_field data, 97
36
56
  phone = value_for_field data, 96
37
57
 
38
- new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone
58
+ new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone, client_id: client_id
39
59
  end
40
60
  end
41
61
  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", "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 = '2.4.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: 2.4.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