aboutyou-sdk 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +8 -8
  2. data/lib/{aboutyou-sdk/CacheProvider/Dalli.rb → AboutYou/CacheProvider/dalli.rb} +18 -19
  3. data/lib/{aboutyou-sdk/CacheProvider/Redis.rb → AboutYou/CacheProvider/redis.rb} +19 -20
  4. data/lib/{aboutyou-sdk/Criteria/ProductFields.rb → AboutYou/Criteria/product_fields.rb} +25 -27
  5. data/lib/{aboutyou-sdk/Criteria/ProductSearchCriteria.rb → AboutYou/Criteria/product_search_criteria.rb} +128 -123
  6. data/lib/{aboutyou-sdk/Factory/DefaultModelFactory.rb → AboutYou/Factory/default_model_factory.rb} +267 -224
  7. data/lib/AboutYou/Model/Basket/abstract_basket_item.rb +57 -0
  8. data/lib/AboutYou/Model/Basket/basket_item.rb +95 -0
  9. data/lib/AboutYou/Model/Basket/basket_set.rb +199 -0
  10. data/lib/AboutYou/Model/Basket/basket_set_item.rb +54 -0
  11. data/lib/AboutYou/Model/Basket/basket_variant_item.rb +123 -0
  12. data/lib/{aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb → AboutYou/Model/CategoryManager/default_category_manager.rb} +80 -65
  13. data/lib/{aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb → AboutYou/Model/FacetManager/default_facet_manager.rb} +58 -50
  14. data/lib/{aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb → AboutYou/Model/ProductSearchResult/facet_count.rb} +2 -3
  15. data/lib/AboutYou/Model/ProductSearchResult/facet_counts.rb +67 -0
  16. data/lib/{aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb → AboutYou/Model/ProductSearchResult/price_range.rb} +17 -18
  17. data/lib/AboutYou/Model/ProductSearchResult/sale_counts.rb +79 -0
  18. data/lib/AboutYou/Model/ProductSearchResult/terms_count.rb +40 -0
  19. data/lib/{aboutyou-sdk/Model/AbstractModel.rb → AboutYou/Model/abstract_model.rb} +2 -3
  20. data/lib/{aboutyou-sdk/Model/App.rb → AboutYou/Model/app.rb} +15 -15
  21. data/lib/{aboutyou-sdk/Model/Autocomplete.rb → AboutYou/Model/autocomplete.rb} +25 -32
  22. data/lib/AboutYou/Model/basket.rb +235 -0
  23. data/lib/AboutYou/Model/categories_result.rb +24 -0
  24. data/lib/AboutYou/Model/category.rb +102 -0
  25. data/lib/AboutYou/Model/category_tree.rb +37 -0
  26. data/lib/AboutYou/Model/facet.rb +86 -0
  27. data/lib/AboutYou/Model/facet_group.rb +96 -0
  28. data/lib/AboutYou/Model/facet_group_set.rb +209 -0
  29. data/lib/AboutYou/Model/image.rb +102 -0
  30. data/lib/{aboutyou-sdk/Model/ImageSize.rb → AboutYou/Model/image_size.rb} +9 -5
  31. data/lib/AboutYou/Model/initiate_order.rb +53 -0
  32. data/lib/AboutYou/Model/order.rb +22 -0
  33. data/lib/AboutYou/Model/product.rb +353 -0
  34. data/lib/AboutYou/Model/product_search_result.rb +114 -0
  35. data/lib/AboutYou/Model/products_ean_result.rb +43 -0
  36. data/lib/AboutYou/Model/products_result.rb +56 -0
  37. data/lib/AboutYou/Model/result_error.rb +28 -0
  38. data/lib/AboutYou/Model/variant.rb +214 -0
  39. data/lib/AboutYou/Model/variants_result.rb +91 -0
  40. data/lib/AboutYou/client.rb +128 -0
  41. data/lib/{aboutyou-sdk/Constants.rb → AboutYou/constants.rb} +3 -5
  42. data/lib/AboutYou/query.rb +343 -0
  43. data/lib/AboutYou/query_builder.rb +530 -0
  44. data/lib/ay.rb +566 -0
  45. data/tests/Sinatra-test/Main.rb +3 -0
  46. data/tests/testAutocomplete.rb +5 -6
  47. data/tests/testCatFilter.rb +8 -9
  48. data/tests/testCatTree.rb +3 -3
  49. data/tests/testCategoryCaching.rb +4 -5
  50. data/tests/{testFacetCaching.rb → testDalliCache.rb} +4 -5
  51. data/tests/testFacetTypes.rb +5 -6
  52. data/tests/testFacets.rb +7 -8
  53. data/tests/testFetchFacet.rb +5 -6
  54. data/tests/testJavaScript.rb +3 -4
  55. data/tests/testProdCatLongestPath.rb +7 -8
  56. data/tests/testProductSearchResult.rb +6 -7
  57. data/tests/testProductsByEans.rb +6 -7
  58. data/tests/testProductsByIds.rb +6 -7
  59. data/tests/testRedisCache.rb +4 -5
  60. data/tests/testSuggest.rb +5 -6
  61. data/tests/testVariantsByIds.rb +7 -8
  62. metadata +46 -46
  63. data/lib/aboutyou-sdk.rb +0 -596
  64. data/lib/aboutyou-sdk/Client.rb +0 -134
  65. data/lib/aboutyou-sdk/Model/Basket.rb +0 -268
  66. data/lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb +0 -76
  67. data/lib/aboutyou-sdk/Model/Basket/BasketItem.rb +0 -100
  68. data/lib/aboutyou-sdk/Model/Basket/BasketSet.rb +0 -192
  69. data/lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb +0 -46
  70. data/lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb +0 -137
  71. data/lib/aboutyou-sdk/Model/CategoriesResult.rb +0 -15
  72. data/lib/aboutyou-sdk/Model/Category.rb +0 -126
  73. data/lib/aboutyou-sdk/Model/CategoryTree.rb +0 -35
  74. data/lib/aboutyou-sdk/Model/Facet.rb +0 -105
  75. data/lib/aboutyou-sdk/Model/FacetGroup.rb +0 -110
  76. data/lib/aboutyou-sdk/Model/FacetGroupSet.rb +0 -242
  77. data/lib/aboutyou-sdk/Model/Image.rb +0 -134
  78. data/lib/aboutyou-sdk/Model/InitiateOrder.rb +0 -50
  79. data/lib/aboutyou-sdk/Model/Order.rb +0 -17
  80. data/lib/aboutyou-sdk/Model/Product.rb +0 -335
  81. data/lib/aboutyou-sdk/Model/ProductSearchResult.rb +0 -125
  82. data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb +0 -59
  83. data/lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb +0 -71
  84. data/lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb +0 -36
  85. data/lib/aboutyou-sdk/Model/ProductsEansResult.rb +0 -47
  86. data/lib/aboutyou-sdk/Model/ProductsResult.rb +0 -52
  87. data/lib/aboutyou-sdk/Model/ResultError.rb +0 -24
  88. data/lib/aboutyou-sdk/Model/Variant.rb +0 -255
  89. data/lib/aboutyou-sdk/Model/VariantsResult.rb +0 -102
  90. data/lib/aboutyou-sdk/Query.rb +0 -350
  91. data/lib/aboutyou-sdk/QueryBuilder.rb +0 -499
@@ -1,102 +0,0 @@
1
- module AboutYou
2
- module SDK
3
- module Model
4
- class VariantsResult
5
-
6
- # @var Variant[] */
7
- attr_accessor :variants
8
- # @var array */
9
- attr_accessor :errors
10
-
11
- ###
12
- #
13
- # @param \stdClass $jsonObject
14
- # @param \Collins\ShopApi\Model\ModelFactoryInterface $factory
15
- # @param \Collins\ShopApi\Model\ProductSearchResult $productSearchResult
16
- #
17
- # @return static
18
- ###
19
- def self.create(variants, errors = Array(nil), productSearchResult)
20
-
21
- variantsResult = self.new
22
- variantsResult.variants = Hash.new
23
- variantsResult.errors = errors;
24
-
25
- if (productSearchResult == false || variants.count == 0)
26
- # no variant was found
27
- return variantsResult;
28
- end
29
-
30
- # get products from product-search
31
- products = productSearchResult.products();
32
- variants.each do |variantId, productId|
33
- if !(products[productId])
34
- # product was not delivered
35
- variantsResult.errors.push(variantId)
36
- next
37
- end
38
-
39
- product = products[productId];
40
- variant = product.variantById(variantId);
41
-
42
- if (variant.is_a? AboutYou::SDK::Model::Variant)
43
- variantsResult.variants[variantId] = variant;
44
- end
45
- end
46
-
47
- return variantsResult;
48
- end
49
-
50
- ###
51
- # @return bool
52
- ###
53
- def hasVariantsFound()
54
-
55
- self.variants.count > 0;
56
- end
57
-
58
- ###
59
- # @return bool
60
- ###
61
- def hasVariantsNotFound()
62
-
63
- self.errors.count > 0;
64
- end
65
-
66
- ###
67
- # @return Variant[]
68
- ###
69
- def variantsFound()
70
-
71
- self.variants;
72
- end
73
-
74
-
75
- ###
76
- # @param int $id
77
- #
78
- #
79
- # @return Variant|null
80
- ###
81
- def variantById(id)
82
-
83
- result = nil;
84
-
85
- if (self.variants[id])
86
- result = self.variants[id];
87
- end
88
-
89
- return result;
90
- end
91
-
92
- ###
93
- # @return int[]
94
- ###
95
- def variantsNotFound()
96
-
97
- self.errors;
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,350 +0,0 @@
1
- require_relative 'QueryBuilder.rb'
2
-
3
- module AboutYou
4
- module SDK
5
- ###
6
- # The Query class coordinates the building, executing and parsing of one or multiple API-calls
7
- #
8
- # Author:: Collins GmbH & Co KG
9
- ###
10
- class Query
11
- # QueryBuilder is a helper class containing most of the logix behind
12
- # building the api-request
13
- include AboutYou::SDK::QueryBuilder
14
-
15
- # used for checking whether a query contains a category-request or not
16
- QUERY_TREE = 'category_tree'
17
- # used for checking whether a query contains a facets-request or not
18
- QUERY_FACETS = 'facets'
19
-
20
- # The Api-Client which performs the Api-Calls
21
- attr_accessor :client
22
- # the query built by the app itself
23
- attr_accessor :query
24
- # a Hash containing the mapping for
25
- # api_call_name => method_name_in_model_factory
26
- attr_accessor :mapping
27
- # the model factory which builds the models from the api-response
28
- attr_accessor :factory
29
- # a helper-query used for fetching categories and/or facets if needed
30
- attr_accessor :ghostQuery
31
- # the actual query send to the api containing query and ghost-query
32
- attr_accessor :allQuery
33
-
34
-
35
- ###
36
- # the Constructor for the Query class
37
- #
38
- # * *Args* :
39
- # - +client+ -> an instance of AboutYou::SDK::Client
40
- # - +factory+ -> an instance of AboutYou::SDK::Factory::DefaultModelFactory
41
- #
42
- # * *Returns* :
43
- # - Instance of AboutYou::SDK::Query
44
- ###
45
- def initialize(client, factory)
46
- self.client = client
47
- self.query= []
48
- self.ghostQuery = []
49
- self.allQuery = []
50
- self.factory=factory
51
- self.mapping = {
52
- 'autocompletion' => 'createAutocomplete',
53
- 'basket' => 'createBasket',
54
- 'category' => 'createCategoriesResult',
55
- 'category_tree' => 'createCategoryTree',
56
- 'facets' => 'createFacetsList',
57
- 'facet' => 'createFacetList',
58
- 'facet_types' => 'createFacetTypes',
59
- 'products' => 'createProductsResult',
60
- 'products_eans' => 'createProductsEansResult',
61
- 'product_search' => 'createProductSearchResult',
62
- 'suggest' => 'createSuggest',
63
- 'get_order' => 'createOrder',
64
- 'initiate_order' => 'initiateOrder',
65
- 'child_apps' => 'createChildApps',
66
- 'live_variant' => 'createVariantsResult'
67
- }
68
- end
69
-
70
- ###
71
- # wrapper-method for fetchAutocomplete which coordinates Category- and Facet-Manager
72
- #
73
- # * *Args* :
74
- # - +searchword+ -> a String containing the word to search completitions for
75
- # - +limit+ -> Maximum number of results [optional]
76
- # - +types+ -> Array of types to search for [optional]
77
- #
78
- # * *Returns* :
79
- # - Instance of AboutYou::SDK::Query
80
- ###
81
- def fetchAutocomplete(searchword, limit = nil, types = nil)
82
-
83
- super(searchword, limit, types)
84
-
85
- self.requireCategoryTree
86
- self.requireFacets
87
-
88
- return self
89
- end
90
-
91
- ###
92
- # wrapper-method for fetchBasket which coordinates Category- and Facet-Manager
93
- #
94
- # * *Args* :
95
- # - +sessionId+ -> a String containing the session id of an user
96
- #
97
- # * *Returns* :
98
- # - Instance of AboutYou::SDK::Query
99
- ###
100
- def fetchBasket(sessionId)
101
-
102
- super(sessionId)
103
-
104
- self.requireCategoryTree
105
- self.requireFacets
106
-
107
- return self
108
- end
109
-
110
- def fetchFacets(groupIds=[])
111
- super(groupIds)
112
- end
113
-
114
- ###
115
- # wrapper-method for fetchProductsByIds which coordinates Category- and Facet-Manager
116
- #
117
- # * *Args* :
118
- # - +ids+ -> Either a single id or an Array of ids which should be fetched
119
- # - +fields+ -> Additional product fields which should be fetched for each product [optional]
120
- #
121
- # * *Returns* :
122
- # - Instance of AboutYou::SDK::Query
123
- ###
124
- def fetchProductsByIds(ids,fields = [])
125
-
126
- super(ids, fields)
127
- if AboutYou::SDK::Criteria::ProductFields.requiresCategories(fields)
128
- self.requireCategoryTree
129
- end
130
- if AboutYou::SDK::Criteria::ProductFields.requiresFacets(fields)
131
- self.requireFacets
132
- end
133
- return self
134
- end
135
-
136
- ###
137
- # wrapper-method for fetchProductsByEans which coordinates Category- and Facet-Manager
138
- #
139
- # * *Args* :
140
- # - +eans+ -> Either a single ean or an Array of eans which should be fetched
141
- # - +fields+ -> Additional product fields which should be fetched for each product [optional]
142
- #
143
- # * *Returns* :
144
- # - Instance of AboutYou::SDK::Query
145
- ###
146
- def fetchProductsByEans(eans,fields = [])
147
-
148
- super(eans, fields)
149
-
150
- if AboutYou::SDK::Criteria::ProductFields.requiresCategories(fields)
151
- self.requireCategoryTree
152
- end
153
- if AboutYou::SDK::Criteria::ProductFields.requiresFacets(fields)
154
- self.requireFacets
155
- end
156
-
157
- return self
158
- end
159
-
160
- ###
161
- # wrapper-method for fetchProductSearch which coordinates Category- and Facet-Manager
162
- #
163
- # * *Args* :
164
- # - +criteria+ -> Hash containing one or multiple search terms
165
- #
166
- # * *Returns* :
167
- # - Instance of AboutYou::SDK::Query
168
- ###
169
- def fetchProductSearch(criteria)
170
-
171
- super(criteria)
172
-
173
- if criteria.requiresCategories
174
- self.requireCategoryTree
175
- end
176
- if criteria.requiresFacets
177
- self.requireFacets
178
- end
179
-
180
- return self
181
- end
182
-
183
-
184
- ###
185
- # this method checks whether it is neccessary for the query to get the category-tree from the api
186
- #
187
- # * *Args* :
188
- # - +fetchForced+ -> determines whether the requirance of the category tree is forced
189
- #
190
- # * *Returns* :
191
- # - Instance of AboutYou::SDK::Query
192
- ###
193
- def requireCategoryTree(fetchForced = false)
194
- unless fetchForced || self.factory.categoryManager.isEmpty
195
- return self
196
- end
197
-
198
- self.ghostQuery.push({QUERY_TREE => {
199
- 'category_tree' => {
200
- 'version' => '2'
201
- }}})
202
-
203
- return self
204
- end
205
-
206
-
207
- ###
208
- # this method checks whether it is neccessary for the query to get the facets from the api
209
- #
210
- # * *Args* :
211
- # - +fetchForced+ -> determines whether the requirance of the facets is forced
212
- #
213
- # * *Returns* :
214
- # - Instance of AboutYou::SDK::Query
215
- ###
216
- def requireFacets(fetchForced = false)
217
- unless fetchForced || self.factory.facetManager.isEmpty
218
- return self
219
- end
220
- self.ghostQuery.push({QUERY_FACETS => {
221
- 'facets' => {}
222
- }})
223
-
224
- return self
225
- end
226
-
227
- ###
228
- # the methods builds the complete query string which represents the body of the api call
229
- #
230
- # * *Returns* :
231
- # - JSON-String containing all queries which need to be executed
232
- ###
233
- def queryString
234
- result = []
235
- self.ghostQuery.each do |ghostQuery|
236
- (ghostQuery.is_a? Hash) ? result.push(ghostQuery[ghostQuery.keys[0]]) : nil
237
- end
238
- self.allQuery = result + self.query
239
- return (result + self.query).to_json
240
- end
241
-
242
-
243
- ###
244
- # requests all of the queries and returns the parsed api-response
245
- #
246
- # * *Returns* :
247
- # - an Array containing all of the models build with the data of the api
248
- ###
249
- def execute
250
- if self.query.empty? && self.ghostQuery.empty?
251
- return []
252
- end
253
- parseResult(self.client.request(queryString), self.query.count > 1)
254
- end
255
-
256
- ###
257
- # requests all of the queries and returns only the first parsed api-response
258
- #
259
- # * *Returns* :
260
- # - the first model build with the data of the api
261
- ###
262
- def executeSingle
263
-
264
- execute[-1]
265
- end
266
-
267
-
268
- ###
269
- # this method checks whether the api delievered a valid json-response or not
270
- #
271
- # * *Args* :
272
- # - +jsonResponse+ -> the plain json received from the api
273
- ###
274
- def checkResponse(jsonResponse)
275
-
276
- if jsonResponse == false || !(jsonResponse.is_a? Array) || jsonResponse.count != self.allQuery.count
277
- raise 'UnexpectedResultException!'
278
- end
279
-
280
- (0..jsonResponse.count-1).each do |index|
281
- currentQuery = self.allQuery[index]
282
- responseKey = jsonResponse[index].keys[0]
283
- queryKey = currentQuery.keys[0]
284
-
285
- if responseKey != queryKey
286
- raise 'UnexpectedResultException! result ' + String(queryKey) + ' expected,
287
- but ' + String(responseKey) + ' given on position ' + String(index) +
288
- ' - query: ' + currentQuery.to_json
289
- end
290
-
291
- unless self.mapping.key? responseKey
292
- raise 'UnexpectedResultException! internal error, ' + String(responseKey) + ' is unknown result'
293
- end
294
- end
295
- end
296
-
297
-
298
- ###
299
- # parses the plain json result from the api and calls the respective modelfactory methods
300
- # for building the models for the json resposne
301
- #
302
- # * *Args* :
303
- # - +jsonResponse+ -> the plain json received from the api
304
- # - +isMultiRequest+ -> boolean which determines whether the request has more then one
305
- # query or not [optional]
306
- #
307
- # * *Returns* :
308
- # - an Array containing all models build from the modelfactory
309
- ###
310
- def parseResult(jsonResponse, isMultiRequest=true)
311
-
312
- self.checkResponse(jsonResponse)
313
- results = []
314
- queryIds = []
315
-
316
- self.allQuery.each do |query|
317
- queryIds.push(query.keys[0])
318
- end
319
-
320
- jsonResponse.each_with_index do |responseObject, index|
321
- currentQuery = self.allQuery[index]
322
- resultKey = responseObject.keys[0]
323
- jsonObject = responseObject[resultKey]
324
- queryKey = currentQuery.keys[0]
325
- factory = self.factory
326
- if (jsonObject.is_a? Hash) && jsonObject['error_code']
327
- result = factory.preHandleError(jsonObject, resultKey, isMultiRequest)
328
- if result != false
329
- results.push({resultKey=> result})
330
- next
331
- end
332
- end
333
- query = currentQuery[queryKey]
334
- queryId = queryIds[index]
335
- if queryId == QUERY_FACETS
336
- factory.updateFacetManager(jsonObject, query)
337
- elsif queryId == QUERY_TREE
338
- factory.initializeCategoryManager(jsonObject)
339
- else
340
- method = self.mapping[resultKey]
341
- result = factory.send(method, jsonObject, query)
342
- results.push(result)
343
- end
344
- end
345
-
346
- return results
347
- end
348
- end
349
- end
350
- end