aboutyou-sdk 0.0.9 → 0.0.10
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-sdk.rb +63 -46
- data/lib/aboutyou-sdk/Client.rb +7 -0
- data/lib/aboutyou-sdk/Constants.rb +70 -35
- data/lib/aboutyou-sdk/Criteria/ProductFields.rb +77 -30
- data/lib/aboutyou-sdk/Criteria/ProductSearchCriteria.rb +442 -409
- data/lib/aboutyou-sdk/Factory/DefaultModelFactory.rb +485 -337
- data/lib/aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb +1 -1
- data/lib/aboutyou-sdk/Query.rb +11 -0
- metadata +2 -2
@@ -1,452 +1,600 @@
|
|
1
1
|
module AboutYou
|
2
2
|
module SDK
|
3
3
|
module Factory
|
4
|
+
###
|
5
|
+
# This class creates model objects from a given api response
|
6
|
+
# the methods will get called automatically from the query so no need
|
7
|
+
# to call them by hand
|
8
|
+
#
|
9
|
+
# author:: Collins GmbH & Co KG
|
10
|
+
###
|
4
11
|
class DefaultModelFactory
|
5
|
-
|
12
|
+
# The client which performs the api calls
|
6
13
|
attr_accessor :shopApi
|
14
|
+
# the category manager responsible for managing the categories
|
7
15
|
attr_accessor :categoryManager
|
16
|
+
# the facet manager responsible for managing the facets
|
8
17
|
attr_accessor :facetManager
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
###
|
20
|
+
# Constructor for AboutYou::SDK::Factory::DefaultModelFactory
|
21
|
+
#
|
22
|
+
# * *Args* :
|
23
|
+
# - +shopApi+ -> the client which should perform the api calls
|
24
|
+
# - +categoryManager+ -> the category manager responsible for managing the categories
|
25
|
+
# - +:facetManager+ -> the facet manager responsible for managing the facets
|
26
|
+
#
|
27
|
+
# * *Returns* :
|
28
|
+
# - an instance of AboutYou::SDK::Factory::DefaultModelFactory
|
29
|
+
###
|
30
|
+
def initialize(shopApi = nil, facetManager, categoryManager)
|
31
|
+
self.shopApi = shopApi
|
32
|
+
self.categoryManager = categoryManager
|
33
|
+
self.facetManager = facetManager
|
34
|
+
AboutYou::SDK::Model::FacetGroupSet.facetManager = self.facetManager
|
21
35
|
end
|
22
36
|
|
37
|
+
###
|
38
|
+
# sets the baseimage url for the image model
|
39
|
+
#
|
40
|
+
# * *Args* :
|
41
|
+
# - +baseUrl+ -> the url which should be used by the image model
|
42
|
+
###
|
23
43
|
def baseImageUrl=(baseUrl)
|
24
|
-
|
25
|
-
AboutYou::SDK::Model::Image.baseUrl=baseUrl;
|
44
|
+
AboutYou::SDK::Model::Image.baseUrl=baseUrl
|
26
45
|
end
|
27
46
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
47
|
+
###
|
48
|
+
# creates an autocomplete model
|
49
|
+
#
|
50
|
+
# * *Args* :
|
51
|
+
# - +jsonObject+ -> the api response in json format
|
52
|
+
# - +query+ -> the query sent to the api
|
53
|
+
#
|
54
|
+
# * *Returns* :
|
55
|
+
# - an instance of AboutYou::SDK::Model::Autocomplete
|
56
|
+
###
|
34
57
|
def createAutocomplete(jsonObject, query)
|
35
|
-
|
36
|
-
return AboutYou::SDK::Model::Autocomplete.createFromJson(jsonObject, self);
|
58
|
+
AboutYou::SDK::Model::Autocomplete.createFromJson(jsonObject, self)
|
37
59
|
end
|
38
60
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
61
|
+
###
|
62
|
+
# creates a basket model
|
63
|
+
#
|
64
|
+
# * *Args* :
|
65
|
+
# - +jsonObject+ -> the api response in json format
|
66
|
+
# - +query+ -> the query sent to the api
|
67
|
+
#
|
68
|
+
# * *Returns* :
|
69
|
+
# - an instance of AboutYou::SDK::Model::Basket
|
70
|
+
###
|
71
|
+
def createBasket(jsonObject, query)
|
72
|
+
AboutYou::SDK::Model::Basket.createFromJson(jsonObject, self)
|
47
73
|
end
|
48
74
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
75
|
+
###
|
76
|
+
# creates a basket item model
|
77
|
+
#
|
78
|
+
# * *Args* :
|
79
|
+
# - +jsonObject+ -> the api response in json format
|
80
|
+
# - +products+ -> the product models for which items should be created
|
81
|
+
#
|
82
|
+
# * *Returns* :
|
83
|
+
# - an instance of AboutYou::SDK::Model::BasketItem
|
84
|
+
###
|
54
85
|
def createBasketItem(jsonObject, products)
|
55
|
-
|
56
|
-
return AboutYou::SDK::Model::Basket::BasketItem.createFromJson(jsonObject, products);
|
86
|
+
AboutYou::SDK::Model::Basket::BasketItem.createFromJson(jsonObject, products)
|
57
87
|
end
|
58
88
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
89
|
+
###
|
90
|
+
# creates a basket set model
|
91
|
+
#
|
92
|
+
# * *Args* :
|
93
|
+
# - +jsonObject+ -> the api response in json format
|
94
|
+
# - +products+ -> the product models for which items should be created
|
95
|
+
#
|
96
|
+
# * *Returns* :
|
97
|
+
# - an instance of AboutYou::SDK::Model::BasketSet
|
98
|
+
###
|
64
99
|
def createBasketSet(jsonObject, products)
|
65
|
-
|
66
|
-
return AboutYou::SDK::Model::BasketSet::createFromJson(jsonObject, self, products);
|
100
|
+
AboutYou::SDK::Model::BasketSet::createFromJson(jsonObject, self, products)
|
67
101
|
end
|
68
102
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
103
|
+
###
|
104
|
+
# creates a basket setitem model
|
105
|
+
#
|
106
|
+
# * *Args* :
|
107
|
+
# - +jsonObject+ -> the api response in json format
|
108
|
+
# - +products+ -> the product models for which items should be created
|
109
|
+
#
|
110
|
+
# * *Returns* :
|
111
|
+
# - an instance of AboutYou::SDK::Model::BasketSetItem
|
112
|
+
###
|
74
113
|
def createBasketSetItem(jsonObject, products)
|
75
|
-
|
76
|
-
return AboutYou::SDK::Model::BasketSetItem::createFromJson(jsonObject, products);
|
114
|
+
AboutYou::SDK::Model::BasketSetItem::createFromJson(jsonObject, products);
|
77
115
|
end
|
78
116
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
117
|
+
###
|
118
|
+
# creates a category model
|
119
|
+
#
|
120
|
+
# * *Args* :
|
121
|
+
# - +jsonObject+ -> the api response in json format
|
122
|
+
#
|
123
|
+
# * *Returns* :
|
124
|
+
# - an instance of AboutYou::SDK::Model::Category
|
125
|
+
###
|
126
|
+
def createCategory(jsonObject)
|
127
|
+
AboutYou::SDK::Model::Category.createFromJson(jsonObject, self.categoryManager)
|
87
128
|
end
|
88
129
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
130
|
+
###
|
131
|
+
# creates a category tree model
|
132
|
+
#
|
133
|
+
# * *Args* :
|
134
|
+
# - +jsonArray+ -> an Array containing the api response
|
135
|
+
# - +query+ -> the query sent to the api
|
136
|
+
#
|
137
|
+
# * *Returns* :
|
138
|
+
# - an instance of AboutYou::SDK::Model::CategoryTree
|
139
|
+
###
|
95
140
|
def createCategoryTree(jsonArray, query)
|
96
|
-
|
97
|
-
self.
|
98
|
-
|
99
|
-
return AboutYou::SDK::Model::CategoryTree.new(self.categoryManager());
|
141
|
+
self.initializeCategoryManager(jsonArray)
|
142
|
+
AboutYou::SDK::Model::CategoryTree.new(self.categoryManager)
|
100
143
|
end
|
101
144
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
145
|
+
###
|
146
|
+
# creates a facet model
|
147
|
+
#
|
148
|
+
# * *Args* :
|
149
|
+
# - +jsonObject+ -> the api response in json format
|
150
|
+
#
|
151
|
+
# * *Returns* :
|
152
|
+
# - an instance of AboutYou::SDK::Model::Facet
|
153
|
+
###
|
107
154
|
def createFacet(jsonObject)
|
108
|
-
|
109
|
-
return AboutYou::SDK::Model::Facet.createFromJson(jsonObject);
|
155
|
+
AboutYou::SDK::Model::Facet.createFromJson(jsonObject)
|
110
156
|
end
|
111
157
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
158
|
+
###
|
159
|
+
# creates a Hash containing one or multiple pairs of
|
160
|
+
# facetKey => AboutYou::SDK::Model::Facet
|
161
|
+
#
|
162
|
+
# * *Args* :
|
163
|
+
# - +jsonArray+ -> an Array containing the api response
|
164
|
+
#
|
165
|
+
# * *Returns* :
|
166
|
+
# - a Hash containing pairs of facetKey => AboutYou::SDK::Model::Facet
|
167
|
+
###
|
168
|
+
def createFacetList(jsonArray, query)
|
169
|
+
facets = {}
|
170
|
+
jsonArray.each do |jsonFacet|
|
171
|
+
facet = self.createFacet(jsonFacet)
|
172
|
+
key = facet.uniqueKey
|
173
|
+
facets[key] = facet
|
174
|
+
end
|
125
175
|
|
126
|
-
|
176
|
+
facets
|
127
177
|
end
|
128
178
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
179
|
+
###
|
180
|
+
# creates a Hash containing one or multiple pairs of
|
181
|
+
# facetKey => AboutYou::SDK::Model::Facet
|
182
|
+
#
|
183
|
+
# * *Args* :
|
184
|
+
# - +jsonObject+ -> the api response in json format
|
185
|
+
# - +query+ -> the query sent to the api
|
186
|
+
#
|
187
|
+
# * *Returns* :
|
188
|
+
# - a Hash containing pairs of facetKey => AboutYou::SDK::Model::Facet
|
189
|
+
###
|
134
190
|
def createFacetsList(jsonObject, query)
|
135
|
-
|
136
|
-
return self.createFacetList(jsonObject["facet"]);
|
191
|
+
self.createFacetList(jsonObject["facet"], query)
|
137
192
|
end
|
138
193
|
|
139
194
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
facetsCounts[groupId] = AboutYou::SDK::Model::FacetCounts.createFromJson(
|
153
|
-
groupId,
|
154
|
-
jsonResultFacet,
|
155
|
-
facetCounts
|
156
|
-
);
|
157
|
-
end
|
195
|
+
###
|
196
|
+
# creates a Hash containing one or multiple pairs of
|
197
|
+
# group_id => instance of AboutYou::SDK::Model::FacetCounts
|
198
|
+
#
|
199
|
+
# * *Args* :
|
200
|
+
# - +jsonObject+ -> the api response in json format
|
201
|
+
#
|
202
|
+
# * *Returns* :
|
203
|
+
# - a Hash containing pairs of group_id => instance of AboutYou::SDK::Model::FacetCounts
|
204
|
+
###
|
205
|
+
def createFacetsCounts(jsonObject)
|
206
|
+
facetsCounts = {}
|
158
207
|
|
159
|
-
|
208
|
+
jsonObject["facets"].each do |groupId, jsonResultFacet|
|
209
|
+
unless groupId[/\d/]
|
210
|
+
next
|
211
|
+
end
|
212
|
+
facetCounts = self.termFacets(groupId, jsonResultFacet["terms"])
|
213
|
+
facetsCounts[groupId] = AboutYou::SDK::Model::FacetCounts.createFromJson(
|
214
|
+
groupId,
|
215
|
+
jsonResultFacet,
|
216
|
+
facetCounts
|
217
|
+
)
|
160
218
|
end
|
161
|
-
|
162
|
-
|
219
|
+
|
220
|
+
facetsCounts
|
221
|
+
end
|
163
222
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
223
|
+
###
|
224
|
+
# creates an Array containing one or multiple instances of
|
225
|
+
# AboutYou::SDK::Model::FacetCount
|
226
|
+
#
|
227
|
+
# * *Args* :
|
228
|
+
# - +groupId+ -> the group id of the facets
|
229
|
+
# - +jsonTerms+ -> the single facet terms in json format
|
230
|
+
#
|
231
|
+
# * *Returns* :
|
232
|
+
# - an Array containing instances of AboutYou::SDK::Model::FacetCount
|
233
|
+
###
|
234
|
+
def termFacets(groupId, jsonTerms)
|
235
|
+
facetCounts = []
|
236
|
+
jsonTerms.each do |jsonTerm|
|
237
|
+
id = Integer(jsonTerm["term"])
|
238
|
+
facet = self.facetManager.facet(groupId, id)
|
239
|
+
unless facet
|
240
|
+
next
|
176
241
|
end
|
242
|
+
# TODO: Handle error, write test
|
243
|
+
facetCounts.push(AboutYou::SDK::Model::FacetCount.new(facet, jsonTerm["count"]))
|
244
|
+
end
|
177
245
|
|
178
|
-
|
179
|
-
|
246
|
+
facetCounts
|
247
|
+
end
|
180
248
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
249
|
+
###
|
250
|
+
# creates an Array containing all facet types available
|
251
|
+
#
|
252
|
+
# * *Args* :
|
253
|
+
# - +jsonArray+ -> an Array containing the api response
|
254
|
+
# - +query+ -> the query sent to the api
|
255
|
+
#
|
256
|
+
# * *Returns* :
|
257
|
+
# - an Array containing all facet types available
|
258
|
+
###
|
186
259
|
def createFacetTypes(jsonArray, query)
|
187
|
-
|
188
|
-
return jsonArray;
|
260
|
+
jsonArray
|
189
261
|
end
|
190
262
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
263
|
+
###
|
264
|
+
# creates an image model
|
265
|
+
#
|
266
|
+
# * *Args* :
|
267
|
+
# - +jsonObject+ -> the api response in json format
|
268
|
+
#
|
269
|
+
# * *Returns* :
|
270
|
+
# - an instance of AboutYou::SDK::Model::Image
|
271
|
+
###
|
196
272
|
def createImage(jsonObject)
|
197
|
-
|
198
|
-
AboutYou::SDK::Model::Image.createFromJson(jsonObject);
|
273
|
+
AboutYou::SDK::Model::Image.createFromJson(jsonObject)
|
199
274
|
end
|
200
275
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
276
|
+
###
|
277
|
+
# creates a product model
|
278
|
+
#
|
279
|
+
# * *Args* :
|
280
|
+
# - +jsonObject+ -> the api response in json format
|
281
|
+
#
|
282
|
+
# * *Returns* :
|
283
|
+
# - an instance of AboutYou::SDK::Model::Product
|
284
|
+
###
|
206
285
|
def createProduct(jsonObject)
|
207
|
-
|
208
|
-
AboutYou::SDK::Model::Product.createFromJson(jsonObject, self, self.shopApi.appId());
|
286
|
+
AboutYou::SDK::Model::Product.createFromJson(jsonObject, self, self.shopApi.appId)
|
209
287
|
end
|
210
288
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
289
|
+
###
|
290
|
+
# creates a variants result model
|
291
|
+
#
|
292
|
+
# * *Args* :
|
293
|
+
# - +jsonObject+ -> the api response in json format
|
294
|
+
# - +query+ -> the query sent to the api
|
295
|
+
#
|
296
|
+
# * *Returns* :
|
297
|
+
# - an instance of AboutYou::SDK::Model::VariantsResult
|
298
|
+
###
|
216
299
|
def createVariantsResult(jsonObject, query)
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
productIds.push(data["product_id"])
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
if (productIds.count > 0)
|
234
|
-
productIds = productIds.uniq;
|
235
|
-
# search products for valid variants
|
236
|
-
productSearchResult = self.shopApi.
|
237
|
-
fetchProductsByIds(
|
238
|
-
productIds,[
|
239
|
-
AboutYou::SDK::Criteria::ProductFields::ATTRIBUTES_MERGED,
|
240
|
-
AboutYou::SDK::Criteria::ProductFields::BRAND,
|
241
|
-
AboutYou::SDK::Criteria::ProductFields::CATEGORIES,
|
242
|
-
AboutYou::SDK::Criteria::ProductFields::DEFAULT_IMAGE,
|
243
|
-
AboutYou::SDK::Criteria::ProductFields::DEFAULT_VARIANT,
|
244
|
-
AboutYou::SDK::Criteria::ProductFields::DESCRIPTION_LONG,
|
245
|
-
AboutYou::SDK::Criteria::ProductFields::DESCRIPTION_SHORT,
|
246
|
-
AboutYou::SDK::Criteria::ProductFields::IS_ACTIVE,
|
247
|
-
AboutYou::SDK::Criteria::ProductFields::IS_SALE,
|
248
|
-
AboutYou::SDK::Criteria::ProductFields::MAX_PRICE,
|
249
|
-
AboutYou::SDK::Criteria::ProductFields::MIN_PRICE,
|
250
|
-
AboutYou::SDK::Criteria::ProductFields::VARIANTS
|
251
|
-
]
|
252
|
-
)
|
300
|
+
variants = {}
|
301
|
+
errors = []
|
302
|
+
productIds = []
|
303
|
+
productSearchResult = false
|
304
|
+
|
305
|
+
jsonObject.each do |id, data|
|
306
|
+
if data["error_code"]
|
307
|
+
errors.push(id)
|
308
|
+
else
|
309
|
+
variants[data["id"]] = data["product_id"]
|
310
|
+
productIds.push(data["product_id"])
|
253
311
|
end
|
312
|
+
end
|
254
313
|
|
255
|
-
|
314
|
+
if productIds.count > 0
|
315
|
+
productIds = productIds.uniq
|
316
|
+
# search products for valid variants
|
317
|
+
productSearchResult = self.shopApi.
|
318
|
+
fetchProductsByIds(
|
319
|
+
productIds, [
|
320
|
+
AboutYou::SDK::Criteria::ProductFields::ATTRIBUTES_MERGED,
|
321
|
+
AboutYou::SDK::Criteria::ProductFields::BRAND,
|
322
|
+
AboutYou::SDK::Criteria::ProductFields::CATEGORIES,
|
323
|
+
AboutYou::SDK::Criteria::ProductFields::DEFAULT_IMAGE,
|
324
|
+
AboutYou::SDK::Criteria::ProductFields::DEFAULT_VARIANT,
|
325
|
+
AboutYou::SDK::Criteria::ProductFields::DESCRIPTION_LONG,
|
326
|
+
AboutYou::SDK::Criteria::ProductFields::DESCRIPTION_SHORT,
|
327
|
+
AboutYou::SDK::Criteria::ProductFields::IS_ACTIVE,
|
328
|
+
AboutYou::SDK::Criteria::ProductFields::IS_SALE,
|
329
|
+
AboutYou::SDK::Criteria::ProductFields::MAX_PRICE,
|
330
|
+
AboutYou::SDK::Criteria::ProductFields::MIN_PRICE,
|
331
|
+
AboutYou::SDK::Criteria::ProductFields::VARIANTS
|
332
|
+
]
|
333
|
+
)
|
334
|
+
end
|
335
|
+
|
336
|
+
AboutYou::SDK::Model::VariantsResult.create(variants, errors, productSearchResult)
|
256
337
|
end
|
257
338
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
339
|
+
###
|
340
|
+
# creates a single product model
|
341
|
+
#
|
342
|
+
# * *Args* :
|
343
|
+
# - +jsonObject+ -> the api response in json format
|
344
|
+
#
|
345
|
+
# * *Returns* :
|
346
|
+
# - an instance of AboutYou::SDK::Model::Product
|
347
|
+
###
|
263
348
|
def createSingleProduct(jsonObject)
|
264
|
-
|
265
|
-
return self.createProduct(jsonObject);
|
349
|
+
self.createProduct(jsonObject)
|
266
350
|
end
|
267
351
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
352
|
+
###
|
353
|
+
# creates a products result model
|
354
|
+
#
|
355
|
+
# * *Args* :
|
356
|
+
# - +jsonObject+ -> the api response in json format
|
357
|
+
# - +query+ -> the query sent to the api
|
358
|
+
#
|
359
|
+
# * *Returns* :
|
360
|
+
# - an instance of AboutYou::SDK::Model::ProductsResult
|
361
|
+
###
|
273
362
|
def createProductsResult(jsonObject, query)
|
274
|
-
AboutYou::SDK::Model::ProductsResult.createFromJson(jsonObject, self)
|
363
|
+
AboutYou::SDK::Model::ProductsResult.createFromJson(jsonObject, self)
|
275
364
|
end
|
276
365
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
366
|
+
###
|
367
|
+
# creates a products eanresult model
|
368
|
+
#
|
369
|
+
# * *Args* :
|
370
|
+
# - +jsonObject+ -> the api response in json format
|
371
|
+
# - +query+ -> the query sent to the api
|
372
|
+
#
|
373
|
+
# * *Returns* :
|
374
|
+
# - an instance of AboutYou::SDK::Model::ProductsEanResult
|
375
|
+
###
|
282
376
|
def createProductsEansResult(jsonObject, query)
|
283
|
-
|
284
|
-
return AboutYou::SDK::Model::ProductsEansResult.createFromJson(jsonObject, self)
|
377
|
+
AboutYou::SDK::Model::ProductsEansResult.createFromJson(jsonObject, self)
|
285
378
|
end
|
286
379
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
380
|
+
###
|
381
|
+
# creates a product searchresult model
|
382
|
+
#
|
383
|
+
# * *Args* :
|
384
|
+
# - +jsonObject+ -> the api response in json format
|
385
|
+
# - +query+ -> the query sent to the api
|
386
|
+
#
|
387
|
+
# * *Returns* :
|
388
|
+
# - an instance of AboutYou::SDK::Model::ProductSearchResult
|
389
|
+
###
|
292
390
|
def createProductSearchResult(jsonObject, query)
|
293
|
-
|
294
|
-
return AboutYou::SDK::Model::ProductSearchResult.createFromJson(jsonObject, self);
|
391
|
+
return AboutYou::SDK::Model::ProductSearchResult.createFromJson(jsonObject, self)
|
295
392
|
end
|
296
393
|
|
297
394
|
###
|
298
|
-
#
|
299
|
-
#
|
300
|
-
#
|
395
|
+
# creates a categories result model
|
396
|
+
#
|
397
|
+
# * *Args* :
|
398
|
+
# - +jsonObject+ -> the api response in json format
|
399
|
+
# - +query+ -> the query sent to the api
|
400
|
+
#
|
401
|
+
# * *Returns* :
|
402
|
+
# - an instance of AboutYou::SDK::Model::CategoriesResult
|
301
403
|
###
|
302
|
-
def createCategoriesResult(jsonObject,
|
303
|
-
|
404
|
+
def createCategoriesResult(jsonObject, query)
|
405
|
+
AboutYou::SDK::Model::CategoriesResult.createFromJson(jsonObject, query["ids"], self)
|
304
406
|
end
|
305
407
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
408
|
+
###
|
409
|
+
# creates an Array containing suggests
|
410
|
+
#
|
411
|
+
# * *Args* :
|
412
|
+
# - +jsonArray+ -> an Array with the api response
|
413
|
+
# - +query+ -> the query sent to the api
|
414
|
+
#
|
415
|
+
# * *Returns* :
|
416
|
+
# - an Array containing suggests
|
417
|
+
###
|
311
418
|
def createSuggest(jsonArray, query)
|
312
|
-
|
313
|
-
return jsonArray;
|
419
|
+
jsonArray
|
314
420
|
end
|
315
421
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
422
|
+
###
|
423
|
+
# creates a variant model
|
424
|
+
#
|
425
|
+
# * *Args* :
|
426
|
+
# - +jsonObject+ -> the api response in json format
|
427
|
+
# - +product+ -> the product of the variant which should be created
|
428
|
+
#
|
429
|
+
# * *Returns* :
|
430
|
+
# - an instance of AboutYou::SDK::Model::Variant
|
431
|
+
###
|
321
432
|
def createVariant(jsonObject, product)
|
322
|
-
|
323
|
-
AboutYou::SDK::Model::Variant.createFromJson(jsonObject, self, product);
|
433
|
+
AboutYou::SDK::Model::Variant.createFromJson(jsonObject, self, product)
|
324
434
|
end
|
325
435
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
436
|
+
###
|
437
|
+
# creates an order model
|
438
|
+
#
|
439
|
+
# * *Args* :
|
440
|
+
# - +jsonObject+ -> the api response in json format
|
441
|
+
# - +query+ -> the query sent to the api
|
442
|
+
#
|
443
|
+
# * *Returns* :
|
444
|
+
# - an instance of AboutYou::SDK::Model::Order
|
445
|
+
###
|
446
|
+
def createOrder(jsonObject, query)
|
447
|
+
basket = self.createBasket(jsonObject["basket"])
|
334
448
|
|
335
|
-
|
449
|
+
AboutYou::SDK::Model::Order.new(jsonObject["order_id"], basket);
|
336
450
|
end
|
337
451
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
452
|
+
###
|
453
|
+
# creates an initiate order model
|
454
|
+
#
|
455
|
+
# * *Args* :
|
456
|
+
# - +jsonObject+ -> the api response in json format
|
457
|
+
# - +query+ -> the query sent to the api
|
458
|
+
#
|
459
|
+
# * *Returns* :
|
460
|
+
# - an instance of AboutYou::SDK::Model::InitiateOrder
|
461
|
+
###
|
462
|
+
def initiateOrder(jsonObject, query)
|
463
|
+
AboutYou::SDK::Model::InitiateOrder.createFromJson(jsonObject)
|
346
464
|
end
|
347
465
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
466
|
+
###
|
467
|
+
# creates a Has containing one or multiple pairs of
|
468
|
+
# app_id => instance of AboutYou::SDK::Model::App
|
469
|
+
#
|
470
|
+
# * *Args* :
|
471
|
+
# - +jsonObject+ -> the api response in json format
|
472
|
+
# - +query+ -> the query sent to the api
|
473
|
+
#
|
474
|
+
# * *Returns* :
|
475
|
+
# - a Hash containing pairs of app_id => instance of AboutYou::SDK::Model::App
|
476
|
+
###
|
477
|
+
def createChildApps(jsonObject, query)
|
478
|
+
apps = {}
|
479
|
+
jsonObject["child_apps"].each do |jsonApp|
|
480
|
+
app = self.createApp(jsonApp)
|
481
|
+
apps[app.id] = app
|
482
|
+
end
|
361
483
|
|
362
|
-
|
484
|
+
apps
|
363
485
|
end
|
364
486
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
487
|
+
###
|
488
|
+
# creates an app model
|
489
|
+
#
|
490
|
+
# * *Args* :
|
491
|
+
# - +jsonObject+ -> the api response in json format
|
492
|
+
#
|
493
|
+
# * *Returns* :
|
494
|
+
# - an instance of AboutYou::SDK::Model::App
|
495
|
+
###
|
370
496
|
def createApp(jsonObject)
|
371
|
-
|
372
|
-
return AboutYou::SDK::Model::App.createFromJson(jsonObject);
|
497
|
+
AboutYou::SDK::Model::App.createFromJson(jsonObject)
|
373
498
|
end
|
374
499
|
|
375
|
-
|
376
|
-
|
500
|
+
###
|
501
|
+
# this methods initiates the category manager
|
502
|
+
#
|
503
|
+
# * *Args* :
|
504
|
+
# - +jsonObject+ -> the api response in json format
|
505
|
+
###
|
377
506
|
def initializeCategoryManager(jsonObject)
|
378
|
-
|
379
|
-
return self.categoryManager().parseJson(jsonObject, self);
|
507
|
+
self.categoryManager.parseJson(jsonObject, self)
|
380
508
|
end
|
381
|
-
|
382
|
-
def updateFacetManager(jsonObject, query)
|
383
509
|
|
384
|
-
|
385
|
-
|
510
|
+
###
|
511
|
+
# this methods updates the facet manager
|
512
|
+
#
|
513
|
+
# * *Args* :
|
514
|
+
# - +jsonObject+ -> the api response in json format
|
515
|
+
# - +query+ -> the query sent to the api
|
516
|
+
###
|
517
|
+
def updateFacetManager(jsonObject, query)
|
518
|
+
self.facetManager.facets=(self.createFacetsList(jsonObject, query))
|
386
519
|
end
|
387
520
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
521
|
+
###
|
522
|
+
# this method creates a price range model
|
523
|
+
#
|
524
|
+
# * *Args* :
|
525
|
+
# - +jsonObject+ -> the api response in json format
|
526
|
+
#
|
527
|
+
# * *Returns* :
|
528
|
+
# - an Array containing instances of AboutYou::SDK::Model::PriceRange
|
529
|
+
###
|
393
530
|
def createPriceRanges(jsonObject)
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
return priceRanges;
|
531
|
+
priceRanges = []
|
532
|
+
jsonObject["ranges"].each do |range|
|
533
|
+
priceRanges.push(AboutYou::SDK::Model::PriceRange.createFromJson(range))
|
534
|
+
end
|
535
|
+
priceRanges
|
401
536
|
end
|
402
537
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
538
|
+
###
|
539
|
+
# this method creates a sale counts model
|
540
|
+
#
|
541
|
+
# * *Args* :
|
542
|
+
# - +jsonObject+ -> the api response in json format
|
543
|
+
#
|
544
|
+
# * *Returns* :
|
545
|
+
# - an instance of AboutYou::SDK::Model::SaleCounts
|
546
|
+
###
|
408
547
|
def createSaleFacet(jsonObject)
|
409
|
-
|
410
|
-
return AboutYou::SDK::Model::SaleCounts.createFromJson(jsonObject);
|
548
|
+
AboutYou::SDK::Model::SaleCounts.createFromJson(jsonObject)
|
411
549
|
end
|
412
550
|
|
413
|
-
|
414
|
-
|
415
|
-
|
551
|
+
###
|
552
|
+
# this method creates the facets for given categories
|
553
|
+
#
|
554
|
+
# * *Args* :
|
555
|
+
# - +jsonArray+ -> an Array containing the Api response
|
556
|
+
#
|
557
|
+
# * *Returns* :
|
558
|
+
# - a Hash containing pairs of category_id => category
|
559
|
+
###
|
416
560
|
def createCategoriesFacets(jsonArray)
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
end
|
561
|
+
counts = []
|
562
|
+
jsonArray.each do |item|
|
563
|
+
counts[item["term"]] = item["count"]
|
564
|
+
end
|
422
565
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
else
|
434
|
-
flattenCategories.delete(id)
|
435
|
-
end
|
566
|
+
# fetch all categories from API
|
567
|
+
flattenCategories = self.shopApi.fetchCategoriesByIds.categories
|
568
|
+
flattenCategories.each do |id ,category|
|
569
|
+
if counts[category.id]
|
570
|
+
category.productCount = counts[category.id]
|
571
|
+
if flattenCategories[String(category.parentId)]
|
572
|
+
category.parent = flattenCategories[String(category.parentId)].addChild(category)
|
573
|
+
end
|
574
|
+
else
|
575
|
+
flattenCategories.delete(id)
|
436
576
|
end
|
437
|
-
|
577
|
+
end
|
578
|
+
flattenCategories
|
438
579
|
end
|
439
|
-
def preHandleError(json, resultKey, isMultiRequest)
|
440
580
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
581
|
+
###
|
582
|
+
# this method tries to handle errors which are received from the api
|
583
|
+
#
|
584
|
+
# * *Args* :
|
585
|
+
# - +json+ -> the api response in json format
|
586
|
+
# - +resultKey+ -> the result key received from the api
|
587
|
+
# - +isMultiRequest+ -> determines whether the api-request was multiquery or not
|
588
|
+
###
|
589
|
+
def preHandleError(json, resultKey, isMultiRequest)
|
590
|
+
if resultKey == 'basket' && json["order_lines"]
|
591
|
+
return false
|
592
|
+
end
|
448
593
|
|
449
|
-
|
594
|
+
if isMultiRequest
|
595
|
+
raise 'ResultError!' + json
|
596
|
+
end
|
597
|
+
raise 'ResultError!' + json
|
450
598
|
end
|
451
599
|
end
|
452
600
|
end
|