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/ay.rb
ADDED
@@ -0,0 +1,566 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'require_all'
|
4
|
+
|
5
|
+
require_rel 'AboutYou'
|
6
|
+
|
7
|
+
###
|
8
|
+
# Provides access to the Collins Frontend Platform.
|
9
|
+
# All the public methods cover a single API query.
|
10
|
+
#
|
11
|
+
# author:: Collins GmbH & Co KG
|
12
|
+
###
|
13
|
+
class AY
|
14
|
+
# url for staging
|
15
|
+
IMAGE_URL_STAGE = 'http://mndb.staging.aboutyou.de/mmdb/file'
|
16
|
+
# url for the sandbox
|
17
|
+
IMAGE_URL_SANDBOX = 'http://mndb.sandbox.aboutyou.de/mmdb/file'
|
18
|
+
# url for live
|
19
|
+
IMAGE_URL_LIVE = 'http://cdn.aboutyou.de/file'
|
20
|
+
|
21
|
+
# the client which performs the api calls
|
22
|
+
attr_accessor :about_you_client
|
23
|
+
# the app id of the app which should be represented by an instance of AY
|
24
|
+
attr_accessor :app_id
|
25
|
+
# the authentication token from dev-center for the app id
|
26
|
+
attr_accessor :app_password
|
27
|
+
# the endpoint used for api calls
|
28
|
+
attr_accessor :api_endpoint
|
29
|
+
# the environment which should be used by the app
|
30
|
+
attr_accessor :environment
|
31
|
+
# a logger template
|
32
|
+
attr_accessor :logger
|
33
|
+
# the model factory builds model objects based on the api response
|
34
|
+
attr_accessor :model_factory_instance
|
35
|
+
# the url for getting images
|
36
|
+
attr_accessor :base_image_url
|
37
|
+
# the session id from a user using this app
|
38
|
+
attr_accessor :session_id
|
39
|
+
# the CacheServer
|
40
|
+
attr_accessor :cache
|
41
|
+
|
42
|
+
###
|
43
|
+
# the Constructor for the AY class
|
44
|
+
#
|
45
|
+
# * *Args* :
|
46
|
+
# - +app_id+ -> The App-Id of the App
|
47
|
+
# - +app_password+ -> The Auth-Token of the App
|
48
|
+
# - +session_id+ -> A String containing the sessionId of the User
|
49
|
+
# - +api_endpoint+ -> Can be either live or staging
|
50
|
+
# - +resultFactory+ -> If nil it will use the DefaultModelFactory with the DefaultFacetManager
|
51
|
+
# - +logger+ -> Logger-Template
|
52
|
+
# - +cache+ -> The preferred Caching-Strategy
|
53
|
+
#
|
54
|
+
# * *Returns* :
|
55
|
+
# - Instance of AY
|
56
|
+
###
|
57
|
+
def initialize(
|
58
|
+
app_id,
|
59
|
+
app_password,
|
60
|
+
session_id = 'SESSION_ID',
|
61
|
+
cache = nil,
|
62
|
+
api_endpoint = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE,
|
63
|
+
result_factory = nil,
|
64
|
+
logger = nil
|
65
|
+
)
|
66
|
+
|
67
|
+
self.session_id = session_id
|
68
|
+
self.app_id = app_id
|
69
|
+
self.app_password = app_password
|
70
|
+
self.about_you_client = AboutYou::SDK::Client.new(
|
71
|
+
app_id,
|
72
|
+
app_password,
|
73
|
+
api_endpoint,
|
74
|
+
logger
|
75
|
+
)
|
76
|
+
|
77
|
+
self.cache = cache
|
78
|
+
if result_factory
|
79
|
+
self.model_factory_instance = result_factory
|
80
|
+
else
|
81
|
+
init_default_factory(self.cache)
|
82
|
+
end
|
83
|
+
|
84
|
+
if api_endpoint == AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
|
85
|
+
self.base_image_url = (IMAGE_URL_STAGE)
|
86
|
+
self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
|
87
|
+
elsif api_endpoint == AboutYou::SDK::Constants::API_ENVIRONMENT_SANDBOX
|
88
|
+
self.base_image_url = (IMAGE_URL_SANDBOX)
|
89
|
+
self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_SANDBOX
|
90
|
+
elsif api_endpoint == AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE
|
91
|
+
self.base_image_url = (IMAGE_URL_LIVE)
|
92
|
+
self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
###
|
97
|
+
# Adds a single item into the basket.
|
98
|
+
# You can specify an amount. Please mind, that an amount > 1 will result
|
99
|
+
# in #amount basket positions.
|
100
|
+
# So if you read out the basket again later, it's your job to
|
101
|
+
# merge the positions again.
|
102
|
+
#
|
103
|
+
# * *Args* :
|
104
|
+
# - +session_id+ -> A String containing the sessionId of the User
|
105
|
+
# - +variant_id+ -> Id of the Variant which should be added to the basket
|
106
|
+
# - +amount+ -> The Amount of the Item which should be added to the basket
|
107
|
+
#
|
108
|
+
# * *Returns* :
|
109
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
110
|
+
###
|
111
|
+
def add_item_to_basket(session_id, variant_id, amount = 1)
|
112
|
+
basket = AboutYou::SDK::Model::Basket.new
|
113
|
+
|
114
|
+
unless variant_id.is_a?(Long)
|
115
|
+
if variant_id.is_a?(String) && variant_id[/\d/]
|
116
|
+
variant_id = Integer(variant_id)
|
117
|
+
else
|
118
|
+
fail 'the variant id must be an integer or string with digits'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
amount.times do
|
123
|
+
basket.update_item(AboutYou::SDK::Model::Basket::BasketItem.new(
|
124
|
+
generate_basket_item_id,
|
125
|
+
variant_id
|
126
|
+
))
|
127
|
+
end
|
128
|
+
|
129
|
+
update_basket(session_id, basket)
|
130
|
+
end
|
131
|
+
|
132
|
+
###
|
133
|
+
# Method to create a unique item id for items in basket
|
134
|
+
#
|
135
|
+
# * *Args* :
|
136
|
+
#
|
137
|
+
# * *Returns* :
|
138
|
+
# - an Intger
|
139
|
+
###
|
140
|
+
def generate_basket_item_id
|
141
|
+
'i_' + SecureRandom.uuid
|
142
|
+
end
|
143
|
+
|
144
|
+
###
|
145
|
+
# Method to remove items from basket
|
146
|
+
#
|
147
|
+
# * *Args* :
|
148
|
+
# - +session_id+ -> A String containing the sessionId of the User
|
149
|
+
# - +itemIds+ -> an Array of Item ids which should be removed
|
150
|
+
#
|
151
|
+
# * *Returns* :
|
152
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
153
|
+
###
|
154
|
+
def remove_items_from_basket(session_id, item_ids)
|
155
|
+
basket = AboutYou::SDK::Model::Basket.new
|
156
|
+
basket.delete_items(item_ids)
|
157
|
+
|
158
|
+
update_basket(session_id, basket)
|
159
|
+
end
|
160
|
+
|
161
|
+
###
|
162
|
+
# Method to update a given basket
|
163
|
+
#
|
164
|
+
# * *Args* :
|
165
|
+
# - +session_id+ -> A String containing the sessionId of the User
|
166
|
+
# - +basket+ -> an Instance of a basket
|
167
|
+
#
|
168
|
+
# * *Returns* :
|
169
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
170
|
+
###
|
171
|
+
def update_basket(session_id, basket)
|
172
|
+
query.update_basket(session_id, basket).execute_single
|
173
|
+
end
|
174
|
+
|
175
|
+
###
|
176
|
+
# Method to initiaite the order
|
177
|
+
#
|
178
|
+
# * *Args* :
|
179
|
+
# - +session_id+ -> A String containing the sessionId of the User
|
180
|
+
# - +successUrl+ -> callback URL if the order was OK
|
181
|
+
# - +cancelUrl+ -> callback URL if the order was canceled [optional]
|
182
|
+
# - +errorUrl+ -> callback URL if the order had any exceptions [optional]
|
183
|
+
#
|
184
|
+
# * *Returns* :
|
185
|
+
# - Instance of AboutYou::SDK::Model::InitiateOrder
|
186
|
+
###
|
187
|
+
def initiate_order(session_id, success_url, cancel_url = nil, error_url = nil)
|
188
|
+
query.initiate_order(
|
189
|
+
session_id,
|
190
|
+
success_url,
|
191
|
+
cancel_url,
|
192
|
+
error_url
|
193
|
+
).execute_single
|
194
|
+
end
|
195
|
+
|
196
|
+
###
|
197
|
+
# Returns the result of an auto completion API request.
|
198
|
+
# Auto completion searches for products and categories by
|
199
|
+
# a given prefix (searchword).
|
200
|
+
#
|
201
|
+
# * *Args* :
|
202
|
+
# - +searchword+ -> The prefix search word to search for
|
203
|
+
# - +limit+ -> Maximum number of results [optional]
|
204
|
+
# - +types+ -> Array of types to search for [optional]
|
205
|
+
#
|
206
|
+
# * *Returns* :
|
207
|
+
# - Instance of AboutYou::SDK::Model::Automcomplete
|
208
|
+
###
|
209
|
+
def fetch_autocomplete(
|
210
|
+
searchword,
|
211
|
+
limit = 50,
|
212
|
+
types = [
|
213
|
+
AboutYou::SDK::Constants::TYPE_PRODUCTS,
|
214
|
+
AboutYou::SDK::Constants::TYPE_CATEGORIES
|
215
|
+
]
|
216
|
+
)
|
217
|
+
query.fetch_autocomplete(searchword, limit, types).execute_single
|
218
|
+
end
|
219
|
+
|
220
|
+
###
|
221
|
+
# Fetch the basket of the given session_id.
|
222
|
+
#
|
223
|
+
# * *Args* :
|
224
|
+
# - +session_id+ -> A String containing the sessionId of the User
|
225
|
+
#
|
226
|
+
# * *Returns* :
|
227
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
228
|
+
###
|
229
|
+
def fetch_basket(session_id)
|
230
|
+
query.fetch_basket(session_id).execute_single
|
231
|
+
end
|
232
|
+
|
233
|
+
###
|
234
|
+
# Returns the result of a category search API request.
|
235
|
+
# By passing one or several category ids it will return
|
236
|
+
# a result of the categories data.
|
237
|
+
#
|
238
|
+
# * *Args* :
|
239
|
+
# - +ids+ -> either a single category ID as integer or an array of IDs [optional]
|
240
|
+
#
|
241
|
+
# * *Returns* :
|
242
|
+
# - Instance of AboutYou::SDK::Model::CategoriesResult
|
243
|
+
###
|
244
|
+
def fetch_categories_by_ids(ids = nil)
|
245
|
+
# we allow to pass a single ID instead of an array
|
246
|
+
ids = Array(ids) if ids
|
247
|
+
|
248
|
+
AboutYou::SDK::Model::CategoriesResult.new(category_manager, ids)
|
249
|
+
end
|
250
|
+
|
251
|
+
###
|
252
|
+
# Fetches the Root Categories of the Category Tree
|
253
|
+
#
|
254
|
+
# * *Returns* :
|
255
|
+
# - Instance of AboutYou::SDK::Model::CategoryTree
|
256
|
+
###
|
257
|
+
def fetch_category_tree
|
258
|
+
AboutYou::SDK::Model::CategoryTree.new(category_manager)
|
259
|
+
end
|
260
|
+
|
261
|
+
###
|
262
|
+
# The Categories will be fetched automatically, if required by any other fetch method
|
263
|
+
#
|
264
|
+
# * *Args* :
|
265
|
+
# - +fetchIfEmpty+ -> defines whether to fetch if empty or not [optional]
|
266
|
+
#
|
267
|
+
# * *Returns* :
|
268
|
+
# - Instance of AboutYou::SDK::CategoryManager::DefaultCategoryManager
|
269
|
+
###
|
270
|
+
def category_manager(fetch_if_empty = true)
|
271
|
+
category_manager = model_factory.category_manager
|
272
|
+
|
273
|
+
if fetch_if_empty && category_manager.empty?
|
274
|
+
query.require_category_tree.execute_single
|
275
|
+
end
|
276
|
+
|
277
|
+
category_manager
|
278
|
+
end
|
279
|
+
|
280
|
+
###
|
281
|
+
# Fetches the products for specific ids
|
282
|
+
#
|
283
|
+
# * *Args* :
|
284
|
+
# - +ids+ -> Either a single id or an Array of ids which should be fetched
|
285
|
+
# - +fields+ -> Additional product fields which should be fetched for each product [optional]
|
286
|
+
#
|
287
|
+
# * *Returns* :
|
288
|
+
# - Instance of AboutYou::SDK::Model::ProductsResult
|
289
|
+
###
|
290
|
+
def fetch_products_by_ids(ids, fields = [])
|
291
|
+
# we allow to pass a single ID instead of an array
|
292
|
+
ids = Array(ids)
|
293
|
+
result = query.fetch_products_by_ids(ids, fields).execute_single
|
294
|
+
products_not_found = result.products_not_found
|
295
|
+
|
296
|
+
if !products_not_found.empty? && logger
|
297
|
+
logger.warning('products not found: appid=' + app_id +
|
298
|
+
' product ids=[' + products_not_found.join(',') + ']'
|
299
|
+
)
|
300
|
+
end
|
301
|
+
|
302
|
+
result
|
303
|
+
end
|
304
|
+
|
305
|
+
###
|
306
|
+
# Fetches variants for specific ids
|
307
|
+
#
|
308
|
+
# * *Args* :
|
309
|
+
# - +ids+ -> Either a single id or an Array of ids which should be fetched
|
310
|
+
#
|
311
|
+
# * *Returns* :
|
312
|
+
# - Instance of AboutYou::SDK::Model::VariantsResult
|
313
|
+
###
|
314
|
+
def fetch_variants_by_ids(ids)
|
315
|
+
# we allow to pass a single ID instead of an array
|
316
|
+
ids = Array(ids)
|
317
|
+
result = query.fetch_live_variant_by_ids(ids).execute_single
|
318
|
+
variants_not_found = result.variants_not_found
|
319
|
+
|
320
|
+
if result.variants_not_found? && logger
|
321
|
+
logger.warning('variants or products for variants not found: appid=' +
|
322
|
+
app_id + ' variant ids=[' + variants_not_found.join(',') + ']'
|
323
|
+
)
|
324
|
+
end
|
325
|
+
|
326
|
+
result
|
327
|
+
end
|
328
|
+
|
329
|
+
###
|
330
|
+
# Fetches products for specific eans
|
331
|
+
#
|
332
|
+
# * *Args* :
|
333
|
+
# - +eans+ -> Either a single ean or an Array of eans which should be fetched
|
334
|
+
# - +fields+ -> Additional product fields which should be fetched for each product [optional]
|
335
|
+
#
|
336
|
+
# * *Returns* :
|
337
|
+
# - Instance of AboutYou::SDK::Model::ProductsEanResult
|
338
|
+
###
|
339
|
+
def fetch_products_by_eans(eans, fields = [])
|
340
|
+
# we allow to pass a single ID instead of an array
|
341
|
+
eans = Array(eans)
|
342
|
+
|
343
|
+
query.fetch_products_by_eans(eans, fields).execute_single
|
344
|
+
end
|
345
|
+
|
346
|
+
###
|
347
|
+
# Fetches the response for a product search
|
348
|
+
#
|
349
|
+
# * *Args* :
|
350
|
+
# - +criteria+ -> Hash containing one or multiple search terms
|
351
|
+
#
|
352
|
+
# * *Returns* :
|
353
|
+
# - Instance of AboutYou::SDK::Model::ProductSearchResult
|
354
|
+
###
|
355
|
+
def fetch_product_search(criteria)
|
356
|
+
query.fetch_product_search(criteria).execute_single
|
357
|
+
end
|
358
|
+
|
359
|
+
###
|
360
|
+
# Fetch the facets of the given group_ids
|
361
|
+
#
|
362
|
+
# * *Args* :
|
363
|
+
# - +group_ids+ -> Array of group ids [optional]
|
364
|
+
#
|
365
|
+
# * *Returns* :
|
366
|
+
# - Instance of AboutYou::SDK::Model::Facet
|
367
|
+
###
|
368
|
+
def fetch_facets(group_ids = [])
|
369
|
+
if model_factory_instance.facet_manager.empty?
|
370
|
+
query.fetch_facets.execute_single
|
371
|
+
end
|
372
|
+
model_factory_instance.facet_manager.facets_by_group_ids(group_ids)
|
373
|
+
end
|
374
|
+
|
375
|
+
###
|
376
|
+
# Fetches all possible Facet types
|
377
|
+
#
|
378
|
+
# * *Returns* :
|
379
|
+
# - Array with all group ids
|
380
|
+
###
|
381
|
+
def fetch_facet_types
|
382
|
+
query.fetch_facet_types.execute_single
|
383
|
+
end
|
384
|
+
|
385
|
+
###
|
386
|
+
# fetches Order for specific id
|
387
|
+
#
|
388
|
+
# * *Args* :
|
389
|
+
# - +orderId+ -> The id for which an order should be returned
|
390
|
+
#
|
391
|
+
# * *Returns* :
|
392
|
+
# - Instance of AboutYou::SDK::Model::Order
|
393
|
+
###
|
394
|
+
def fetch_order(order_id)
|
395
|
+
query.fetch_order(order_id).execute_single
|
396
|
+
end
|
397
|
+
|
398
|
+
###
|
399
|
+
# Fetch single facets by id and group id
|
400
|
+
#
|
401
|
+
# * *Args* :
|
402
|
+
# - +params+ -> Hash containing 2 keys: "id", "group_id"
|
403
|
+
#
|
404
|
+
# * *Returns* :
|
405
|
+
# - AboutYou::SDK::Model::Facet
|
406
|
+
###
|
407
|
+
def fetch_facet(params)
|
408
|
+
query.fetch_facet(params).execute_single
|
409
|
+
end
|
410
|
+
|
411
|
+
###
|
412
|
+
# Returns the result of a suggest API request.
|
413
|
+
# Suggestions are words that are often searched together
|
414
|
+
# with the searchword you pass (e.g. "stretch" for "jeans").
|
415
|
+
#
|
416
|
+
# * *Args* :
|
417
|
+
# - +searchword+ -> The search string to search for
|
418
|
+
#
|
419
|
+
# * *Returns* :
|
420
|
+
# - an Array containing the suggestions
|
421
|
+
###
|
422
|
+
def fetch_suggest(searchword)
|
423
|
+
query.fetch_suggest(searchword).execute_single
|
424
|
+
end
|
425
|
+
|
426
|
+
###
|
427
|
+
# Returns the list of child apps
|
428
|
+
#
|
429
|
+
# * *returns* :
|
430
|
+
# - an Array containing all child Apps
|
431
|
+
###
|
432
|
+
def fetch_child_apps
|
433
|
+
query.fetch_child_apps.execute_single
|
434
|
+
end
|
435
|
+
|
436
|
+
###
|
437
|
+
# Method for getting the query
|
438
|
+
#
|
439
|
+
# * *Returns* :
|
440
|
+
# - an Instance of AboutYou::SDK::Query
|
441
|
+
###
|
442
|
+
def query
|
443
|
+
AboutYou::SDK::Query.new(about_you_client, model_factory)
|
444
|
+
end
|
445
|
+
|
446
|
+
###
|
447
|
+
# Method for getting the model factory. If no model factory is set it initializes the default one
|
448
|
+
#
|
449
|
+
# * *Returns* :
|
450
|
+
# - an Instance of AboutYou::SDK::Factory::DefaultModelFactory
|
451
|
+
###
|
452
|
+
def model_factory
|
453
|
+
init_default_factory unless model_factory_instance
|
454
|
+
|
455
|
+
model_factory_instance
|
456
|
+
end
|
457
|
+
|
458
|
+
###
|
459
|
+
# Method for getting the product search criteria base class, on which you can specify your criteria
|
460
|
+
#
|
461
|
+
# * *Args* :
|
462
|
+
# - +session_id+ -> a string containing the session id [optional]
|
463
|
+
#
|
464
|
+
# * *Returns* :
|
465
|
+
# - AboutYou::SDK::Criteria::ProductSearchCriteria
|
466
|
+
###
|
467
|
+
def product_search_criteria(session_id = nil)
|
468
|
+
session_id = self.session_id unless session_id
|
469
|
+
|
470
|
+
AboutYou::SDK::Criteria::ProductSearchCriteria.new(session_id)
|
471
|
+
end
|
472
|
+
|
473
|
+
###
|
474
|
+
# Returns the URL to the Collins JavaScript file for helper functions
|
475
|
+
# to add product variants into the basket of ABOUT YOU or auto-resizing
|
476
|
+
# the iframe. This URL may be changed in future, so please use this method instead
|
477
|
+
# of a hard coded URL into your HTML template.
|
478
|
+
#
|
479
|
+
# * *Returns* :
|
480
|
+
# - a string containing an url to the javascript file
|
481
|
+
###
|
482
|
+
def java_script_url
|
483
|
+
if environment == AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
|
484
|
+
'//devcenter-staging-www1.pub.collins.kg:81/appjs/' +
|
485
|
+
String(app_id) + '.js'
|
486
|
+
else
|
487
|
+
'//developer.aboutyou.de/appjs/' + String(app_id) + '.js'
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
###
|
492
|
+
# Returns a HTML script tag that loads the Collins JavaScript fie.
|
493
|
+
#
|
494
|
+
# * *Returns* :
|
495
|
+
# - a string containing an HTML script tag
|
496
|
+
###
|
497
|
+
def java_script_tag
|
498
|
+
'<script type="text/javascript" src="' + java_script_url + '"></script>'
|
499
|
+
end
|
500
|
+
|
501
|
+
###
|
502
|
+
# Setter-Method for the app-Credentials
|
503
|
+
#
|
504
|
+
# * *Args* :
|
505
|
+
# - +app_id+ -> the id of an app
|
506
|
+
# - +app_password+ -> the auth-token for the app
|
507
|
+
###
|
508
|
+
def app_credentials=(app_id, app_password)
|
509
|
+
self.app_id = app_id
|
510
|
+
self.app_password = app_password
|
511
|
+
about_you_client.app_id = app_id
|
512
|
+
about_you_client.app_password = app_password
|
513
|
+
end
|
514
|
+
|
515
|
+
###
|
516
|
+
# Setter-Method for the api endpoint
|
517
|
+
#
|
518
|
+
# * *Args* :
|
519
|
+
# - +api_endpoint+ -> the endpoint can be the string 'stage' or 'live', then the default endpoints will be used or an absolute url
|
520
|
+
###
|
521
|
+
def api_endpoint=(api_endpoint)
|
522
|
+
about_you_client.api_endpoint = api_endpoint
|
523
|
+
end
|
524
|
+
|
525
|
+
###
|
526
|
+
# Setter-Method for the base image url
|
527
|
+
#
|
528
|
+
# * *Args* :
|
529
|
+
# - +base_image_url+ -> nil will reset to the default url, false to get relative urls, otherwise the url prefix
|
530
|
+
###
|
531
|
+
def base_image_url=(base_image_url = nil)
|
532
|
+
if !base_image_url
|
533
|
+
@base_image_url = IMAGE_URL_LIVE
|
534
|
+
elsif base_image_url.is_a?(String)
|
535
|
+
@base_image_url = base_image_url.gsub(/[#{'/'}]+$/, '')
|
536
|
+
else
|
537
|
+
@base_image_url = ''
|
538
|
+
end
|
539
|
+
|
540
|
+
model_factory.base_image_url = @base_image_url
|
541
|
+
end
|
542
|
+
|
543
|
+
###
|
544
|
+
# initializes the default model factory
|
545
|
+
#
|
546
|
+
# * *Args* :
|
547
|
+
# - +cache+ -> an Instance of the used cache [optional]
|
548
|
+
###
|
549
|
+
def init_default_factory(cache = nil)
|
550
|
+
self.model_factory_instance = AboutYou::SDK::Factory::DefaultModelFactory.new(self)
|
551
|
+
|
552
|
+
model_factory_instance.initialize_managers(
|
553
|
+
AboutYou::SDK::Model::FacetManager::DefaultFacetManager.new(
|
554
|
+
cache,
|
555
|
+
app_id,
|
556
|
+
self
|
557
|
+
),
|
558
|
+
AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager.new(
|
559
|
+
cache,
|
560
|
+
app_id,
|
561
|
+
self
|
562
|
+
)
|
563
|
+
)
|
564
|
+
model_factory_instance.base_image_url = base_image_url
|
565
|
+
end
|
566
|
+
end
|