huginn_acumen_product_agent 1.2.1 → 1.2.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a99adb8ef72e51a149b349a6acf70a67e5508d54288d5d06e560e1cc686748a
|
4
|
+
data.tar.gz: ff73fc37c85d3a181348b0494d4844e5b30fa96db548c554c1d2a46c59e1fc21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cae798dcb83e98878a4537ae76727233faac0d6ee375172fcbb0ba23a639e489d7035546220da5136ccdac3adbf56f222f0f4451632991e04528de3198e5fbb7
|
7
|
+
data.tar.gz: 5d7177a669c4ab7f990f0d19cd5e6ffa9f35bd837a2d044f8bd8bc6cd8e92061261405e006d2285d3679549ac2e1de7f156e9c2d0894b048be909a16c968c734
|
@@ -19,6 +19,8 @@ module Agents
|
|
19
19
|
'endpoint' => 'https://example.com',
|
20
20
|
'site_code' => '',
|
21
21
|
'password' => '',
|
22
|
+
'physical_formats' => [],
|
23
|
+
'digital_formats' => [],
|
22
24
|
'attribute_to_property' => {},
|
23
25
|
'contributor_types_map' => {},
|
24
26
|
}
|
@@ -37,6 +39,14 @@ module Agents
|
|
37
39
|
errors.add(:base, 'password is a required field')
|
38
40
|
end
|
39
41
|
|
42
|
+
unless options['physical_formats'].present?
|
43
|
+
errors.add(:base, "physical_formats is a required field")
|
44
|
+
end
|
45
|
+
|
46
|
+
unless options['digital_formats'].present?
|
47
|
+
errors.add(:base, "digital_formats is a required field")
|
48
|
+
end
|
49
|
+
|
40
50
|
unless options['attribute_to_property'].is_a?(Hash)
|
41
51
|
errors.add(:base, "if provided, attribute_to_property must be a hash")
|
42
52
|
end
|
@@ -66,6 +76,8 @@ module Agents
|
|
66
76
|
endpoint = interpolated['endpoint']
|
67
77
|
site_code = interpolated['site_code']
|
68
78
|
password = interpolated['password']
|
79
|
+
physical_formats = interpolated['physical_formats']
|
80
|
+
digital_formats = interpolated['digital_formats']
|
69
81
|
|
70
82
|
auth = {
|
71
83
|
'site_code' => site_code,
|
@@ -76,7 +88,7 @@ module Agents
|
|
76
88
|
|
77
89
|
ids = event.payload['ids']
|
78
90
|
products = get_products_by_ids(client, ids)
|
79
|
-
products = get_product_variants(client, products)
|
91
|
+
products = get_product_variants(client, products, physical_formats, digital_formats)
|
80
92
|
products = get_product_categories(client, products)
|
81
93
|
products = get_product_contributors(client, products)
|
82
94
|
|
@@ -60,7 +60,7 @@ module AcumenProductQueryConcern
|
|
60
60
|
products
|
61
61
|
end
|
62
62
|
|
63
|
-
def get_product_variants(acumen_client, products)
|
63
|
+
def get_product_variants(acumen_client, products, physical_formats, digital_formats)
|
64
64
|
ids = products.map { |product| product['identifier'] }
|
65
65
|
# fetch product/variant relationships
|
66
66
|
variant_links = get_variants_for_ids(acumen_client, ids)
|
@@ -72,7 +72,7 @@ module AcumenProductQueryConcern
|
|
72
72
|
variants = get_products_by_ids(acumen_client, variant_ids)
|
73
73
|
|
74
74
|
# merge variants and products together
|
75
|
-
process_products_and_variants(products, variants, variant_links)
|
75
|
+
process_products_and_variants(products, variants, variant_links, physical_formats, digital_formats)
|
76
76
|
end
|
77
77
|
|
78
78
|
def get_product_categories(acumen_client, products)
|
@@ -108,7 +108,7 @@ module AcumenProductQueryConcern
|
|
108
108
|
'Inv_Product.Pub_Date' => 'datePublished',
|
109
109
|
})
|
110
110
|
variant['@type'] = 'ProductModel'
|
111
|
-
variant['isDefault'] =
|
111
|
+
variant['isDefault'] = false
|
112
112
|
variant['isTaxable'] = field_value(p, 'Inv_Product.Taxable') == '1'
|
113
113
|
variant['acumenAttributes'] = {
|
114
114
|
'is_master' => field_value(p, 'Inv_Product.OnWeb_LinkOnly') == '0'
|
@@ -358,7 +358,7 @@ module AcumenProductQueryConcern
|
|
358
358
|
results
|
359
359
|
end
|
360
360
|
|
361
|
-
def process_products_and_variants(products, variants, links)
|
361
|
+
def process_products_and_variants(products, variants, links, physical_formats, digital_formats)
|
362
362
|
products_map = {}
|
363
363
|
products.each { |product| products_map[product['identifier']] = product }
|
364
364
|
|
@@ -375,6 +375,31 @@ module AcumenProductQueryConcern
|
|
375
375
|
|
376
376
|
result = []
|
377
377
|
products_map.each_value { |p| result.push(p) }
|
378
|
+
|
379
|
+
result.each do |product|
|
380
|
+
if product['model'].length == 1
|
381
|
+
product['model'][0]['isDefault'] = true
|
382
|
+
next
|
383
|
+
else
|
384
|
+
physical_formats.each do |val|
|
385
|
+
match = product['model'].select { |v| v[field_value(product, 'Inv_Product.Category')] == val }
|
386
|
+
|
387
|
+
if match
|
388
|
+
match['isDefault'] = true
|
389
|
+
break
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
digital_formats.each do |val|
|
394
|
+
match = product['model'].select { |v| v[field_value(product, 'Inv_Product.Category')] == val }
|
395
|
+
|
396
|
+
if match
|
397
|
+
match['isDefault'] = true
|
398
|
+
break
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
378
403
|
result
|
379
404
|
end
|
380
405
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huginn_acumen_product_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Spizziri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|