aboutyou-sdk 0.0.29 → 0.0.30
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 +8 -8
- data/lib/AboutYou/CacheProvider/dalli.rb +3 -0
- data/lib/AboutYou/Criteria/product_fields.rb +3 -0
- data/lib/AboutYou/Criteria/product_search_criteria.rb +8 -8
- data/lib/AboutYou/Factory/default_model_factory.rb +15 -2
- data/lib/AboutYou/Model/Basket/abstract_basket_item.rb +25 -20
- data/lib/AboutYou/Model/Basket/basket_item.rb +27 -27
- data/lib/AboutYou/Model/Basket/basket_set.rb +60 -62
- data/lib/AboutYou/Model/Basket/basket_set_item.rb +8 -9
- data/lib/AboutYou/Model/Basket/basket_variant_item.rb +55 -21
- data/lib/AboutYou/Model/ProductSearchResult/facet_count.rb +0 -2
- data/lib/AboutYou/Model/ProductSearchResult/price_range.rb +2 -2
- data/lib/AboutYou/Model/abstract_model.rb +5 -3
- data/lib/AboutYou/Model/app.rb +0 -2
- data/lib/AboutYou/Model/autocomplete.rb +0 -2
- data/lib/AboutYou/Model/basket.rb +91 -19
- data/lib/AboutYou/Model/brand.rb +8 -4
- data/lib/AboutYou/Model/categories_result.rb +13 -2
- data/lib/AboutYou/Model/category.rb +45 -19
- data/lib/AboutYou/Model/category_tree.rb +21 -7
- data/lib/AboutYou/Model/facet.rb +44 -22
- data/lib/AboutYou/Model/facet_group.rb +55 -21
- data/lib/AboutYou/Model/facet_group_set.rb +106 -23
- data/lib/AboutYou/Model/image.rb +36 -25
- data/lib/AboutYou/Model/image_size.rb +8 -5
- data/lib/AboutYou/Model/initiate_order.rb +26 -7
- data/lib/AboutYou/Model/order.rb +12 -2
- data/lib/AboutYou/Model/product.rb +261 -5
- data/lib/AboutYou/Model/product_search_result.rb +40 -10
- data/lib/AboutYou/Model/{products_ean_result.rb → products_eans_result.rb} +11 -5
- data/lib/AboutYou/Model/products_result.rb +13 -14
- data/lib/AboutYou/Model/result_error.rb +18 -2
- data/lib/AboutYou/Model/variant.rb +87 -26
- data/lib/AboutYou/Model/variants_result.rb +31 -15
- data/lib/AboutYou/client.rb +7 -0
- data/lib/AboutYou/query.rb +7 -2
- data/lib/AboutYou/query_builder.rb +22 -3
- data/lib/aboutyou-sdk.rb +7 -0
- metadata +3 -3
@@ -2,41 +2,76 @@ module AboutYou
|
|
2
2
|
module SDK
|
3
3
|
module Model
|
4
4
|
###
|
5
|
-
#
|
6
5
|
# This class represents an product model
|
7
|
-
#
|
8
6
|
###
|
9
7
|
class Product
|
10
8
|
include AbstractModel
|
11
|
-
|
9
|
+
# product id
|
12
10
|
attr_accessor :id
|
11
|
+
# instance of AboutYou::SDK::Factory::DefaultModelFactory
|
13
12
|
attr_accessor :factory
|
13
|
+
# product name
|
14
14
|
attr_accessor :name
|
15
|
+
# product in sale or not
|
15
16
|
attr_accessor :is_sale
|
17
|
+
# product active or not
|
16
18
|
attr_accessor :is_active
|
19
|
+
# short description
|
17
20
|
attr_accessor :description_short
|
21
|
+
# long description
|
18
22
|
attr_accessor :description_long
|
23
|
+
# product min price
|
19
24
|
attr_accessor :min_price
|
25
|
+
# product max price
|
20
26
|
attr_accessor :max_price
|
27
|
+
# product max savings price
|
21
28
|
attr_accessor :max_savings_price
|
29
|
+
# product max savings
|
22
30
|
attr_accessor :max_savings
|
31
|
+
# product max savings percentage
|
23
32
|
attr_accessor :max_savings_percentage
|
33
|
+
# product brand id
|
24
34
|
attr_accessor :brand_id
|
35
|
+
# product merchant id
|
25
36
|
attr_accessor :merchant_id
|
37
|
+
# category id paths of this product
|
26
38
|
attr_accessor :category_id_paths
|
39
|
+
# facet ids of this product
|
27
40
|
attr_accessor :facet_ids
|
41
|
+
# product default image
|
28
42
|
attr_accessor :default_image
|
43
|
+
# product default variant
|
29
44
|
attr_accessor :default_variant
|
45
|
+
# product selected variant
|
30
46
|
attr_accessor :selected_variant
|
47
|
+
# variants of product
|
31
48
|
attr_accessor :variants
|
49
|
+
# inactive styles of product
|
32
50
|
attr_accessor :inactive_variants
|
51
|
+
# styles of product
|
33
52
|
attr_accessor :styles
|
53
|
+
# facet groups of product
|
34
54
|
attr_accessor :facet_groups
|
55
|
+
# root categories for product
|
35
56
|
attr_accessor :root_categories
|
57
|
+
# active root categories for the product
|
36
58
|
attr_accessor :active_root_categories
|
59
|
+
# leaf categories for product
|
37
60
|
attr_accessor :leaf_categories
|
61
|
+
# active leaf categories of the product
|
38
62
|
attr_accessor :active_leaf_categories
|
39
63
|
|
64
|
+
###
|
65
|
+
# This method is used for creating an instance of this class by a json_object.
|
66
|
+
#
|
67
|
+
# * *Args* :
|
68
|
+
# - +json_object+ -> the json_object received from the api
|
69
|
+
# - +factory+ -> instance of AboutYou::SDK::Factory::DefaultModelFactory
|
70
|
+
# - +app_id+ -> app id of the product
|
71
|
+
#
|
72
|
+
# * *Returns* :
|
73
|
+
# - Instance of AboutYou::SDK::Model::Product
|
74
|
+
###
|
40
75
|
def self.create_from_json(json_object, factory, app_id)
|
41
76
|
product = new
|
42
77
|
|
@@ -75,6 +110,18 @@ module AboutYou
|
|
75
110
|
product
|
76
111
|
end
|
77
112
|
|
113
|
+
###
|
114
|
+
# This method is used for parsing the variants of the product
|
115
|
+
#
|
116
|
+
# * *Args* :
|
117
|
+
# - +json_object+ -> the json_object received from the api
|
118
|
+
# - +factory+ -> instance of AboutYou::SDK::Factory::DefaultModelFactory
|
119
|
+
# - +product+ -> self
|
120
|
+
# - +attribute_name+ -> attribute name for parsing [optional]
|
121
|
+
#
|
122
|
+
# * *Returns* :
|
123
|
+
# - Hash containing pairs of variant_id => instance of AboutYou::SDK::Model::Variant
|
124
|
+
###
|
78
125
|
def parse_variants(json_object, factory, product, attribute_name = 'variants')
|
79
126
|
variants = {}
|
80
127
|
|
@@ -90,6 +137,16 @@ module AboutYou
|
|
90
137
|
variants
|
91
138
|
end
|
92
139
|
|
140
|
+
###
|
141
|
+
# This method is used for parsing the styles of the product
|
142
|
+
#
|
143
|
+
# * *Args* :
|
144
|
+
# - +json_object+ -> the json_object received from the api
|
145
|
+
# - +factory+ -> instance of AboutYou::SDK::Factory::DefaultModelFactory
|
146
|
+
#
|
147
|
+
# * *Returns* :
|
148
|
+
# - Array containing instances of AboutYou::SDK::Model::Product
|
149
|
+
###
|
93
150
|
def parse_styles(json_object, factory)
|
94
151
|
styles = []
|
95
152
|
|
@@ -100,6 +157,15 @@ module AboutYou
|
|
100
157
|
styles
|
101
158
|
end
|
102
159
|
|
160
|
+
###
|
161
|
+
# This method is used for parsing the category id paths for this product
|
162
|
+
#
|
163
|
+
# * *Args* :
|
164
|
+
# - +json_object+ -> the json_object received from the api
|
165
|
+
#
|
166
|
+
# * *Returns* :
|
167
|
+
# - Array of Strings
|
168
|
+
###
|
103
169
|
def parse_category_id_paths(json_object)
|
104
170
|
paths = []
|
105
171
|
|
@@ -113,20 +179,47 @@ module AboutYou
|
|
113
179
|
paths
|
114
180
|
end
|
115
181
|
|
182
|
+
###
|
183
|
+
# This method is used for parsing the facet ids of this product
|
184
|
+
#
|
185
|
+
# * *Args* :
|
186
|
+
# - +json_object+ -> the json_object received from the api
|
187
|
+
#
|
188
|
+
# * *Returns* :
|
189
|
+
# - a Hash containing pairs of facet_ids => AboutYou::SDK::Model::Facet
|
190
|
+
###
|
116
191
|
def parse_facet_ids(json_object)
|
117
192
|
ids = parse_facet_ids_in_attributes_merged(json_object)
|
118
193
|
ids = parse_facet_ids_in_variants(json_object) if ids.nil?
|
119
194
|
ids = parse_facet_ids_in_brand(json_object) if ids.nil?
|
120
195
|
|
121
|
-
!ids.nil? ? ids :
|
196
|
+
!ids.nil? ? ids : {}
|
122
197
|
end
|
123
198
|
|
199
|
+
###
|
200
|
+
# This method is used for parsing the facet ids in merged attributes
|
201
|
+
#
|
202
|
+
# * *Args* :
|
203
|
+
# - +json_object+ -> the json_object received from the api
|
204
|
+
#
|
205
|
+
# * *Returns* :
|
206
|
+
# - nil / a Hash containing pairs of facet_ids => AboutYou::SDK::Model::Facet
|
207
|
+
###
|
124
208
|
def parse_facet_ids_in_attributes_merged(json_object)
|
125
209
|
return nil unless json_object['attributes_merged']
|
126
210
|
|
127
211
|
parse_attributes_json(json_object['attributes_merged'])
|
128
212
|
end
|
129
213
|
|
214
|
+
###
|
215
|
+
# This method is used for parsing an attribues json object
|
216
|
+
#
|
217
|
+
# * *Args* :
|
218
|
+
# - +attributes_json_object+ -> the attributes_json_object received from the api
|
219
|
+
#
|
220
|
+
# * *Returns* :
|
221
|
+
# - nil / a Hash containing pairs of facet_ids => AboutYou::SDK::Model::Facet
|
222
|
+
###
|
130
223
|
def parse_attributes_json(attributes_json_object)
|
131
224
|
ids = {}
|
132
225
|
|
@@ -141,6 +234,15 @@ module AboutYou
|
|
141
234
|
ids
|
142
235
|
end
|
143
236
|
|
237
|
+
###
|
238
|
+
# This method is used for parsing the facet ids in the variants of this product
|
239
|
+
#
|
240
|
+
# * *Args* :
|
241
|
+
# - +json_object+ -> the json_object received from the api
|
242
|
+
#
|
243
|
+
# * *Returns* :
|
244
|
+
# - Array containing facet ids
|
245
|
+
###
|
144
246
|
def parse_facet_ids_in_variants(json_object)
|
145
247
|
if json_object['variants']
|
146
248
|
ids = []
|
@@ -159,12 +261,27 @@ module AboutYou
|
|
159
261
|
nil
|
160
262
|
end
|
161
263
|
|
264
|
+
###
|
265
|
+
# This method is used for parsing the facet ids brands
|
266
|
+
#
|
267
|
+
# * *Args* :
|
268
|
+
# - +json_object+ -> the json_object received from the api
|
269
|
+
#
|
270
|
+
# * *Returns* :
|
271
|
+
# - nil / a Hash containing pairs of facet_ids => AboutYou::SDK::Model::Facet
|
272
|
+
###
|
162
273
|
def parse_facet_ids_in_brand(json_object)
|
163
274
|
return nil unless json_object['brand_id']
|
164
275
|
|
165
276
|
{ '0' => [json_object['brand_id']] }
|
166
277
|
end
|
167
278
|
|
279
|
+
###
|
280
|
+
# This method generates a facet group set for self.facet_ids
|
281
|
+
#
|
282
|
+
# * *Fails* :
|
283
|
+
# - if self.facet_ids is empty
|
284
|
+
###
|
168
285
|
def generate_facet_group_set
|
169
286
|
fail 'RuntimeException! To use this method, you must add the field
|
170
287
|
ProductFields::ATTRIBUTES_MERGED to the "product search" or
|
@@ -173,18 +290,39 @@ module AboutYou
|
|
173
290
|
self.facet_groups = AboutYou::SDK::Model::FacetGroupSet.new(facet_ids)
|
174
291
|
end
|
175
292
|
|
293
|
+
###
|
294
|
+
# Getter for the facet group set
|
295
|
+
#
|
296
|
+
# * *Returns* :
|
297
|
+
# - instance of AboutYou::SDK::Model::FacetGroupSet
|
298
|
+
###
|
176
299
|
def facet_group_set
|
177
300
|
generate_facet_group_set unless @facet_groups
|
178
301
|
|
179
302
|
@facet_groups
|
180
303
|
end
|
181
304
|
|
305
|
+
###
|
306
|
+
# This method is used for getting a category
|
307
|
+
#
|
308
|
+
# * *Args* :
|
309
|
+
# - +active+ -> Boolean determining whether the category has to be active or not
|
310
|
+
#
|
311
|
+
# * *Returns* :
|
312
|
+
# - nil / instance of AboutYou::SDK::Model::Category
|
313
|
+
###
|
182
314
|
def category(active = false)
|
183
|
-
return
|
315
|
+
return unless category_id_paths
|
184
316
|
|
185
317
|
leaf_categories(active)[leaf_categories(active).keys[0]]
|
186
318
|
end
|
187
319
|
|
320
|
+
###
|
321
|
+
# Getter for the deepest category
|
322
|
+
#
|
323
|
+
# * *Returns* :
|
324
|
+
# - nil / instance of AboutYou::SDK::Model::Category
|
325
|
+
###
|
188
326
|
def category_with_longest_active_path
|
189
327
|
return nil unless category_id_paths
|
190
328
|
|
@@ -196,10 +334,25 @@ module AboutYou
|
|
196
334
|
nil
|
197
335
|
end
|
198
336
|
|
337
|
+
###
|
338
|
+
# Getter for the leaf categories
|
339
|
+
#
|
340
|
+
# * *Args* :
|
341
|
+
# - +active_only+ -> Boolean controlling whether only active categories should be returned or not
|
342
|
+
#
|
343
|
+
# * *Returns* :
|
344
|
+
# - Array containing instances of AboutYou::SDK::Model::Category
|
345
|
+
###
|
199
346
|
def leaf_categories(active_only = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
|
200
347
|
factory.category_manager.categories(leaf_category_ids, active_only)
|
201
348
|
end
|
202
349
|
|
350
|
+
###
|
351
|
+
# Getter for the root category ids
|
352
|
+
#
|
353
|
+
# * *Returns* :
|
354
|
+
# - Array containing category_ids
|
355
|
+
###
|
203
356
|
def root_category_ids
|
204
357
|
root_category = []
|
205
358
|
category_id_paths.each do |category_id_path|
|
@@ -209,6 +362,12 @@ module AboutYou
|
|
209
362
|
root_category.uniq
|
210
363
|
end
|
211
364
|
|
365
|
+
###
|
366
|
+
# Getter for the leaf category ids
|
367
|
+
#
|
368
|
+
# * *Returns* :
|
369
|
+
# - Array containing category_ids
|
370
|
+
###
|
212
371
|
def leaf_category_ids
|
213
372
|
leaf_categories = []
|
214
373
|
category_id_paths.each do |category_id_path|
|
@@ -218,18 +377,54 @@ module AboutYou
|
|
218
377
|
leaf_categories.uniq
|
219
378
|
end
|
220
379
|
|
380
|
+
###
|
381
|
+
# Getter for the categories
|
382
|
+
#
|
383
|
+
# * *Args* :
|
384
|
+
# - +active_only+ -> Boolean controlling whether only active categories should be returned or not
|
385
|
+
#
|
386
|
+
# * *Returns* :
|
387
|
+
# - Array containing instances of AboutYou::SDK::Model::Category
|
388
|
+
###
|
221
389
|
def categories(active_only = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
|
222
390
|
root_categories(active_only)
|
223
391
|
end
|
224
392
|
|
393
|
+
###
|
394
|
+
# Getter for the root categories
|
395
|
+
#
|
396
|
+
# * *Args* :
|
397
|
+
# - +active_only+ -> Boolean controlling whether only active categories should be returned or not
|
398
|
+
#
|
399
|
+
# * *Returns* :
|
400
|
+
# - Array containing instances of AboutYou::SDK::Model::Category
|
401
|
+
###
|
225
402
|
def root_categories(active_only = Category::ACTIVE_ONLY)
|
226
403
|
factory.category_manager.categories(root_category_ids, active_only)
|
227
404
|
end
|
228
405
|
|
406
|
+
###
|
407
|
+
# Getter for facets for a certain group id
|
408
|
+
#
|
409
|
+
# * *Args* :
|
410
|
+
# - +group_id+ -> group_id used for searching
|
411
|
+
#
|
412
|
+
# * *Returns* :
|
413
|
+
# - [] / instance of AboutYou::SDK::Model::FacetGroup
|
414
|
+
###
|
229
415
|
def group_facets(group_id)
|
230
416
|
facet_group_set.group(group_id) ? group.facets : []
|
231
417
|
end
|
232
418
|
|
419
|
+
###
|
420
|
+
# Getter for all facetGroups for a certain group id
|
421
|
+
#
|
422
|
+
# * *Args* :
|
423
|
+
# - +group_id+ -> group_id used for searching
|
424
|
+
#
|
425
|
+
# * *Returns* :
|
426
|
+
# - Hash containing pairs of unique_group_key => group_id
|
427
|
+
###
|
233
428
|
def facet_groups(group_id)
|
234
429
|
all_groups = {}
|
235
430
|
|
@@ -242,6 +437,15 @@ module AboutYou
|
|
242
437
|
all_groups
|
243
438
|
end
|
244
439
|
|
440
|
+
###
|
441
|
+
# Getter for the selectable facet groups
|
442
|
+
#
|
443
|
+
# * *Args* :
|
444
|
+
# - +selected_facet_group_set+ -> selected instance of AboutYou::SDK::Model::FacetGroupSet
|
445
|
+
#
|
446
|
+
# * *Returns* :
|
447
|
+
# - Hash containing pairs of unique_group_key => instance of AboutYou::SDK::Model::FacetGroup
|
448
|
+
###
|
245
449
|
def selectable_facet_groups(selected_facet_group_set)
|
246
450
|
all_groups = {}
|
247
451
|
selected_group_ids = selected_facet_group_set.group_ids
|
@@ -279,6 +483,15 @@ module AboutYou
|
|
279
483
|
all_groups
|
280
484
|
end
|
281
485
|
|
486
|
+
###
|
487
|
+
# Getter for the excluded groups
|
488
|
+
#
|
489
|
+
# * *Args* :
|
490
|
+
# - +selected_facet_group_set+ -> selected instance of AboutYou::SDK::Model::FacetGroupSet
|
491
|
+
#
|
492
|
+
# * *Returns* :
|
493
|
+
# - Hash containing pairs of unique_group_key => instance of AboutYou::SDK::Model::FacetGroup
|
494
|
+
###
|
282
495
|
def excluded_facet_groups(selected_facet_group_set)
|
283
496
|
all_groups = {}
|
284
497
|
|
@@ -307,6 +520,12 @@ module AboutYou
|
|
307
520
|
all_groups
|
308
521
|
end
|
309
522
|
|
523
|
+
###
|
524
|
+
# Getter for the brand
|
525
|
+
#
|
526
|
+
# * *Returns* :
|
527
|
+
# - Instance of AboutYou::SDK::Model::Facet
|
528
|
+
###
|
310
529
|
def brand
|
311
530
|
facet_group_set.facet(
|
312
531
|
AboutYou::SDK::Model::Facet::FACET_BRAND,
|
@@ -314,10 +533,28 @@ module AboutYou
|
|
314
533
|
)
|
315
534
|
end
|
316
535
|
|
536
|
+
###
|
537
|
+
# This method returns a variant by a certain variant_id
|
538
|
+
#
|
539
|
+
# * *Args* :
|
540
|
+
# - +variant_id+ -> variant id used for searching
|
541
|
+
#
|
542
|
+
# * *Returns* :
|
543
|
+
# - nil / instance of AboutYou::SDK::Model::Variant
|
544
|
+
###
|
317
545
|
def variant_by_id(variant_id)
|
318
546
|
variants[variant_id] ? variants[variant_id] : nil
|
319
547
|
end
|
320
548
|
|
549
|
+
###
|
550
|
+
# This method searches for variants by a certain ean
|
551
|
+
#
|
552
|
+
# * *Args* :
|
553
|
+
# - +ean+ -> ean used for searching
|
554
|
+
#
|
555
|
+
# * *Returns* :
|
556
|
+
# - [] / Array containing instances of AboutYou::SDK::Model::Variant
|
557
|
+
###
|
321
558
|
def variants_by_ean(ean)
|
322
559
|
variants = []
|
323
560
|
|
@@ -328,6 +565,15 @@ module AboutYou
|
|
328
565
|
variants
|
329
566
|
end
|
330
567
|
|
568
|
+
###
|
569
|
+
# This method searches for a variant by a certain facet group set
|
570
|
+
#
|
571
|
+
# * *Args* :
|
572
|
+
# - +facet_group_set+ -> facet_group_set used for searching
|
573
|
+
#
|
574
|
+
# * *Returns* :
|
575
|
+
# - nil / instance of AboutYou::SDK::Model::Variant
|
576
|
+
###
|
331
577
|
def variant_by_facet(facet_group_set)
|
332
578
|
key = facet_group_set.unique_key
|
333
579
|
variants.each do |variant|
|
@@ -337,6 +583,16 @@ module AboutYou
|
|
337
583
|
nil
|
338
584
|
end
|
339
585
|
|
586
|
+
###
|
587
|
+
# This method searches for variants by a certain facet_id and group_id
|
588
|
+
#
|
589
|
+
# * *Args* :
|
590
|
+
# - +facet_id+ -> facet_id used for searching
|
591
|
+
# - +group_id+ -> group_id used for searching
|
592
|
+
#
|
593
|
+
# * *Returns* :
|
594
|
+
# - [] / Array containing instances of AboutYou::SDK::Model::Variant
|
595
|
+
###
|
340
596
|
def variants_by_facet_id(facet_id, group_id)
|
341
597
|
variants = []
|
342
598
|
|