vng 3.4.1 → 3.5.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: 86c5764d54af7b5d5ca0fa4fa758e1f28311f3d5629196329792f0d767a44286
4
- data.tar.gz: c98f4606e09460f8ee13c4d450c136eae7ebbcb2aff694380445a050db552099
3
+ metadata.gz: 77c224107919eb31f903b177076f19139b24287cee093d03280bb856e0873636
4
+ data.tar.gz: ae7664b9509ad5186586c163ea706e90e8d4f4bfca6ed6ebbc6f9dd2e990a57e
5
5
  SHA512:
6
- metadata.gz: a485a69359c8b812f6cbb4918f01150e4c160faaebab5b89a003efbe5d9a8922362be9be6d309311b1ac078f8472615749ebeab3efb8b0327850b645b32141a6
7
- data.tar.gz: b6bdc6c10c743c9385b3bd156c235aec71fffc683dbe268bf859c1730b8f24e58016076585324001336928ab361b0d188773062fd80e25a2aa5393b4880486fb
6
+ metadata.gz: 3e9115a5876e0cf0775ed992f6b38325e353f678e30c77bded350f59f32ef4280757b524589f10b61aad4d32b32debe4e81fa4166a277d22c97f6da1ce837c68
7
+ data.tar.gz: 0ea0c1d2e3fc576cb3e14510e0f3b5c1ee8b67159d114cbe70210ffb41daa18ad78e905269133bc1f2ae0e6edd96f8d0b12e0160f6e2b459ce7fc702be6550ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [3.5.0] - 2025-01-22
2
+
3
+ - Add Asset.for_client_id
4
+
1
5
  ## [3.4.1] - 2025-01-22
2
6
 
3
7
  - Fix mock for WorkOrder#route_id
data/lib/vng/asset.rb CHANGED
@@ -5,10 +5,13 @@ module Vng
5
5
  class Asset < Resource
6
6
  PATH = '/api/v1/data/Assets/'
7
7
 
8
- attr_reader :id
8
+ attr_reader :id, :name, :weight, :breed_option_id
9
9
 
10
- def initialize(id:)
10
+ def initialize(id:, name: nil, weight: nil, breed_option_id: nil)
11
11
  @id = id
12
+ @name = name
13
+ @weight = weight
14
+ @breed_option_id = breed_option_id
12
15
  end
13
16
 
14
17
  def self.create(name:, weight:, breed_option_id:, client_id:)
@@ -24,17 +27,26 @@ module Vng
24
27
 
25
28
  data = request path: PATH, body: body
26
29
 
27
- # curl = 'curl'.tap do |curl|
28
- # curl << ' -X POST'
29
- # request.each_header{|k, v| curl << %Q{ -H "#{k}: #{v}"}}
30
- # curl << %Q{ -d '#{request.body}'} if request.body
31
- # curl << %Q{ "#{uri.to_s}"}
32
- # end
33
- # puts curl
34
-
35
30
  new id: data['Asset']['objectID']
36
31
  end
37
32
 
33
+ def self.for_client_id(client_id)
34
+ body = { clientID: client_id, isCompleteObject: 'true' }
35
+
36
+ data = request path: PATH, body: body
37
+
38
+ data.fetch('Assets', []).map do |asset|
39
+ next unless active?(asset)
40
+
41
+ id = asset['objectID']
42
+ name = asset['name']
43
+ breed_option_id = option_for_field asset, 1014
44
+ weight = value_for_field asset, 1017
45
+ weight = (Integer weight unless weight.empty?)
46
+ new id: id, name: name, weight: weight, breed_option_id: breed_option_id
47
+ end
48
+ end
49
+
38
50
  def destroy
39
51
  body = {
40
52
  method: '4',
@@ -180,6 +180,13 @@ module Vng
180
180
  end
181
181
  elsif @body[:method].eql? '4'
182
182
  {}
183
+ else
184
+ {"Assets" => [
185
+ {"objectID" => "2201008", "name" => "Fluffy", "isActive" => "true", "Fields" => [
186
+ {"fieldID" => 1014, "fieldValue" => "400", "optionID" => 400},
187
+ {"fieldID" => 1017, "fieldValue" => "", "optionID" => 0},
188
+ ]},
189
+ ]}
183
190
  end
184
191
  when '/api/v1/resources/priceBlocks/'
185
192
  if @body[:pageNo].eql? 1
data/lib/vng/resource.rb CHANGED
@@ -39,6 +39,11 @@ module Vng
39
39
  field['fieldValue'] if field
40
40
  end
41
41
 
42
+ def self.option_for_field(data, field_id)
43
+ field = data['Fields'].find { |field| field['fieldID'] == field_id }
44
+ field['optionID'] if field
45
+ end
46
+
42
47
  def self.value_for_relation(data, relation_type)
43
48
  relation = data['Relations'].find do |relation|
44
49
  relation['relationType'] == relation_type &&
data/lib/vng/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vng
2
- VERSION = '3.4.1'
2
+ VERSION = '3.5.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vng
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob