aboutyou-sdk 0.0.1

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.
Files changed (53) hide show
  1. checksums.yaml +15 -0
  2. data/lib/aboutyou-sdk.rb +545 -0
  3. data/lib/aboutyou-sdk/Client.rb +125 -0
  4. data/lib/aboutyou-sdk/Constants.rb +48 -0
  5. data/lib/aboutyou-sdk/Criteria/ProductFields.rb +54 -0
  6. data/lib/aboutyou-sdk/Criteria/ProductSearchCriteria.rb +436 -0
  7. data/lib/aboutyou-sdk/Factory/DefaultModelFactory.rb +454 -0
  8. data/lib/aboutyou-sdk/Model/AbstractModel.rb +26 -0
  9. data/lib/aboutyou-sdk/Model/App.rb +35 -0
  10. data/lib/aboutyou-sdk/Model/Autocomplete.rb +92 -0
  11. data/lib/aboutyou-sdk/Model/Basket.rb +262 -0
  12. data/lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb +76 -0
  13. data/lib/aboutyou-sdk/Model/Basket/BasketItem.rb +100 -0
  14. data/lib/aboutyou-sdk/Model/Basket/BasketSet.rb +192 -0
  15. data/lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb +46 -0
  16. data/lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb +137 -0
  17. data/lib/aboutyou-sdk/Model/CategoriesResult.rb +15 -0
  18. data/lib/aboutyou-sdk/Model/Category.rb +126 -0
  19. data/lib/aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb +172 -0
  20. data/lib/aboutyou-sdk/Model/CategoryTree.rb +35 -0
  21. data/lib/aboutyou-sdk/Model/Facet.rb +105 -0
  22. data/lib/aboutyou-sdk/Model/FacetGroup.rb +110 -0
  23. data/lib/aboutyou-sdk/Model/FacetGroupSet.rb +247 -0
  24. data/lib/aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb +79 -0
  25. data/lib/aboutyou-sdk/Model/Image.rb +134 -0
  26. data/lib/aboutyou-sdk/Model/ImageSize.rb +21 -0
  27. data/lib/aboutyou-sdk/Model/InitiateOrder.rb +50 -0
  28. data/lib/aboutyou-sdk/Model/Order.rb +17 -0
  29. data/lib/aboutyou-sdk/Model/Product.rb +543 -0
  30. data/lib/aboutyou-sdk/Model/ProductSearchResult.rb +125 -0
  31. data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb +26 -0
  32. data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb +38 -0
  33. data/lib/aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb +49 -0
  34. data/lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb +58 -0
  35. data/lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb +27 -0
  36. data/lib/aboutyou-sdk/Model/ProductsEansResult.rb +43 -0
  37. data/lib/aboutyou-sdk/Model/ProductsResult.rb +52 -0
  38. data/lib/aboutyou-sdk/Model/ResultError.rb +24 -0
  39. data/lib/aboutyou-sdk/Model/Variant.rb +255 -0
  40. data/lib/aboutyou-sdk/Model/VariantsResult.rb +102 -0
  41. data/lib/aboutyou-sdk/Query.rb +261 -0
  42. data/lib/aboutyou-sdk/QueryBuilder.rb +440 -0
  43. data/tests/Sinatra-test/Main.rb +5 -0
  44. data/tests/testApiClient.rb +35 -0
  45. data/tests/testAutocomplete.rb +40 -0
  46. data/tests/testCatFilter.rb +35 -0
  47. data/tests/testCatTree.rb +37 -0
  48. data/tests/testFacets.rb +36 -0
  49. data/tests/testProdCatLongestPath.rb +34 -0
  50. data/tests/testProductSearchResult.rb +35 -0
  51. data/tests/testProductsByIds.rb +34 -0
  52. data/tests/testVariantsByIds.rb +34 -0
  53. metadata +122 -0
@@ -0,0 +1,440 @@
1
+ require 'json'
2
+
3
+ module AboutYou
4
+ module SDK
5
+ module QueryBuilder
6
+
7
+ ###
8
+ # @param string $searchword The prefix search word to search for.
9
+ # @param int $limit Maximum number of results.
10
+ # @param array $types Array of types to search for (Constants::TYPE_...).
11
+ #
12
+ # @return $this
13
+ #
14
+ # @throws \InvalidArgumentException
15
+ ###
16
+ def fetchAutocomplete(
17
+ searchword,
18
+ limit = nil,
19
+ types = nil)
20
+
21
+ if (!(searchword.is_a? String))
22
+ raise 'InvalidArgumentException! searchword must be a string'
23
+ end
24
+
25
+ # strtolower is a workaround of ticket SAPI-532
26
+ options = Hash[
27
+ 'searchword' => searchword.downcase
28
+ ]
29
+
30
+ if (limit != nil)
31
+ if (!(limit.is_a? Integer) && !limit[/\d/])
32
+ raise 'InvalidArgumentException! limit must be an integer'
33
+ end
34
+ options['limit'] = Integer(limit);
35
+ end
36
+
37
+ if (!types.empty?)
38
+ options['types'] = types;
39
+ end
40
+
41
+ self.query.push(Hash['autocompletion' => options])
42
+
43
+ return self;
44
+ end
45
+
46
+ ###
47
+ # @param string $sessionId Free to choose ID of the current website visitor.
48
+ #
49
+ # @return $this
50
+ ###
51
+ def fetchBasket(sessionId)
52
+
53
+ checkSessionId(sessionId);
54
+
55
+ self.query.push(Hash['basket' => Hash['session_id' => sessionId]])
56
+
57
+ return self;
58
+ end
59
+
60
+ ###
61
+ # @param string $sessionId Free to choose ID of the current website visitor.
62
+ # @param int $productVariantId ID of product variant.
63
+ # @param int $amount Amount of items to add.
64
+ #
65
+ #@return $this
66
+ ###
67
+ def addItemsToBasket(sessionId, items)
68
+
69
+ checkSessionId(sessionId);
70
+
71
+ orderLines = Array();
72
+
73
+ items.each do ||item|
74
+ orderLine = Hash['id' => item.getId(),'variant_id' => item.getVariantId()]
75
+
76
+ if(item.getAdditionalData())
77
+ orderLine['additional_data'] = item.getAdditionalData();
78
+ end
79
+
80
+ orderLines.push(orderLine)
81
+ end
82
+
83
+ self.query.push( Hash['basket' => Hash['session_id' => sessionId,'order_lines' => orderLines]])
84
+
85
+ return self;
86
+ end
87
+
88
+ ###
89
+ # @param string $sessionId Free to choose ID of the current website visitor.
90
+ # @param Model\BasketItemSet[] $itemSets
91
+ # @param int $amount Amount of items to add.
92
+ #
93
+ # @return $this
94
+ ###
95
+ def addItemSetsToBasket(sessionId, itemSets)
96
+
97
+ checkSessionId(sessionId);
98
+
99
+ orderLines = Array();
100
+
101
+ itemSets.each do |itemSet|
102
+ orderLine = Hash[
103
+ 'id' => itemSet.getId(),
104
+ 'set_items' => Array()
105
+ ]
106
+
107
+ if(itemSet.getAdditionalData())
108
+ orderLine['additional_data'] = itemSet.getAdditionalData();
109
+ end
110
+
111
+
112
+ itemSet.getItems().each do |item|
113
+ entry = Hash['variant_id' => item.getVariantId()]
114
+
115
+ if(item.getAdditionalData())
116
+ entry['additional_data'] = item.getAdditionalData();
117
+ end
118
+
119
+ orderLine['set_items'].push(entry)
120
+ end
121
+
122
+ orderLines.push(orderLine)
123
+ end
124
+
125
+ self.query.push(Hash['basket' => Hash['session_id' => sessionId,'order_lines' => orderLines]])
126
+
127
+ return self;
128
+ end
129
+
130
+ ###
131
+ # @param string $sessionId Free to choose ID of the current website visitor.
132
+ # @param int $productVariantId ID of product variant.
133
+ # @param string $basketItemId ID of single item or set in the basket
134
+ #
135
+ # @return $this
136
+ ###
137
+ def addToBasket(sessionId, productVariantId, basketItemId)
138
+
139
+ checkSessionId(sessionId);
140
+
141
+ self.query.push(Hash['basket' => Hash[
142
+ 'session_id' => sessionId,
143
+ 'order_lines' => Array(
144
+ Hash[
145
+ 'id' => basketItemId,
146
+ 'variant_id' => Integer(productVariantId)
147
+ ]
148
+ )
149
+ ]
150
+ ]
151
+ )
152
+
153
+ return self;
154
+ end
155
+
156
+ ###
157
+ # @param string $sessionId Free to choose ID of the current website visitor.
158
+ # @param string[] $itemIds array of basket item ids to delete, this can be sets or single items
159
+ #
160
+ # @return $this
161
+ ###
162
+ def removeFromBasket(sessionId, itemIds)
163
+
164
+ checkSessionId(sessionId);
165
+
166
+ orderLines = Array();
167
+
168
+ itemIds.each do |id|
169
+ orderLines.push(Hash['delete' => id])
170
+ end
171
+
172
+ self.query.push(Hash[
173
+ 'basket' => Hash[
174
+ 'session_id' => sessionId,
175
+ 'order_lines' => orderLines
176
+ ]
177
+ ]
178
+ )
179
+
180
+ return self;
181
+ end
182
+
183
+ ###
184
+ # @param string $sessionId
185
+ # @param Basket $basket
186
+ #
187
+ # @return $this
188
+ ###
189
+ def updateBasket(sessionId, basket)
190
+
191
+ checkSessionId(sessionId);
192
+
193
+ basketQuery = Hash['session_id' => sessionId]
194
+
195
+ orderLines = basket.getOrderLinesArray();
196
+ if (!orderLines.empty?)
197
+ basketQuery['order_lines'] = orderLines;
198
+ end
199
+
200
+ self.query.push(Hash['basket' => basketQuery])
201
+
202
+ return self;
203
+ end
204
+
205
+ ###
206
+ # @param int[]|string[] $ids either a single category ID as integer or an array of IDs
207
+ #
208
+ # @return $this
209
+ ###
210
+ def fetchCategoriesByIds(ids = nil)
211
+
212
+ if (ids == nil)
213
+ self.query.push('category' => nil)
214
+ else
215
+ # we allow to pass a single ID instead of an array
216
+ ids = Array(ids)
217
+
218
+ ids.each do |id|
219
+ id = id.to_i
220
+ if (id < 1)
221
+ raise 'InvalidArgumentException! A single category ID must be greater than 0'
222
+ end
223
+ end
224
+
225
+ ids = ids.map{|id| Integer(id)}
226
+
227
+ self.query.push(Hash[
228
+ 'category' => Hash[
229
+ 'ids' => ids
230
+ ]
231
+ ]
232
+ )
233
+ end
234
+ return self
235
+ end
236
+
237
+ ###
238
+ # @param int $maxDepth -1 <= $maxDepth <= 10,
239
+ #
240
+ # @return $this
241
+ ###
242
+ def fetchCategoryTree()
243
+
244
+ self.query.push(Hash['category_tree' => {"version"=>"2"}])
245
+
246
+ return self
247
+ end
248
+
249
+ ###
250
+ # @param string[]|int[] $ids
251
+ # @param array $fields
252
+ #
253
+ # @return $this
254
+ ###
255
+ def fetchProductsByIds(ids,fields = Array(nil))
256
+ # we allow to pass a single ID instead of an array
257
+
258
+ ids = Array(ids)
259
+ ids = ids.map{|id| Integer(id)}
260
+
261
+ self.query.push(Hash['products' => Hash['ids' => ids,'fields' => AboutYou::SDK::Criteria::ProductFields::filterFields(fields)]])
262
+
263
+ return self;
264
+ end
265
+
266
+ ###
267
+ # @param string[]|int[] $ids
268
+ #
269
+ # @return $this
270
+ ###
271
+ def fetchLiveVariantByIds(ids)
272
+ # we allow to pass a single ID instead of an array
273
+ ids = Array(ids)
274
+
275
+ ids = ids.map{|id| Integer(id)}
276
+
277
+ self.query.push(Hash['live_variant' => Hash['ids' => ids]])
278
+
279
+ return self;
280
+ end
281
+
282
+ ###
283
+ # @param string[] $eans
284
+ # @param array $fields
285
+ #
286
+ # @return $this
287
+ ###
288
+ def fetchProductsByEans(eans,fields = Array())
289
+ self.query.push(Hash[
290
+ 'products_eans' => Hash[
291
+ 'eans' => eans,
292
+ 'fields' => ProductFields::filterFields(fields),
293
+ 'version' => '2'
294
+ ]
295
+ ]
296
+ )
297
+
298
+ return self;
299
+ end
300
+
301
+ ###
302
+ # @param string|int $orderId
303
+ #
304
+ # @return $this
305
+ ###
306
+ def fetchOrder(orderId)
307
+
308
+ self.query.push(Hash['get_order' => Hash['order_id' =>orderId]])
309
+
310
+ return self;
311
+ end
312
+
313
+ ###
314
+ # @param string $sessionId
315
+ # @param string $successUrl
316
+ # @param string $cancelUrl
317
+ # @param string $errorUrl
318
+ #
319
+ # @return $this
320
+ ###
321
+ def initiateOrder(sessionId, successUrl, cancelUrl, errorUrl)
322
+
323
+ checkSessionId(sessionId);
324
+
325
+ args = Hash['session_id' => sessionId,'success_url' => successUrl]
326
+ if (cancelUrl)
327
+ args['cancel_url'] = cancelUrl;
328
+ end
329
+ if (errorUrl)
330
+ args['error_url'] = errorUrl;
331
+ end
332
+ self.query.push(Hash['initiate_order' => args])
333
+
334
+ return self;
335
+ end
336
+
337
+ ###
338
+ # @param ProductSearchCriteria $criteria
339
+ #
340
+ # @return $this
341
+ ###
342
+ def fetchProductSearch(criteria)
343
+
344
+ checkSessionId(criteria.sessionId());
345
+ self.query.push(Hash['product_search' =>criteria.toArray])
346
+
347
+ return self;
348
+ end
349
+
350
+ ###
351
+ # @param array $groupIds
352
+ #
353
+ # @return $this
354
+ #
355
+ # @throws \InvalidArgumentException
356
+ ###
357
+ def fetchFacets(groupIds = Array())
358
+
359
+ groupIds = groupIds.map{|groupId| Integer(groupId)}
360
+
361
+ self.query.push(Hash['facets' => Hash['group_ids' => groupIds]])
362
+
363
+ return self;
364
+ end
365
+
366
+ ###
367
+ # @param array $params
368
+ #
369
+ # @return $this
370
+ #
371
+ # @throws \InvalidArgumentException
372
+ ###
373
+ def fetchFacet(params)
374
+
375
+ if (params.empty)
376
+ raise 'InvalidArgumentException! no params given'
377
+ end
378
+
379
+ self.query.push(Hash['facet' => params])
380
+
381
+ return self
382
+ end
383
+
384
+ ###
385
+ # @return $this
386
+ ###
387
+ def fetchFacetTypes()
388
+
389
+ self.query.push(Hash['facet_types' => nil]);
390
+
391
+ return self;
392
+ end
393
+
394
+ ###
395
+ # @param string $searchword The search string to search for.
396
+ #
397
+ # @return $this
398
+ ###
399
+ def fetchSuggest(searchword)
400
+
401
+ self.query.push(Hash['suggest' => Hash['searchword' => searchword]])
402
+
403
+ return self
404
+ end
405
+
406
+ ###
407
+ # @return $this
408
+ ###
409
+ def fetchChildApps()
410
+
411
+ self.query.push(Hash['child_apps' => nil])
412
+
413
+ return self;
414
+ end
415
+
416
+ ###
417
+ # @return string
418
+ ###
419
+ def queryString()
420
+
421
+ return self.query.to_json
422
+ end
423
+
424
+ ###
425
+ # @param $sessionId
426
+ #
427
+ # @throws \InvalidArgumentException
428
+ ###
429
+ def checkSessionId(sessionId)
430
+
431
+ if (!(sessionId.is_a? String))
432
+ raise 'InvalidArgumentException! The session id must be a string'
433
+ end
434
+ if !(sessionId.length > 4)
435
+ raise 'InvalidArgumentException! The session id must have at least 5 characters'
436
+ end
437
+ end
438
+ end
439
+ end
440
+ end
@@ -0,0 +1,5 @@
1
+ require 'sinatra'
2
+
3
+ get "/" do
4
+ erb :'partial_view', :locals => {:foo => "bar"}
5
+ end
@@ -0,0 +1,35 @@
1
+ require 'httparty'
2
+
3
+ query = HTTParty.post("https://shop-api.aboutyou.de/api",
4
+ {
5
+ :body=>
6
+ '[{
7
+ "products": {
8
+ "ids": [
9
+ 144388,
10
+ 144389
11
+ ],
12
+ "fields": [
13
+ "id",
14
+ "name",
15
+ "active",
16
+ "brand_id",
17
+ "description_long",
18
+ "description_short",
19
+ "default_variant",
20
+ "variants",
21
+ "min_price",
22
+ "max_price",
23
+ "sale",
24
+ "default_image",
25
+ "attributes_merged",
26
+ "categories"
27
+ ]
28
+ }
29
+ }]',
30
+ :basic_auth => { :username => 281 , :password => 'e6068c4ca020262613d06122663cb300'},
31
+ :headers => { 'Content-Type' => 'application/json',
32
+ 'Accept-Encoding' => 'gzip,deflate' }
33
+ })
34
+
35
+ puts query