huginn_acumen_product_agent 1.0.0 → 1.1.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: a6d6febab93205d4676c198c74dc8eb8d956f775eaa3ce800387c1b84e849921
4
- data.tar.gz: 5dd201cfb88672b67a8e4350056c30204843a9460afb2573c0e0587acabfff8f
3
+ metadata.gz: b36d5091b225ea542f9b95dc054a4979a1d7e8a586e86a9663b74873cb317e68
4
+ data.tar.gz: 15ec0f1bac866a558a7db347ca639ebac9e2b754436c25f22191ece87dffd455
5
5
  SHA512:
6
- metadata.gz: a1bd50ef65b8361ebfbd2b1b6e938c971790426620b4d56f62d95d1ccc7b19eca6a6f017336fd23b840d446472d65cd9f133f0e0e5635a67fb160af81c22dadb
7
- data.tar.gz: 6931f53b778d415e2e3f4a51a242bb9a97e47fcb6692818d2e9c6489a7c96864dee5264a7fd6351d2541d07da5f25b014e30358991eb22084aeb96f17bc52c8f
6
+ metadata.gz: d7ca97a566cb429d0f7e6fa3b06d2ce27c5de7a0d33833b32b2725801278037967d5c6479b88950708973d9a458f73f08b440c5d26bc10a6d49552e6e1cb5b7b
7
+ data.tar.gz: d9645a9bbd997945490fe8c80a4d03bcc0541fde8d46ffd17fae1b48751e05998bd039ae7a67a4f54bb8c5524b3f71a9bdceaa0cfc6d0bc6d0e116f47716ff41
@@ -31,6 +31,12 @@ class AcumenClient
31
31
  get_results(response, 'ProdMkt_Contrib_Link')
32
32
  end
33
33
 
34
+ def get_contributor_types(ids)
35
+ body = build_product_contributor_type_query(ids)
36
+ response = execute_in_list_query(body, {})
37
+ get_results(response, 'ProdMkt_Contributor')
38
+ end
39
+
34
40
  def get_product_categories(skus)
35
41
  q = build_product_categories_query(skus)
36
42
  response = execute_in_list_query(q, {})
@@ -245,6 +251,27 @@ class AcumenClient
245
251
  XML
246
252
  end
247
253
 
254
+ def build_product_contributor_type_query(ids)
255
+ <<~XML
256
+ <acusoapRequest>
257
+ #{build_acumen_query_auth()}
258
+ <query>
259
+ <statement>
260
+ <column_name>ProdMkt_Contributor.ID</column_name>
261
+ <comparator>in</comparator>
262
+ <value>#{ids.join(',')}</value>
263
+ </statement>
264
+ </query>
265
+ <requested_output>
266
+ <view_owner_table_name>ProdMkt_Contributor</view_owner_table_name>
267
+ <view_name>ProdMkt_ContributorAllRead</view_name>
268
+ <column_name>ProdMkt_Contributor.ID</column_name>
269
+ <column_name>ProdMkt_Contributor.Contrib_Type</column_name>
270
+ </requested_output>
271
+ </acusoapRequest>
272
+ XML
273
+ end
274
+
248
275
  def build_acumen_query_auth()
249
276
  <<~XML
250
277
  <authentication>
@@ -20,6 +20,7 @@ module Agents
20
20
  'site_code' => '',
21
21
  'password' => '',
22
22
  'attribute_to_property' => {},
23
+ 'contributor_types_map' => {},
23
24
  }
24
25
  end
25
26
 
@@ -39,6 +40,10 @@ module Agents
39
40
  unless options['attribute_to_property'].is_a?(Hash)
40
41
  errors.add(:base, "if provided, attribute_to_property must be a hash")
41
42
  end
43
+
44
+ unless options['contributor_types_map'].is_a?(Hash)
45
+ errors.add(:base, "if provided, contributor_types_map must be a hash")
46
+ end
42
47
  end
43
48
 
44
49
  def working?
@@ -110,6 +115,5 @@ module Agents
110
115
  end
111
116
  end
112
117
  end
113
-
114
118
  end
115
119
  end
@@ -37,11 +37,22 @@ module AcumenProductQueryConcern
37
37
  id = product['acumenAttributes']['product_marketing_id']
38
38
  product_contributor = product_contributors[id]
39
39
 
40
+
40
41
  if product_contributor
41
- product['contributor'] = product_contributor.map do |pc|
42
+ contributor_ids = product_contributor.map do |pc|
43
+ pc['contributor_id']
44
+ end
45
+
46
+ type_response = acumen_client.get_contributor_types(contributor_ids)
47
+ contributor_types = process_contributor_types_query(type_response)
48
+
49
+ product['contributors'] = product_contributor.map do |pc|
42
50
  {
43
51
  '@type' => 'Person',
44
- 'identifier' => pc['contributor_id']
52
+ 'identifier' => pc['contributor_id'],
53
+ 'acumenAttributes' => {
54
+ 'contrib_type' => contributor_types[pc['contributor_id']]
55
+ }
45
56
  }
46
57
  end
47
58
  end
@@ -74,7 +85,7 @@ module AcumenProductQueryConcern
74
85
  products.each do |product|
75
86
  sku = product['sku']
76
87
  if categories[sku]
77
- active = categories[sku].select { |c| c['inactive'] != 0 }
88
+ active = categories[sku].select { |c| c['inactive'] == '0' }
78
89
  product['categories'] = active.map do |category|
79
90
  {
80
91
  '@type' => 'Thing',
@@ -119,6 +130,7 @@ module AcumenProductQueryConcern
119
130
  'identifier' => variant['identifier'],
120
131
  'sku' => variant['sku'],
121
132
  'name' => field_value(p, 'Inv_Product.Full_Title'),
133
+ 'disambiguatingDescription' => field_value(p, 'Inv_Product.SubTitle'),
122
134
  'model' => [
123
135
  variant
124
136
  ],
@@ -315,15 +327,34 @@ module AcumenProductQueryConcern
315
327
  'ProdMkt_Contrib_Link.Inactive' => 'inactive',
316
328
  })
317
329
 
318
- if results[mapped['product_marketing_id']]
319
- results[mapped['product_marketing_id']].push(mapped)
320
- else
321
- results[mapped['product_marketing_id']] = [mapped]
330
+ if mapped['inactive'] == '0'
331
+
332
+ if results[mapped['product_marketing_id']]
333
+ results[mapped['product_marketing_id']].push(mapped)
334
+ else
335
+ results[mapped['product_marketing_id']] = [mapped]
336
+ end
322
337
  end
323
338
  end
324
339
  results
325
340
  end
326
341
 
342
+ def process_contributor_types_query(types)
343
+ results = {}
344
+ types.each do |type|
345
+ mapped = response_mapper(type, {
346
+ 'ProdMkt_Contributor.ID' => 'contributor_id',
347
+ 'ProdMkt_Contributor.Contrib_Type' => 'type',
348
+ })
349
+
350
+ if !results[mapped['contributor_id']]
351
+ results[mapped['contributor_id']] = mapped['type']
352
+ end
353
+ end
354
+
355
+ results
356
+ end
357
+
327
358
  def process_products_and_variants(products, variants, links)
328
359
  products_map = {}
329
360
  products.each { |product| products_map[product['identifier']] = product }
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.0.0
4
+ version: 1.1.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-03-06 00:00:00.000000000 Z
11
+ date: 2020-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler