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.
@@ -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
- # @param ShopApi $shopApi
12
- # @param FacetManagerInterface $facetManager
13
- # @param EventDispatcher $eventDispatcher
14
- ###
15
- def initialize(shopApi = nil,facetManager,categoryManager)
16
-
17
- self.shopApi=(shopApi);
18
- self.categoryManager = categoryManager;
19
- self.facetManager=facetManager;
20
- AboutYou::SDK::Model::FacetGroupSet.facetManager=(self.facetManager);
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
- # {@inheritdoc}
31
- #
32
- # @return ShopApi\Model\Autocomplete
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
- # {@inheritdoc}
41
- #
42
- # @return ShopApi\Model\Basket
43
- ###
44
- def createBasket(jsonObject)
45
-
46
- return AboutYou::SDK::Model::Basket.createFromJson(jsonObject, self);
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
- # {@inheritdoc}
51
- #
52
- # @return ShopApi\Model\Basket\BasketItem
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
- # {@inheritdoc}
61
- #
62
- # @return ShopApi\Model\Basket\BasketSet
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
- # {@inheritdoc}
71
- #
72
- # @return ShopApi\Model\Basket\BasketSetItem
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
- # {@inheritdoc}
81
- #
82
- # @return ShopApi\Model\Category
83
- ###
84
- def createCategory(jsonObject, parent = nil)
85
-
86
- return AboutYou::SDK::Model::Category.createFromJson(jsonObject, self.categoryManager);
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
- # {@inheritdoc}
91
- #
92
- #
93
- # @return ShopApi\Model\CategoryTree
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.initializeCategoryManager(jsonArray);
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
- # {@inheritdoc}
104
- #
105
- # @return ShopApi\Model\Facet
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
- # {@inheritdoc}
114
- #
115
- # @return ShopApi\Model\Facet[]
116
- ###
117
- def createFacetList(jsonArray, query=nil)
118
-
119
- facets = Hash.new
120
- jsonArray.each do |jsonFacet|
121
- facet = self.createFacet(jsonFacet);
122
- key = facet.uniqueKey();
123
- facets[key] = facet;
124
- end
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
- return facets;
176
+ facets
127
177
  end
128
178
 
129
- ###
130
- # {@inheritdoc}
131
- #
132
- # @return ShopApi\Model\Facet[]
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
- # {@inheritdoc}
142
- ###
143
- def createFacetsCounts(jsonObject)
144
- facetsCounts = Hash.new
145
-
146
- jsonObject["facets"].each do |groupId, jsonResultFacet|
147
- if !(groupId[/\d/])
148
- next
149
- end
150
- facetCounts = self.termFacets(groupId, jsonResultFacet["terms"])
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
- return facetsCounts;
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
- def termFacets(groupId, jsonTerms)
219
+
220
+ facetsCounts
221
+ end
163
222
 
164
- facetManager = self.facetManager;
165
-
166
- facetCounts = Array(nil);
167
- jsonTerms.each do |jsonTerm|
168
- id = Integer(jsonTerm["term"]);
169
- facet = facetManager.facet(groupId, id);
170
- if (facet == nil)
171
- next;
172
- end
173
- # TODO: Handle error, write test
174
-
175
- facetCounts.push(AboutYou::SDK::Model::FacetCount.new(facet, jsonTerm["count"]))
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
- return facetCounts;
179
- end
246
+ facetCounts
247
+ end
180
248
 
181
- ###
182
- # {@inheritdoc}
183
- #
184
- # @return integer[]
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
- # {@inheritdoc}
193
- #
194
- # @return ShopApi\Model\Image
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
- # {@inheritdoc}
203
- #
204
- # @return ShopApi\Model\Product
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
- # {@inheritdoc}
213
- #
214
- # @return ShopApi\Model\VariantsResult
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
- variants = Hash.new
219
- errors = Array(nil);
220
- productIds = Array(nil);
221
- productSearchResult = false;
222
-
223
- jsonObject.each do |id, data|
224
- if (data["error_code"])
225
- errors.push(id)
226
- else
227
- variants[data["id"]] = data["product_id"]
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
- return AboutYou::SDK::Model::VariantsResult.create(variants, errors, productSearchResult);
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
- # {@inheritdoc}
260
- #
261
- # @return ShopApi\Model\Product
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
- # {@inheritdoc}
270
- #
271
- # @return ShopApi\Model\ProductsResult
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
- # {@inheritdoc}
279
- #
280
- # @return ShopApi\Model\ProductsEansResult
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
- # {@inheritdoc}
289
- #
290
- # @return ShopApi\Model\ProductSearchResult
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
- # {@inheritdoc}
299
- #
300
- # @return ShopApi\Model\CategoriesResult
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, queryParams)
303
- return AboutYou::SDK::Model::CategoriesResult.createFromJson(jsonObject, queryParams["ids"], self)
404
+ def createCategoriesResult(jsonObject, query)
405
+ AboutYou::SDK::Model::CategoriesResult.createFromJson(jsonObject, query["ids"], self)
304
406
  end
305
407
 
306
- ###
307
- # {@inheritdoc}
308
- #
309
- # @return string[]
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
- # {@inheritdoc}
318
- #
319
- # @return ShopApi\Model\Variant
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
- # {@inheritdoc}
328
- #
329
- # @return ShopApi\Model\Order
330
- ###
331
- def createOrder(jsonObject)
332
-
333
- basket = self.createBasket(jsonObject["basket"]);
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
- return AboutYou::SDK::Model::Basket.new(jsonObject["order_id"], basket);
449
+ AboutYou::SDK::Model::Order.new(jsonObject["order_id"], basket);
336
450
  end
337
451
 
338
- ###
339
- # {@inheritdoc}
340
- #
341
- # @return ShopApi\Model\InitiateOrder
342
- ###
343
- def initiateOrder(jsonObject)
344
-
345
- return AboutYou::SDK::Model::InitiateOrder.createFromJson(jsonObject);
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
- # {@inheritdoc}
350
- #
351
- # @return ShopApi\Model\App[]
352
- ###
353
- def createChildApps(jsonObject)
354
-
355
- apps = Hash.new
356
- jsonObject["child_apps"].each do |jsonApp|
357
- app = self.createApp(jsonApp);
358
- key = app.id();
359
- apps[key] = app;
360
- end
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
- return apps;
484
+ apps
363
485
  end
364
486
 
365
- ###
366
- # {@inheritdoc}
367
- #
368
- # @return ShopApi\Model\App
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
- facets = self.createFacetsList(jsonObject, query);
385
- self.facetManager.facets=(facets);
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
- # {@inheritdoc}
390
- #
391
- # @return ShopApi\Model\ProductSearchResult\PriceRange[]
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
- priceRanges = Array(nil);
396
- jsonObject["ranges"].each do |range|
397
- priceRanges.push(AboutYou::SDK::Model::PriceRange.createFromJson(range))
398
- end
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
- # {@inheritdoc}
405
- #
406
- # @return ShopApi\Model\ProductSearchResult\SaleCounts
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
- # {@inheritdoc}
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
- counts = Array(nil);
418
- jsonArray.each do |item|
419
- categoryId = item["term"];
420
- counts[categoryId] = item["count"];
421
- end
561
+ counts = []
562
+ jsonArray.each do |item|
563
+ counts[item["term"]] = item["count"]
564
+ end
422
565
 
423
- # fetch all categories from API
424
- flattenCategories = self.shopApi().fetchCategoriesByIds().categories
425
- flattenCategories.each do |id ,category|
426
- if (counts[category.id])
427
- category.productCount = counts[category.id]
428
- if (flattenCategories[String(category.parentId)])
429
- parent = flattenCategories[String(category.parentId)];
430
- parent.addChild(category);
431
- category.parent=parent
432
- end
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
- return flattenCategories;
577
+ end
578
+ flattenCategories
438
579
  end
439
- def preHandleError(json, resultKey, isMultiRequest)
440
580
 
441
- if (resultKey == 'basket' && json["order_lines"])
442
- return false;
443
- end
444
-
445
- if (isMultiRequest)
446
- return 'ShopApi\Model\ResultError(json)';
447
- end
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
- raise 'ResultErrorException(json)';
594
+ if isMultiRequest
595
+ raise 'ResultError!' + json
596
+ end
597
+ raise 'ResultError!' + json
450
598
  end
451
599
  end
452
600
  end