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.
- checksums.yaml +8 -8
- data/lib/{aboutyou-sdk/CacheProvider/Dalli.rb → AboutYou/CacheProvider/dalli.rb} +18 -19
- data/lib/{aboutyou-sdk/CacheProvider/Redis.rb → AboutYou/CacheProvider/redis.rb} +19 -20
- data/lib/{aboutyou-sdk/Criteria/ProductFields.rb → AboutYou/Criteria/product_fields.rb} +25 -27
- data/lib/{aboutyou-sdk/Criteria/ProductSearchCriteria.rb → AboutYou/Criteria/product_search_criteria.rb} +128 -123
- data/lib/{aboutyou-sdk/Factory/DefaultModelFactory.rb → AboutYou/Factory/default_model_factory.rb} +267 -224
- data/lib/AboutYou/Model/Basket/abstract_basket_item.rb +57 -0
- data/lib/AboutYou/Model/Basket/basket_item.rb +95 -0
- data/lib/AboutYou/Model/Basket/basket_set.rb +199 -0
- data/lib/AboutYou/Model/Basket/basket_set_item.rb +54 -0
- data/lib/AboutYou/Model/Basket/basket_variant_item.rb +123 -0
- data/lib/{aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb → AboutYou/Model/CategoryManager/default_category_manager.rb} +80 -65
- data/lib/{aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb → AboutYou/Model/FacetManager/default_facet_manager.rb} +58 -50
- data/lib/{aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb → AboutYou/Model/ProductSearchResult/facet_count.rb} +2 -3
- data/lib/AboutYou/Model/ProductSearchResult/facet_counts.rb +67 -0
- data/lib/{aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb → AboutYou/Model/ProductSearchResult/price_range.rb} +17 -18
- data/lib/AboutYou/Model/ProductSearchResult/sale_counts.rb +79 -0
- data/lib/AboutYou/Model/ProductSearchResult/terms_count.rb +40 -0
- data/lib/{aboutyou-sdk/Model/AbstractModel.rb → AboutYou/Model/abstract_model.rb} +2 -3
- data/lib/{aboutyou-sdk/Model/App.rb → AboutYou/Model/app.rb} +15 -15
- data/lib/{aboutyou-sdk/Model/Autocomplete.rb → AboutYou/Model/autocomplete.rb} +25 -32
- data/lib/AboutYou/Model/basket.rb +235 -0
- data/lib/AboutYou/Model/categories_result.rb +24 -0
- data/lib/AboutYou/Model/category.rb +102 -0
- data/lib/AboutYou/Model/category_tree.rb +37 -0
- data/lib/AboutYou/Model/facet.rb +86 -0
- data/lib/AboutYou/Model/facet_group.rb +96 -0
- data/lib/AboutYou/Model/facet_group_set.rb +209 -0
- data/lib/AboutYou/Model/image.rb +102 -0
- data/lib/{aboutyou-sdk/Model/ImageSize.rb → AboutYou/Model/image_size.rb} +9 -5
- data/lib/AboutYou/Model/initiate_order.rb +53 -0
- data/lib/AboutYou/Model/order.rb +22 -0
- data/lib/AboutYou/Model/product.rb +353 -0
- data/lib/AboutYou/Model/product_search_result.rb +114 -0
- data/lib/AboutYou/Model/products_ean_result.rb +43 -0
- data/lib/AboutYou/Model/products_result.rb +56 -0
- data/lib/AboutYou/Model/result_error.rb +28 -0
- data/lib/AboutYou/Model/variant.rb +214 -0
- data/lib/AboutYou/Model/variants_result.rb +91 -0
- data/lib/AboutYou/client.rb +128 -0
- data/lib/{aboutyou-sdk/Constants.rb → AboutYou/constants.rb} +3 -5
- data/lib/AboutYou/query.rb +343 -0
- data/lib/AboutYou/query_builder.rb +530 -0
- data/lib/ay.rb +566 -0
- data/tests/Sinatra-test/Main.rb +3 -0
- data/tests/testAutocomplete.rb +5 -6
- data/tests/testCatFilter.rb +8 -9
- data/tests/testCatTree.rb +3 -3
- data/tests/testCategoryCaching.rb +4 -5
- data/tests/{testFacetCaching.rb → testDalliCache.rb} +4 -5
- data/tests/testFacetTypes.rb +5 -6
- data/tests/testFacets.rb +7 -8
- data/tests/testFetchFacet.rb +5 -6
- data/tests/testJavaScript.rb +3 -4
- data/tests/testProdCatLongestPath.rb +7 -8
- data/tests/testProductSearchResult.rb +6 -7
- data/tests/testProductsByEans.rb +6 -7
- data/tests/testProductsByIds.rb +6 -7
- data/tests/testRedisCache.rb +4 -5
- data/tests/testSuggest.rb +5 -6
- data/tests/testVariantsByIds.rb +7 -8
- metadata +46 -46
- data/lib/aboutyou-sdk.rb +0 -596
- data/lib/aboutyou-sdk/Client.rb +0 -134
- data/lib/aboutyou-sdk/Model/Basket.rb +0 -268
- data/lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb +0 -76
- data/lib/aboutyou-sdk/Model/Basket/BasketItem.rb +0 -100
- data/lib/aboutyou-sdk/Model/Basket/BasketSet.rb +0 -192
- data/lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb +0 -46
- data/lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb +0 -137
- data/lib/aboutyou-sdk/Model/CategoriesResult.rb +0 -15
- data/lib/aboutyou-sdk/Model/Category.rb +0 -126
- data/lib/aboutyou-sdk/Model/CategoryTree.rb +0 -35
- data/lib/aboutyou-sdk/Model/Facet.rb +0 -105
- data/lib/aboutyou-sdk/Model/FacetGroup.rb +0 -110
- data/lib/aboutyou-sdk/Model/FacetGroupSet.rb +0 -242
- data/lib/aboutyou-sdk/Model/Image.rb +0 -134
- data/lib/aboutyou-sdk/Model/InitiateOrder.rb +0 -50
- data/lib/aboutyou-sdk/Model/Order.rb +0 -17
- data/lib/aboutyou-sdk/Model/Product.rb +0 -335
- data/lib/aboutyou-sdk/Model/ProductSearchResult.rb +0 -125
- data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb +0 -59
- data/lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb +0 -71
- data/lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb +0 -36
- data/lib/aboutyou-sdk/Model/ProductsEansResult.rb +0 -47
- data/lib/aboutyou-sdk/Model/ProductsResult.rb +0 -52
- data/lib/aboutyou-sdk/Model/ResultError.rb +0 -24
- data/lib/aboutyou-sdk/Model/Variant.rb +0 -255
- data/lib/aboutyou-sdk/Model/VariantsResult.rb +0 -102
- data/lib/aboutyou-sdk/Query.rb +0 -350
- data/lib/aboutyou-sdk/QueryBuilder.rb +0 -499
data/lib/{aboutyou-sdk/Factory/DefaultModelFactory.rb → AboutYou/Factory/default_model_factory.rb}
RENAMED
@@ -10,124 +10,137 @@ module AboutYou
|
|
10
10
|
###
|
11
11
|
class DefaultModelFactory
|
12
12
|
# The client which performs the api calls
|
13
|
-
attr_accessor :
|
13
|
+
attr_accessor :shop_api
|
14
14
|
# the category manager responsible for managing the categories
|
15
|
-
attr_accessor :
|
15
|
+
attr_accessor :category_manager
|
16
16
|
# the facet manager responsible for managing the facets
|
17
|
-
attr_accessor :
|
17
|
+
attr_accessor :facet_manager
|
18
18
|
|
19
19
|
###
|
20
20
|
# Constructor for AboutYou::SDK::Factory::DefaultModelFactory
|
21
21
|
#
|
22
22
|
# * *Args* :
|
23
|
-
# - +
|
24
|
-
# - +
|
25
|
-
# - +:
|
23
|
+
# - +shop_api+ -> the client which should perform the api calls
|
24
|
+
# - +category_manager+ -> the category manager responsible for managing the categories
|
25
|
+
# - +:facet_manager+ -> the facet manager responsible for managing the facets
|
26
26
|
#
|
27
27
|
# * *Returns* :
|
28
28
|
# - an instance of AboutYou::SDK::Factory::DefaultModelFactory
|
29
29
|
###
|
30
|
-
def initialize(
|
31
|
-
self.
|
30
|
+
def initialize(shop_api = nil)
|
31
|
+
self.shop_api = shop_api
|
32
32
|
end
|
33
|
-
|
34
|
-
def
|
35
|
-
self.
|
36
|
-
self.
|
37
|
-
AboutYou::SDK::Model::FacetGroupSet.
|
33
|
+
|
34
|
+
def initialize_managers(facet_manager, category_manager)
|
35
|
+
self.category_manager = category_manager
|
36
|
+
self.facet_manager = facet_manager
|
37
|
+
AboutYou::SDK::Model::FacetGroupSet.facet_manager = self.facet_manager
|
38
38
|
end
|
39
39
|
|
40
40
|
###
|
41
41
|
# sets the baseimage url for the image model
|
42
42
|
#
|
43
43
|
# * *Args* :
|
44
|
-
# - +
|
44
|
+
# - +base_url+ -> the url which should be used by the image model
|
45
45
|
###
|
46
|
-
def
|
47
|
-
AboutYou::SDK::Model::Image.
|
46
|
+
def base_image_url=(base_url)
|
47
|
+
AboutYou::SDK::Model::Image.base_url = base_url
|
48
48
|
end
|
49
49
|
|
50
50
|
###
|
51
51
|
# creates an autocomplete model
|
52
52
|
#
|
53
53
|
# * *Args* :
|
54
|
-
# - +
|
54
|
+
# - +json_object+ -> the api response in json format
|
55
55
|
# - +query+ -> the query sent to the api
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# * *Returns* :
|
58
58
|
# - an instance of AboutYou::SDK::Model::Autocomplete
|
59
59
|
###
|
60
|
-
def
|
61
|
-
AboutYou::SDK::Model::Autocomplete.
|
60
|
+
def create_autocomplete(json_object, _query)
|
61
|
+
AboutYou::SDK::Model::Autocomplete.create_from_json(json_object, self)
|
62
62
|
end
|
63
63
|
|
64
64
|
###
|
65
65
|
# creates a basket model
|
66
66
|
#
|
67
67
|
# * *Args* :
|
68
|
-
# - +
|
68
|
+
# - +json_object+ -> the api response in json format
|
69
69
|
# - +query+ -> the query sent to the api
|
70
|
-
#
|
70
|
+
#
|
71
71
|
# * *Returns* :
|
72
72
|
# - an instance of AboutYou::SDK::Model::Basket
|
73
73
|
###
|
74
|
-
def
|
75
|
-
AboutYou::SDK::Model::Basket.
|
74
|
+
def create_basket(json_object, _query)
|
75
|
+
AboutYou::SDK::Model::Basket.create_from_json(json_object, self)
|
76
76
|
end
|
77
77
|
|
78
78
|
###
|
79
79
|
# creates a basket item model
|
80
80
|
#
|
81
81
|
# * *Args* :
|
82
|
-
# - +
|
82
|
+
# - +json_object+ -> the api response in json format
|
83
83
|
# - +products+ -> the product models for which items should be created
|
84
|
-
#
|
84
|
+
#
|
85
85
|
# * *Returns* :
|
86
86
|
# - an instance of AboutYou::SDK::Model::BasketItem
|
87
87
|
###
|
88
|
-
def
|
89
|
-
AboutYou::SDK::Model::Basket::BasketItem.
|
88
|
+
def create_basket_item(json_object, products)
|
89
|
+
AboutYou::SDK::Model::Basket::BasketItem.create_from_json(
|
90
|
+
json_object,
|
91
|
+
products
|
92
|
+
)
|
90
93
|
end
|
91
94
|
|
92
95
|
###
|
93
96
|
# creates a basket set model
|
94
97
|
#
|
95
98
|
# * *Args* :
|
96
|
-
# - +
|
99
|
+
# - +json_object+ -> the api response in json format
|
97
100
|
# - +products+ -> the product models for which items should be created
|
98
|
-
#
|
101
|
+
#
|
99
102
|
# * *Returns* :
|
100
103
|
# - an instance of AboutYou::SDK::Model::BasketSet
|
101
104
|
###
|
102
|
-
def
|
103
|
-
AboutYou::SDK::Model::BasketSet
|
105
|
+
def create_basket_set(json_object, products)
|
106
|
+
AboutYou::SDK::Model::BasketSet.create_from_json(
|
107
|
+
json_object,
|
108
|
+
self,
|
109
|
+
products
|
110
|
+
)
|
104
111
|
end
|
105
112
|
|
106
113
|
###
|
107
114
|
# creates a basket setitem model
|
108
115
|
#
|
109
116
|
# * *Args* :
|
110
|
-
# - +
|
117
|
+
# - +json_object+ -> the api response in json format
|
111
118
|
# - +products+ -> the product models for which items should be created
|
112
|
-
#
|
119
|
+
#
|
113
120
|
# * *Returns* :
|
114
121
|
# - an instance of AboutYou::SDK::Model::BasketSetItem
|
115
122
|
###
|
116
|
-
def
|
117
|
-
AboutYou::SDK::Model::BasketSetItem
|
123
|
+
def create_basket_set_item(json_object, products)
|
124
|
+
AboutYou::SDK::Model::BasketSetItem.create_from_json(
|
125
|
+
json_object,
|
126
|
+
products
|
127
|
+
)
|
118
128
|
end
|
119
129
|
|
120
130
|
###
|
121
131
|
# creates a category model
|
122
132
|
#
|
123
133
|
# * *Args* :
|
124
|
-
# - +
|
125
|
-
#
|
134
|
+
# - +json_object+ -> the api response in json format
|
135
|
+
#
|
126
136
|
# * *Returns* :
|
127
137
|
# - an instance of AboutYou::SDK::Model::Category
|
128
138
|
###
|
129
|
-
def
|
130
|
-
AboutYou::SDK::Model::Category.
|
139
|
+
def create_category(json_object)
|
140
|
+
AboutYou::SDK::Model::Category.create_from_json(
|
141
|
+
json_object,
|
142
|
+
category_manager
|
143
|
+
)
|
131
144
|
end
|
132
145
|
|
133
146
|
###
|
@@ -135,27 +148,27 @@ module AboutYou
|
|
135
148
|
#
|
136
149
|
# * *Args* :
|
137
150
|
# - +jsonArray+ -> an Array containing the api response
|
138
|
-
# - +
|
139
|
-
#
|
151
|
+
# - +_query+ -> the _query sent to the api
|
152
|
+
#
|
140
153
|
# * *Returns* :
|
141
154
|
# - an instance of AboutYou::SDK::Model::CategoryTree
|
142
155
|
###
|
143
|
-
def
|
144
|
-
|
145
|
-
AboutYou::SDK::Model::CategoryTree.new(
|
156
|
+
def create_category_tree(json_array, _query)
|
157
|
+
initialize_category_manager(json_array)
|
158
|
+
AboutYou::SDK::Model::CategoryTree.new(category_manager)
|
146
159
|
end
|
147
160
|
|
148
161
|
###
|
149
162
|
# creates a facet model
|
150
163
|
#
|
151
164
|
# * *Args* :
|
152
|
-
# - +
|
153
|
-
#
|
165
|
+
# - +json_object+ -> the api response in json format
|
166
|
+
#
|
154
167
|
# * *Returns* :
|
155
168
|
# - an instance of AboutYou::SDK::Model::Facet
|
156
169
|
###
|
157
|
-
def
|
158
|
-
AboutYou::SDK::Model::Facet.
|
170
|
+
def create_facet(json_object)
|
171
|
+
AboutYou::SDK::Model::Facet.create_from_json(json_object)
|
159
172
|
end
|
160
173
|
|
161
174
|
###
|
@@ -164,15 +177,15 @@ module AboutYou
|
|
164
177
|
#
|
165
178
|
# * *Args* :
|
166
179
|
# - +jsonArray+ -> an Array containing the api response
|
167
|
-
#
|
180
|
+
#
|
168
181
|
# * *Returns* :
|
169
182
|
# - a Hash containing pairs of facetKey => AboutYou::SDK::Model::Facet
|
170
183
|
###
|
171
|
-
def
|
184
|
+
def create_facet_list(json_array, _query)
|
172
185
|
facets = {}
|
173
|
-
|
174
|
-
facet =
|
175
|
-
key = facet.
|
186
|
+
json_array.each do |json_facet|
|
187
|
+
facet = create_facet(json_facet)
|
188
|
+
key = facet.unique_key
|
176
189
|
facets[key] = facet
|
177
190
|
end
|
178
191
|
|
@@ -184,142 +197,151 @@ module AboutYou
|
|
184
197
|
# facetKey => AboutYou::SDK::Model::Facet
|
185
198
|
#
|
186
199
|
# * *Args* :
|
187
|
-
# - +
|
200
|
+
# - +json_object+ -> the api response in json format
|
188
201
|
# - +query+ -> the query sent to the api
|
189
|
-
#
|
202
|
+
#
|
190
203
|
# * *Returns* :
|
191
204
|
# - a Hash containing pairs of facetKey => AboutYou::SDK::Model::Facet
|
192
205
|
###
|
193
|
-
def
|
194
|
-
|
206
|
+
def create_facets_list(json_object, query = nil)
|
207
|
+
create_facet_list(json_object['facet'], query)
|
195
208
|
end
|
196
|
-
|
197
209
|
|
198
210
|
###
|
199
211
|
# creates a Hash containing one or multiple pairs of
|
200
212
|
# group_id => instance of AboutYou::SDK::Model::FacetCounts
|
201
213
|
#
|
202
214
|
# * *Args* :
|
203
|
-
# - +
|
204
|
-
#
|
215
|
+
# - +json_object+ -> the api response in json format
|
216
|
+
#
|
205
217
|
# * *Returns* :
|
206
218
|
# - a Hash containing pairs of group_id => instance of AboutYou::SDK::Model::FacetCounts
|
207
219
|
###
|
208
|
-
def
|
209
|
-
|
220
|
+
def create_facets_counts(json_object)
|
221
|
+
facets_counts = {}
|
210
222
|
|
211
|
-
|
212
|
-
unless
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
groupId,
|
218
|
-
jsonResultFacet,
|
219
|
-
facetCounts
|
223
|
+
json_object['facets'].each do |group_id, json_result_facet|
|
224
|
+
next unless group_id[/\d/]
|
225
|
+
|
226
|
+
facet_counts = term_facets(
|
227
|
+
group_id,
|
228
|
+
json_result_facet['terms']
|
220
229
|
)
|
230
|
+
facets_counts[group_id] =
|
231
|
+
AboutYou::SDK::Model::FacetCounts.create_from_json(
|
232
|
+
group_id,
|
233
|
+
json_result_facet,
|
234
|
+
facet_counts
|
235
|
+
)
|
221
236
|
end
|
222
237
|
|
223
|
-
|
238
|
+
facets_counts
|
224
239
|
end
|
225
|
-
|
240
|
+
|
226
241
|
###
|
227
242
|
# creates an Array containing one or multiple instances of
|
228
243
|
# AboutYou::SDK::Model::FacetCount
|
229
244
|
#
|
230
245
|
# * *Args* :
|
231
|
-
# - +
|
246
|
+
# - +group_id+ -> the group id of the facets
|
232
247
|
# - +jsonTerms+ -> the single facet terms in json format
|
233
|
-
#
|
248
|
+
#
|
234
249
|
# * *Returns* :
|
235
250
|
# - an Array containing instances of AboutYou::SDK::Model::FacetCount
|
236
251
|
###
|
237
|
-
def
|
238
|
-
|
239
|
-
|
240
|
-
id = Integer(
|
241
|
-
facet =
|
242
|
-
unless facet
|
243
|
-
|
244
|
-
end
|
252
|
+
def term_facets(group_id, json_terms)
|
253
|
+
facet_counts = []
|
254
|
+
json_terms.each do |json_term|
|
255
|
+
id = Integer(json_term['term'])
|
256
|
+
facet = facet_manager.facet(group_id, id)
|
257
|
+
next unless facet
|
258
|
+
|
245
259
|
# TODO: Handle error, write test
|
246
|
-
|
260
|
+
facet_counts.push(AboutYou::SDK::Model::FacetCount.new(
|
261
|
+
facet,
|
262
|
+
json_term['count']
|
263
|
+
)
|
264
|
+
)
|
247
265
|
end
|
248
266
|
|
249
|
-
|
250
|
-
end
|
251
|
-
|
267
|
+
facet_counts
|
268
|
+
end
|
269
|
+
|
252
270
|
###
|
253
271
|
# creates an Array containing all facet types available
|
254
272
|
#
|
255
273
|
# * *Args* :
|
256
274
|
# - +jsonArray+ -> an Array containing the api response
|
257
|
-
# - +
|
258
|
-
#
|
275
|
+
# - +_query+ -> the _query sent to the api
|
276
|
+
#
|
259
277
|
# * *Returns* :
|
260
278
|
# - an Array containing all facet types available
|
261
279
|
###
|
262
|
-
def
|
263
|
-
|
280
|
+
def create_facet_types(json_array, _query)
|
281
|
+
json_array
|
264
282
|
end
|
265
283
|
|
266
284
|
###
|
267
285
|
# creates an image model
|
268
286
|
#
|
269
287
|
# * *Args* :
|
270
|
-
# - +
|
271
|
-
#
|
288
|
+
# - +json_object+ -> the api response in json format
|
289
|
+
#
|
272
290
|
# * *Returns* :
|
273
291
|
# - an instance of AboutYou::SDK::Model::Image
|
274
292
|
###
|
275
|
-
def
|
276
|
-
AboutYou::SDK::Model::Image.
|
293
|
+
def create_image(json_object)
|
294
|
+
AboutYou::SDK::Model::Image.create_from_json(json_object)
|
277
295
|
end
|
278
296
|
|
279
297
|
###
|
280
298
|
# creates a product model
|
281
299
|
#
|
282
300
|
# * *Args* :
|
283
|
-
# - +
|
284
|
-
#
|
301
|
+
# - +json_object+ -> the api response in json format
|
302
|
+
#
|
285
303
|
# * *Returns* :
|
286
304
|
# - an instance of AboutYou::SDK::Model::Product
|
287
305
|
###
|
288
|
-
def
|
289
|
-
AboutYou::SDK::Model::Product.
|
306
|
+
def create_product(json_object)
|
307
|
+
AboutYou::SDK::Model::Product.create_from_json(
|
308
|
+
json_object,
|
309
|
+
self,
|
310
|
+
shop_api.app_id
|
311
|
+
)
|
290
312
|
end
|
291
313
|
|
292
314
|
###
|
293
315
|
# creates a variants result model
|
294
316
|
#
|
295
317
|
# * *Args* :
|
296
|
-
# - +
|
297
|
-
# - +
|
298
|
-
#
|
318
|
+
# - +json_object+ -> the api response in json format
|
319
|
+
# - +_query+ -> the _query sent to the api
|
320
|
+
#
|
299
321
|
# * *Returns* :
|
300
322
|
# - an instance of AboutYou::SDK::Model::VariantsResult
|
301
323
|
###
|
302
|
-
def
|
324
|
+
def create_variants_result(json_object, _query)
|
303
325
|
variants = {}
|
304
326
|
errors = []
|
305
|
-
|
306
|
-
|
327
|
+
product_ids = []
|
328
|
+
product_search_result = false
|
307
329
|
|
308
|
-
|
309
|
-
if data[
|
330
|
+
json_object.each do |id, data|
|
331
|
+
if data['error_code']
|
310
332
|
errors.push(id)
|
311
333
|
else
|
312
|
-
variants[data[
|
313
|
-
|
334
|
+
variants[data['id']] = data['product_id']
|
335
|
+
product_ids.push(data['product_id'])
|
314
336
|
end
|
315
337
|
end
|
316
338
|
|
317
|
-
if
|
318
|
-
|
339
|
+
if product_ids.count > 0
|
340
|
+
product_ids = product_ids.uniq
|
319
341
|
# search products for valid variants
|
320
|
-
|
321
|
-
|
322
|
-
|
342
|
+
|
343
|
+
product_search_result = shop_api.fetch_products_by_ids(
|
344
|
+
product_ids, [
|
323
345
|
AboutYou::SDK::Criteria::ProductFields::ATTRIBUTES_MERGED,
|
324
346
|
AboutYou::SDK::Criteria::ProductFields::BRAND,
|
325
347
|
AboutYou::SDK::Criteria::ProductFields::CATEGORIES,
|
@@ -335,152 +357,173 @@ module AboutYou
|
|
335
357
|
]
|
336
358
|
)
|
337
359
|
end
|
338
|
-
|
339
|
-
AboutYou::SDK::Model::VariantsResult.create(
|
360
|
+
|
361
|
+
AboutYou::SDK::Model::VariantsResult.create(
|
362
|
+
variants,
|
363
|
+
errors,
|
364
|
+
product_search_result
|
365
|
+
)
|
340
366
|
end
|
341
367
|
|
342
368
|
###
|
343
369
|
# creates a single product model
|
344
|
-
#
|
370
|
+
#
|
345
371
|
# * *Args* :
|
346
|
-
# - +
|
347
|
-
#
|
372
|
+
# - +json_object+ -> the api response in json format
|
373
|
+
#
|
348
374
|
# * *Returns* :
|
349
375
|
# - an instance of AboutYou::SDK::Model::Product
|
350
376
|
###
|
351
|
-
def
|
352
|
-
|
377
|
+
def create_single_product(json_object)
|
378
|
+
createProduct(json_object)
|
353
379
|
end
|
354
380
|
|
355
381
|
###
|
356
382
|
# creates a products result model
|
357
|
-
#
|
383
|
+
#
|
358
384
|
# * *Args* :
|
359
|
-
# - +
|
360
|
-
# - +
|
361
|
-
#
|
385
|
+
# - +json_object+ -> the api response in json format
|
386
|
+
# - +_query+ -> the _query sent to the api
|
387
|
+
#
|
362
388
|
# * *Returns* :
|
363
389
|
# - an instance of AboutYou::SDK::Model::ProductsResult
|
364
390
|
###
|
365
|
-
def
|
366
|
-
AboutYou::SDK::Model::ProductsResult.
|
391
|
+
def create_products_result(json_object, _query)
|
392
|
+
AboutYou::SDK::Model::ProductsResult.create_from_json(
|
393
|
+
json_object,
|
394
|
+
self
|
395
|
+
)
|
367
396
|
end
|
368
397
|
|
369
398
|
###
|
370
399
|
# creates a products eanresult model
|
371
|
-
#
|
400
|
+
#
|
372
401
|
# * *Args* :
|
373
|
-
# - +
|
374
|
-
# - +
|
375
|
-
#
|
402
|
+
# - +json_object+ -> the api response in json format
|
403
|
+
# - +_query+ -> the _query sent to the api
|
404
|
+
#
|
376
405
|
# * *Returns* :
|
377
406
|
# - an instance of AboutYou::SDK::Model::ProductsEanResult
|
378
407
|
###
|
379
|
-
def
|
380
|
-
AboutYou::SDK::Model::ProductsEansResult.
|
408
|
+
def create_products_ean_result(json_object, _query)
|
409
|
+
AboutYou::SDK::Model::ProductsEansResult.create_from_json(
|
410
|
+
json_object,
|
411
|
+
self
|
412
|
+
)
|
381
413
|
end
|
382
414
|
|
383
415
|
###
|
384
416
|
# creates a product searchresult model
|
385
|
-
#
|
417
|
+
#
|
386
418
|
# * *Args* :
|
387
|
-
# - +
|
388
|
-
# - +
|
389
|
-
#
|
419
|
+
# - +json_object+ -> the api response in json format
|
420
|
+
# - +_query+ -> the _query sent to the api
|
421
|
+
#
|
390
422
|
# * *Returns* :
|
391
423
|
# - an instance of AboutYou::SDK::Model::ProductSearchResult
|
392
424
|
###
|
393
|
-
def
|
394
|
-
|
425
|
+
def create_product_search_result(json_object, _query)
|
426
|
+
AboutYou::SDK::Model::ProductSearchResult.create_from_json(
|
427
|
+
json_object,
|
428
|
+
self
|
429
|
+
)
|
395
430
|
end
|
396
431
|
|
397
432
|
###
|
398
433
|
# creates a categories result model
|
399
|
-
#
|
434
|
+
#
|
400
435
|
# * *Args* :
|
401
|
-
# - +
|
436
|
+
# - +json_object+ -> the api response in json format
|
402
437
|
# - +query+ -> the query sent to the api
|
403
|
-
#
|
438
|
+
#
|
404
439
|
# * *Returns* :
|
405
440
|
# - an instance of AboutYou::SDK::Model::CategoriesResult
|
406
441
|
###
|
407
|
-
def
|
408
|
-
AboutYou::SDK::Model::CategoriesResult.
|
442
|
+
def create_categories_result(json_object, query)
|
443
|
+
AboutYou::SDK::Model::CategoriesResult.create_from_json(
|
444
|
+
json_object,
|
445
|
+
query['ids'],
|
446
|
+
self
|
447
|
+
)
|
409
448
|
end
|
410
449
|
|
411
450
|
###
|
412
451
|
# creates an Array containing suggests
|
413
|
-
#
|
452
|
+
#
|
414
453
|
# * *Args* :
|
415
454
|
# - +jsonArray+ -> an Array with the api response
|
416
|
-
# - +
|
417
|
-
#
|
455
|
+
# - +_query+ -> the _query sent to the api
|
456
|
+
#
|
418
457
|
# * *Returns* :
|
419
458
|
# - an Array containing suggests
|
420
459
|
###
|
421
|
-
def
|
460
|
+
def create_suggest(jsonArray, _query)
|
422
461
|
jsonArray
|
423
462
|
end
|
424
463
|
|
425
464
|
###
|
426
465
|
# creates a variant model
|
427
|
-
#
|
466
|
+
#
|
428
467
|
# * *Args* :
|
429
|
-
# - +
|
468
|
+
# - +json_object+ -> the api response in json format
|
430
469
|
# - +product+ -> the product of the variant which should be created
|
431
|
-
#
|
470
|
+
#
|
432
471
|
# * *Returns* :
|
433
472
|
# - an instance of AboutYou::SDK::Model::Variant
|
434
473
|
###
|
435
|
-
def
|
436
|
-
AboutYou::SDK::Model::Variant.
|
474
|
+
def create_variant(json_object, product)
|
475
|
+
AboutYou::SDK::Model::Variant.create_from_json(
|
476
|
+
json_object,
|
477
|
+
self,
|
478
|
+
product
|
479
|
+
)
|
437
480
|
end
|
438
481
|
|
439
482
|
###
|
440
483
|
# creates an order model
|
441
|
-
#
|
484
|
+
#
|
442
485
|
# * *Args* :
|
443
|
-
# - +
|
444
|
-
# - +
|
445
|
-
#
|
486
|
+
# - +json_object+ -> the api response in json format
|
487
|
+
# - +_query+ -> the _query sent to the api
|
488
|
+
#
|
446
489
|
# * *Returns* :
|
447
490
|
# - an instance of AboutYou::SDK::Model::Order
|
448
491
|
###
|
449
|
-
def
|
450
|
-
basket =
|
492
|
+
def create_order(json_object, _query)
|
493
|
+
basket = create_basket(json_object['basket'])
|
451
494
|
|
452
|
-
AboutYou::SDK::Model::Order.new(
|
495
|
+
AboutYou::SDK::Model::Order.new(json_object['order_id'], basket)
|
453
496
|
end
|
454
497
|
|
455
498
|
###
|
456
499
|
# creates an initiate order model
|
457
|
-
#
|
500
|
+
#
|
458
501
|
# * *Args* :
|
459
|
-
# - +
|
460
|
-
# - +
|
461
|
-
#
|
502
|
+
# - +json_object+ -> the api response in json format
|
503
|
+
# - +_query+ -> the _query sent to the api
|
504
|
+
#
|
462
505
|
# * *Returns* :
|
463
506
|
# - an instance of AboutYou::SDK::Model::InitiateOrder
|
464
507
|
###
|
465
|
-
def
|
466
|
-
AboutYou::SDK::Model::InitiateOrder.
|
508
|
+
def initiate_order(json_object, _query)
|
509
|
+
AboutYou::SDK::Model::InitiateOrder.create_from_json(json_object)
|
467
510
|
end
|
468
511
|
|
469
512
|
###
|
470
513
|
# creates a Has containing one or multiple pairs of
|
471
514
|
# app_id => instance of AboutYou::SDK::Model::App
|
472
|
-
#
|
515
|
+
#
|
473
516
|
# * *Args* :
|
474
|
-
# - +
|
475
|
-
# - +
|
476
|
-
#
|
517
|
+
# - +json_object+ -> the api response in json format
|
518
|
+
# - +_query+ -> the _query sent to the api
|
519
|
+
#
|
477
520
|
# * *Returns* :
|
478
521
|
# - a Hash containing pairs of app_id => instance of AboutYou::SDK::Model::App
|
479
522
|
###
|
480
|
-
def
|
523
|
+
def create_child_apps(json_object, _query)
|
481
524
|
apps = {}
|
482
|
-
|
483
|
-
app =
|
525
|
+
json_object['child_apps'].each do |json_app|
|
526
|
+
app = create_app(json_app)
|
484
527
|
apps[app.id] = app
|
485
528
|
end
|
486
529
|
|
@@ -489,112 +532,112 @@ module AboutYou
|
|
489
532
|
|
490
533
|
###
|
491
534
|
# creates an app model
|
492
|
-
#
|
535
|
+
#
|
493
536
|
# * *Args* :
|
494
|
-
# - +
|
495
|
-
#
|
537
|
+
# - +json_object+ -> the api response in json format
|
538
|
+
#
|
496
539
|
# * *Returns* :
|
497
540
|
# - an instance of AboutYou::SDK::Model::App
|
498
541
|
###
|
499
|
-
def
|
500
|
-
AboutYou::SDK::Model::App.
|
542
|
+
def create_app(json_object)
|
543
|
+
AboutYou::SDK::Model::App.create_from_json(json_object)
|
501
544
|
end
|
502
545
|
|
503
546
|
###
|
504
547
|
# this methods initiates the category manager
|
505
|
-
#
|
548
|
+
#
|
506
549
|
# * *Args* :
|
507
|
-
# - +
|
550
|
+
# - +json_object+ -> the api response in json format
|
508
551
|
###
|
509
|
-
def
|
510
|
-
|
552
|
+
def initialize_category_manager(json_object)
|
553
|
+
category_manager.parse_json(json_object, self)
|
511
554
|
end
|
512
|
-
|
555
|
+
|
513
556
|
###
|
514
557
|
# this methods updates the facet manager
|
515
|
-
#
|
558
|
+
#
|
516
559
|
# * *Args* :
|
517
|
-
# - +
|
560
|
+
# - +json_object+ -> the api response in json format
|
518
561
|
# - +query+ -> the query sent to the api
|
519
562
|
###
|
520
|
-
def
|
521
|
-
|
563
|
+
def update_facet_manager(json_object, query)
|
564
|
+
facet_manager.parse_json(json_object, self, query)
|
522
565
|
end
|
523
566
|
|
524
567
|
###
|
525
568
|
# this method creates a price range model
|
526
|
-
#
|
569
|
+
#
|
527
570
|
# * *Args* :
|
528
|
-
# - +
|
529
|
-
#
|
571
|
+
# - +json_object+ -> the api response in json format
|
572
|
+
#
|
530
573
|
# * *Returns* :
|
531
574
|
# - an Array containing instances of AboutYou::SDK::Model::PriceRange
|
532
575
|
###
|
533
|
-
def
|
534
|
-
|
535
|
-
|
536
|
-
|
576
|
+
def create_price_ranges(json_object)
|
577
|
+
price_ranges = []
|
578
|
+
json_object['ranges'].each do |range|
|
579
|
+
price_ranges.push(
|
580
|
+
AboutYou::SDK::Model::PriceRange.create_from_json(
|
581
|
+
range
|
582
|
+
)
|
583
|
+
)
|
537
584
|
end
|
538
|
-
|
585
|
+
|
586
|
+
price_ranges
|
539
587
|
end
|
540
588
|
|
541
589
|
###
|
542
590
|
# this method creates a sale counts model
|
543
|
-
#
|
591
|
+
#
|
544
592
|
# * *Args* :
|
545
|
-
# - +
|
546
|
-
#
|
593
|
+
# - +json_object+ -> the api response in json format
|
594
|
+
#
|
547
595
|
# * *Returns* :
|
548
596
|
# - an instance of AboutYou::SDK::Model::SaleCounts
|
549
597
|
###
|
550
|
-
def
|
551
|
-
AboutYou::SDK::Model::SaleCounts.
|
598
|
+
def create_sale_facet(json_object)
|
599
|
+
AboutYou::SDK::Model::SaleCounts.create_from_json(json_object)
|
552
600
|
end
|
553
601
|
|
554
602
|
###
|
555
603
|
# this method creates the facets for given categories
|
556
|
-
#
|
604
|
+
#
|
557
605
|
# * *Args* :
|
558
606
|
# - +jsonArray+ -> an Array containing the Api response
|
559
|
-
#
|
607
|
+
#
|
560
608
|
# * *Returns* :
|
561
609
|
# - a Hash containing pairs of category_id => category
|
562
610
|
###
|
563
|
-
def
|
564
|
-
|
611
|
+
def create_categories_facets(json_array)
|
612
|
+
category_manager = self.category_manager
|
565
613
|
|
566
|
-
|
567
|
-
|
568
|
-
id = item[
|
569
|
-
category =
|
614
|
+
flatten_categories = {}
|
615
|
+
json_array.each do |item|
|
616
|
+
id = item['term']
|
617
|
+
category = category_manager.category(id)
|
570
618
|
next unless category
|
571
619
|
|
572
|
-
category.
|
573
|
-
|
620
|
+
category.product_count = item['count']
|
621
|
+
flatten_categories[id] = category
|
574
622
|
end
|
575
623
|
|
576
|
-
|
624
|
+
flatten_categories
|
577
625
|
end
|
578
|
-
|
626
|
+
|
579
627
|
###
|
580
628
|
# this method tries to handle errors which are received from the api
|
581
|
-
#
|
629
|
+
#
|
582
630
|
# * *Args* :
|
583
631
|
# - +json+ -> the api response in json format
|
584
632
|
# - +resultKey+ -> the result key received from the api
|
585
633
|
# - +isMultiRequest+ -> determines whether the api-request was multiquery or not
|
586
634
|
###
|
587
|
-
def
|
588
|
-
if
|
589
|
-
return false
|
590
|
-
end
|
635
|
+
def pre_handle_error(json, result_key, is_multi_request)
|
636
|
+
return false if result_key == 'basket' && json['order_lines']
|
591
637
|
|
592
|
-
|
593
|
-
raise 'ResultError!' + json
|
594
|
-
end
|
595
|
-
raise 'ResultError!' + json
|
638
|
+
fail 'ResultError!' + json + is_multi_request
|
596
639
|
end
|
597
640
|
end
|
598
641
|
end
|
599
|
-
end
|
600
|
-
end
|
642
|
+
end
|
643
|
+
end
|