huginn_acumen_product_agent 1.5.1 → 1.7.1
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: f139af2f44d6618c028e02f0e32392f4d86b9d93bd671fd4d30f97cfe5d285a3
|
4
|
+
data.tar.gz: 389101ff173b00ba5e995826ce02ff0f04d6bf0b14059a1d68998ef882b3e7ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '079581a58cddd69561dc20c7ed8b9e131aad0ec78c76b365ca6ecd7cacd1b114dd21ed9533b24beec13534fa6a0373d12da9b6e01274a33a540a0877553f3185'
|
7
|
+
data.tar.gz: d3623463c67be3cd512f2f0e2199f8c51249abc99c461b502738e7b4fac0e5afb2886eb8fe15b6096920df2d8e856b8836c38767aabf586b71b4d30b63d0681c
|
@@ -95,6 +95,8 @@ class AcumenClient
|
|
95
95
|
<column_name>Inv_Product.Category</column_name>
|
96
96
|
<column_name>Inv_Product.Next_Release</column_name>
|
97
97
|
<column_name>Inv_Product.BO_Reason</column_name>
|
98
|
+
<column_name>Inv_Product.Not_On_Website</column_name>
|
99
|
+
<column_name>Inv_Product.Not_Active</column_name>
|
98
100
|
</requested_output>
|
99
101
|
</acusoapRequest>
|
100
102
|
XML
|
@@ -11,7 +11,28 @@ module Agents
|
|
11
11
|
default_schedule 'never'
|
12
12
|
|
13
13
|
description <<-MD
|
14
|
-
Huginn agent for sane ACUMEN product data.
|
14
|
+
Huginn agent for retrieving sane ACUMEN product data.
|
15
|
+
|
16
|
+
## Agent Options
|
17
|
+
The following outlines the available options in this agent
|
18
|
+
|
19
|
+
### Acumen Connection
|
20
|
+
* endpoint: The root URL for the Acumen API
|
21
|
+
* site_code: The site code from Acumen
|
22
|
+
* password: The Acumen API password
|
23
|
+
|
24
|
+
### Variant Settings
|
25
|
+
* physical_formats: A list of the formats associated with a physical product
|
26
|
+
* digital_formats: A list of the formats associated with a digital product
|
27
|
+
|
28
|
+
### Product Attributes
|
29
|
+
* attribute_to_property: An optional map linking Acumen attributes to Schema.org
|
30
|
+
product properties.
|
31
|
+
|
32
|
+
### Other Options
|
33
|
+
* ignore_skus: An optional array of Acumen product skus that will be intentionally
|
34
|
+
excluded from any output.
|
35
|
+
|
15
36
|
MD
|
16
37
|
|
17
38
|
def default_options
|
@@ -22,7 +43,6 @@ module Agents
|
|
22
43
|
'physical_formats' => [],
|
23
44
|
'digital_formats' => [],
|
24
45
|
'attribute_to_property' => {},
|
25
|
-
'contributor_types_map' => {},
|
26
46
|
}
|
27
47
|
end
|
28
48
|
|
@@ -51,8 +71,10 @@ module Agents
|
|
51
71
|
errors.add(:base, "if provided, attribute_to_property must be a hash")
|
52
72
|
end
|
53
73
|
|
54
|
-
|
55
|
-
|
74
|
+
if options['ignore_skus']
|
75
|
+
unless options['ignore_skus'].is_a?(Array)
|
76
|
+
errors.add(:base, "if provided, ignore_skus must be an array")
|
77
|
+
end
|
56
78
|
end
|
57
79
|
end
|
58
80
|
|
@@ -78,6 +100,7 @@ module Agents
|
|
78
100
|
password = interpolated['password']
|
79
101
|
physical_formats = interpolated['physical_formats']
|
80
102
|
digital_formats = interpolated['digital_formats']
|
103
|
+
ignore_skus = interpolated['ignore_skus'] ? interpolated['ignore_skus'] : []
|
81
104
|
|
82
105
|
auth = {
|
83
106
|
'site_code' => site_code,
|
@@ -104,7 +127,9 @@ module Agents
|
|
104
127
|
end
|
105
128
|
|
106
129
|
products.each do |product|
|
107
|
-
|
130
|
+
unless ignore_skus.include?(product['sku'])
|
131
|
+
create_event payload: product
|
132
|
+
end
|
108
133
|
end
|
109
134
|
end
|
110
135
|
|
@@ -10,6 +10,8 @@ module AcumenProductQueryConcern
|
|
10
10
|
|
11
11
|
def get_products_by_ids(acumen_client, ids)
|
12
12
|
response = acumen_client.get_products(ids)
|
13
|
+
products = []
|
14
|
+
|
13
15
|
products = parse_product_request(response)
|
14
16
|
|
15
17
|
response = acumen_client.get_products_marketing(ids)
|
@@ -20,7 +22,16 @@ module AcumenProductQueryConcern
|
|
20
22
|
|
21
23
|
def get_variants_for_ids(acumen_client, ids)
|
22
24
|
result = get_linked_products_by_ids(acumen_client, ids)
|
23
|
-
|
25
|
+
|
26
|
+
# Filtering out duplicate links getting sent from acumen
|
27
|
+
filter = []
|
28
|
+
result.each do |link|
|
29
|
+
if (link['alt_format'].to_s != 0.to_s && !link.in?(filter))
|
30
|
+
filter.push(link)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
return filter
|
24
35
|
end
|
25
36
|
|
26
37
|
def get_linked_products_by_ids(acumen_client, ids)
|
@@ -77,20 +88,24 @@ module AcumenProductQueryConcern
|
|
77
88
|
|
78
89
|
def get_product_categories(acumen_client, products)
|
79
90
|
# fetch categories
|
80
|
-
|
91
|
+
|
92
|
+
skus = products.map { |product| product['model'].map { |m| m['sku'] } }[0]
|
81
93
|
response = acumen_client.get_product_categories(skus)
|
82
94
|
categories = process_product_categories_query(response)
|
83
95
|
|
84
96
|
# map categories to products
|
85
97
|
products.each do |product|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
98
|
+
product['model'].each do |variant|
|
99
|
+
variant['categories'] = []
|
100
|
+
sku = variant['sku']
|
101
|
+
if categories[sku]
|
102
|
+
active = categories[sku].select { |c| c['inactive'] == '0' }
|
103
|
+
active.map do |category|
|
104
|
+
variant['categories'].push({
|
105
|
+
'@type' => 'Thing',
|
106
|
+
'identifier' => category['category_id']
|
107
|
+
})
|
108
|
+
end
|
94
109
|
end
|
95
110
|
end
|
96
111
|
end
|
@@ -111,6 +126,7 @@ module AcumenProductQueryConcern
|
|
111
126
|
variant['@type'] = 'ProductModel'
|
112
127
|
variant['isDefault'] = false
|
113
128
|
variant['isTaxable'] = field_value(p, 'Inv_Product.Taxable') == '1'
|
129
|
+
variant['isAvailableForPurchase'] = field_value(p, 'Inv_Product.Not_On_Website') == '0'
|
114
130
|
variant['acumenAttributes'] = {
|
115
131
|
'is_master' => field_value(p, 'Inv_Product.OnWeb_LinkOnly') == '0'
|
116
132
|
}
|
@@ -145,6 +161,7 @@ module AcumenProductQueryConcern
|
|
145
161
|
'info_alpha_1' => field_value(p, 'Inv_Product.Info_Alpha_1'),
|
146
162
|
'info_boolean_1' => field_value(p, 'Inv_Product.Info_Boolean_1'),
|
147
163
|
},
|
164
|
+
'isAvailableForPurchase' => field_value(p, variant['isAvailableForPurchase']),
|
148
165
|
}
|
149
166
|
|
150
167
|
category = field_value(p, 'Inv_Product.Category')
|
@@ -388,6 +405,7 @@ module AcumenProductQueryConcern
|
|
388
405
|
result.each do |product|
|
389
406
|
if product['model'].length == 1
|
390
407
|
product['model'][0]['isDefault'] = true
|
408
|
+
set_base_sku(product, product['model'][0]['sku'])
|
391
409
|
next
|
392
410
|
else
|
393
411
|
physical_formats.each do |val|
|
@@ -408,6 +426,17 @@ module AcumenProductQueryConcern
|
|
408
426
|
end
|
409
427
|
end
|
410
428
|
end
|
429
|
+
|
430
|
+
model_ids = product['model'].map { |m| m['identifier'] }
|
431
|
+
primary_variant = product['model'].select { |m| m['identifier'] == model_ids.min }.first
|
432
|
+
|
433
|
+
# Set the base SKU to the SKU of the oldest record.
|
434
|
+
# The base_sku property is designed to be a system value specific to the inegration using this agent.
|
435
|
+
# As a result, we don't particularly care what that value is so long as we can retrieve it consistently
|
436
|
+
# across executions. If a paperback product is created first, this will always return that product's SKU
|
437
|
+
# as the base. This gives us a consistent way to link Acumen products to an external system where database
|
438
|
+
# IDs may not match.
|
439
|
+
set_base_sku(product, primary_variant ? primary_variant['sku'] : product['model'][0]['sku'])
|
411
440
|
end
|
412
441
|
result
|
413
442
|
end
|
@@ -427,6 +456,18 @@ module AcumenProductQueryConcern
|
|
427
456
|
field[key]['__content__'] if field[key]
|
428
457
|
end
|
429
458
|
|
459
|
+
def set_base_sku(product, sku)
|
460
|
+
|
461
|
+
product['additionalProperty'].push({
|
462
|
+
'@type' => 'PropertyValue',
|
463
|
+
'propertyID' => 'baseSku',
|
464
|
+
'name' => 'Base SKU',
|
465
|
+
'value' => sku,
|
466
|
+
})
|
467
|
+
|
468
|
+
product
|
469
|
+
end
|
470
|
+
|
430
471
|
def quantitative_value(value, unit)
|
431
472
|
{
|
432
473
|
'@type' => 'QuantitativeValue',
|
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.
|
4
|
+
version: 1.7.1
|
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-
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|