huginn_acumen_product_agent 1.5.0 → 1.7.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f611c6b9e7567e84ec03753277031b227c70fee3afe17cfbf35be0c185932b4f
|
4
|
+
data.tar.gz: ecfc5e4acee56876eee9b4c3de78db3f6e40ff1cce60d5a6e834c75dae97523f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ccf91cb1986314c492cbe9b0b189503504705bc6521a8f7861bbef9338bdb2e27ebb2036b5b595c55c33c52f1cb81e4534ca9686b3d2a67cd1fa6dfa2389e6b
|
7
|
+
data.tar.gz: 63b33acb6744b016c1f08ddf409d6580c2e78e57b46c93ccfe91326b7233b2dc54db09cd5fb52ee6eb49f6178f0439ee0b9518d87633baefcd0e52a5a7af9e10
|
@@ -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')
|
@@ -375,9 +392,11 @@ module AcumenProductQueryConcern
|
|
375
392
|
links.each do |link|
|
376
393
|
from_id = link['from_id']
|
377
394
|
to_id = link['to_id']
|
378
|
-
|
379
|
-
|
380
|
-
|
395
|
+
if variants_map.key?(to_id)
|
396
|
+
variant = variants_map[to_id]
|
397
|
+
variant['isDefault'] = false
|
398
|
+
products_map[from_id]['model'].push(*variant['model'])
|
399
|
+
end
|
381
400
|
end
|
382
401
|
|
383
402
|
result = []
|
@@ -406,6 +425,17 @@ module AcumenProductQueryConcern
|
|
406
425
|
end
|
407
426
|
end
|
408
427
|
end
|
428
|
+
|
429
|
+
model_ids = product['model'].map { |m| m['identifier'] }
|
430
|
+
primary_variant = product['model'].select { |m| m['identifier'] == model_ids.min }.first
|
431
|
+
|
432
|
+
# Set the base SKU to the SKU of the oldest record.
|
433
|
+
# The base_sku property is designed to be a system value specific to the inegration using this agent.
|
434
|
+
# As a result, we don't particularly care what that value is so long as we can retrieve it consistently
|
435
|
+
# across executions. If a paperback product is created first, this will always return that product's SKU
|
436
|
+
# as the base. This gives us a consistent way to link Acumen products to an external system where database
|
437
|
+
# IDs may not match.
|
438
|
+
set_base_sku(product, primary_variant ? primary_variant['sku'] : product['model'][0]['sku'])
|
409
439
|
end
|
410
440
|
result
|
411
441
|
end
|
@@ -425,6 +455,18 @@ module AcumenProductQueryConcern
|
|
425
455
|
field[key]['__content__'] if field[key]
|
426
456
|
end
|
427
457
|
|
458
|
+
def set_base_sku(product, sku)
|
459
|
+
|
460
|
+
product['additionalProperty'].push({
|
461
|
+
'@type' => 'PropertyValue',
|
462
|
+
'propertyID' => 'baseSku',
|
463
|
+
'name' => 'Base SKU',
|
464
|
+
'value' => sku,
|
465
|
+
})
|
466
|
+
|
467
|
+
product
|
468
|
+
end
|
469
|
+
|
428
470
|
def quantitative_value(value, unit)
|
429
471
|
{
|
430
472
|
'@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.0
|
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-06
|
11
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|