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
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWRiNTIyMzA5N2MxYjdhM2YyZThlMThmMWYxYTY3ODZlMDQ5MDI5Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTM5OGU3Yjk0NzU4NjFiNGQxZmYyZjdiMjE0MThmZjlkNzM0ZjUxZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWNhNTBkYWRhNjNjZWM1NjdjZWE4ZWMzNTg4MDc2YjM4M2IxYTI3MzhmNjli
|
10
|
+
YzA3N2Q4ZDkwMmEzZTcwM2EwNmI0YmUwOGFkZjVlYjc4MDlmMzE4ZjQ2ZmVh
|
11
|
+
N2U2N2IyNDM5ZWFiYWZiNTJkOTdjMjIwODI5MzI5NzMxMzRkZTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTIyNDgzNjkxYmU4NzlmZmU5ZGRkN2U3OWRlMTdlYTVlOGQ2ODgzMTZkYzMx
|
14
|
+
NmNhYmZjMGU2NjM2ZDg5NDA5YjZhZjRmZjc4NjIyY2E2ZDlmNDQyOTMwZDYw
|
15
|
+
ZGE0OTQwMjg5ZmEwMGU2N2VkODRkNWEwMTczNTJkYjk0MDk5YTI=
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module AboutYou
|
2
2
|
module SDK
|
3
3
|
module CacheProvider
|
4
|
-
|
5
4
|
###
|
6
5
|
# This class is used as an interface for cache operations.
|
7
6
|
# It is used when caching with Dalli.
|
@@ -10,23 +9,23 @@ module AboutYou
|
|
10
9
|
###
|
11
10
|
class Dalli
|
12
11
|
require 'dalli'
|
13
|
-
|
12
|
+
|
14
13
|
# an instance of the cache client.
|
15
14
|
attr_accessor :client
|
16
|
-
|
15
|
+
|
17
16
|
###
|
18
17
|
# the Constructor for the Dalli class
|
19
18
|
#
|
20
19
|
# * *Args* :
|
21
20
|
# - +client+ -> an instance of Dalli::Client
|
22
|
-
#
|
21
|
+
#
|
23
22
|
# * *Returns* :
|
24
23
|
# - Instance of AboutYou::SDK::CacheProvider::Dalli
|
25
24
|
###
|
26
25
|
def initialize(client)
|
27
26
|
self.client = client
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
###
|
31
30
|
# This method is used for setting new cache entries with Dalli.
|
32
31
|
#
|
@@ -34,53 +33,53 @@ module AboutYou
|
|
34
33
|
# - +key+ -> The key of the cache entry
|
35
34
|
# - +value+ -> The value of the cache entry
|
36
35
|
# - +duration+ -> the duration of the cache entry
|
37
|
-
#
|
36
|
+
#
|
38
37
|
# * *Returns* :
|
39
|
-
# - True/False determining whether the setting was
|
38
|
+
# - True/False determining whether the setting was successful of not
|
40
39
|
###
|
41
40
|
def set(key, value, duration)
|
42
|
-
|
41
|
+
client.set(key, value, duration)
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
###
|
46
45
|
# This method is used for getting cache entries with Dalli.
|
47
46
|
#
|
48
47
|
# * *Args* :
|
49
48
|
# - +key+ -> The key of the cache entry
|
50
|
-
#
|
49
|
+
#
|
51
50
|
# * *Returns* :
|
52
51
|
# - Either the value for the given key or nil if the key was not found
|
53
52
|
###
|
54
53
|
def get(key)
|
55
|
-
|
54
|
+
client.get(key)
|
56
55
|
end
|
57
|
-
|
56
|
+
|
58
57
|
###
|
59
58
|
# This method is used for deleting cache entries with Dalli.
|
60
59
|
#
|
61
60
|
# * *Args* :
|
62
61
|
# - +key+ -> The key of the cache entry
|
63
|
-
#
|
62
|
+
#
|
64
63
|
# * *Returns* :
|
65
|
-
# - True/False determining whether the deletion was
|
64
|
+
# - True/False determining whether the deletion was successful or not
|
66
65
|
###
|
67
66
|
def delete(key)
|
68
|
-
|
67
|
+
client.delete(key)
|
69
68
|
end
|
70
|
-
|
69
|
+
|
71
70
|
###
|
72
71
|
# This method is used for checking whether a cache entry exists or not with Dalli.
|
73
72
|
#
|
74
73
|
# * *Args* :
|
75
74
|
# - +key+ -> The key of the cache entry
|
76
|
-
#
|
75
|
+
#
|
77
76
|
# * *Returns* :
|
78
77
|
# - True/False determining whether the key exists in the cache or not
|
79
78
|
###
|
80
79
|
def exists(key)
|
81
|
-
|
80
|
+
!client.get(key).nil?
|
82
81
|
end
|
83
82
|
end
|
84
83
|
end
|
85
84
|
end
|
86
|
-
end
|
85
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module AboutYou
|
2
2
|
module SDK
|
3
3
|
module CacheProvider
|
4
|
-
|
5
4
|
###
|
6
5
|
# This class is used as an interface for cache operations.
|
7
6
|
# It is used when caching with Redis.
|
@@ -10,23 +9,23 @@ module AboutYou
|
|
10
9
|
###
|
11
10
|
class Redis
|
12
11
|
require 'redis'
|
13
|
-
|
12
|
+
|
14
13
|
# an instance of the cache client.
|
15
14
|
attr_accessor :client
|
16
|
-
|
15
|
+
|
17
16
|
###
|
18
17
|
# the Constructor for the Redis class
|
19
18
|
#
|
20
19
|
# * *Args* :
|
21
20
|
# - +client+ -> an instance of Redis
|
22
|
-
#
|
21
|
+
#
|
23
22
|
# * *Returns* :
|
24
23
|
# - Instance of AboutYou::SDK::CacheProvider::Redis
|
25
24
|
###
|
26
25
|
def initialize(client)
|
27
26
|
self.client = client
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
###
|
31
30
|
# This method is used for setting new cache entries with Redis.
|
32
31
|
#
|
@@ -34,55 +33,55 @@ module AboutYou
|
|
34
33
|
# - +key+ -> The key of the cache entry
|
35
34
|
# - +value+ -> The value of the cache entry
|
36
35
|
# - +duration+ -> the duration of the cache entry
|
37
|
-
#
|
36
|
+
#
|
38
37
|
# * *Returns* :
|
39
|
-
# - True/False determining whether the setting was
|
38
|
+
# - True/False determining whether the setting was successful of not
|
40
39
|
###
|
41
40
|
def set(key, value, duration)
|
42
41
|
value = value.to_json unless value.is_a?(String)
|
43
|
-
|
44
|
-
|
42
|
+
client.set(key, value)
|
43
|
+
client.expire(key, duration)
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
###
|
48
47
|
# This method is used for getting cache entries with Redis.
|
49
48
|
#
|
50
49
|
# * *Args* :
|
51
50
|
# - +key+ -> The key of the cache entry
|
52
|
-
#
|
51
|
+
#
|
53
52
|
# * *Returns* :
|
54
53
|
# - Either the value for the given key or nil if the key was not found
|
55
54
|
###
|
56
55
|
def get(key)
|
57
|
-
JSON.parse(
|
56
|
+
JSON.parse(client.get(key))
|
58
57
|
end
|
59
|
-
|
58
|
+
|
60
59
|
###
|
61
60
|
# This method is used for deleting cache entries with Redis.
|
62
61
|
#
|
63
62
|
# * *Args* :
|
64
63
|
# - +key+ -> The key of the cache entry
|
65
|
-
#
|
64
|
+
#
|
66
65
|
# * *Returns* :
|
67
|
-
# - True/False determining whether the deletion was
|
66
|
+
# - True/False determining whether the deletion was successful or not
|
68
67
|
###
|
69
68
|
def delete(key)
|
70
|
-
|
69
|
+
client.del(key)
|
71
70
|
end
|
72
|
-
|
71
|
+
|
73
72
|
###
|
74
73
|
# This method is used for checking whether a cache entry exists or not with Redis.
|
75
74
|
#
|
76
75
|
# * *Args* :
|
77
76
|
# - +key+ -> The key of the cache entry
|
78
|
-
#
|
77
|
+
#
|
79
78
|
# * *Returns* :
|
80
79
|
# - True/False determining whether the key exists in the cache or not
|
81
80
|
###
|
82
81
|
def exists(key)
|
83
|
-
|
82
|
+
client.exists(key)
|
84
83
|
end
|
85
84
|
end
|
86
85
|
end
|
87
86
|
end
|
88
|
-
end
|
87
|
+
end
|
@@ -9,38 +9,37 @@ module AboutYou
|
|
9
9
|
###
|
10
10
|
class ProductFields
|
11
11
|
# id and name is set per default
|
12
|
-
|
13
|
-
#product field "is_active"
|
12
|
+
# product field "is_active"
|
14
13
|
IS_ACTIVE = 'active'
|
15
|
-
#product field "brand_id"
|
14
|
+
# product field "brand_id"
|
16
15
|
BRAND = 'brand_id'
|
17
|
-
#product field "description_long"
|
16
|
+
# product field "description_long"
|
18
17
|
DESCRIPTION_LONG = 'description_long'
|
19
|
-
#product field "description_short"
|
18
|
+
# product field "description_short"
|
20
19
|
DESCRIPTION_SHORT = 'description_short'
|
21
|
-
#product field "default_variant"
|
20
|
+
# product field "default_variant"
|
22
21
|
DEFAULT_VARIANT = 'default_variant'
|
23
|
-
#product field "variants"
|
22
|
+
# product field "variants"
|
24
23
|
VARIANTS = 'variants'
|
25
|
-
#product field "min_price"
|
24
|
+
# product field "min_price"
|
26
25
|
MIN_PRICE = 'min_price'
|
27
|
-
#product field "max_price"
|
26
|
+
# product field "max_price"
|
28
27
|
MAX_PRICE = 'max_price'
|
29
|
-
#product field "sale"
|
28
|
+
# product field "sale"
|
30
29
|
IS_SALE = 'sale'
|
31
|
-
#product field "default_image"
|
30
|
+
# product field "default_image"
|
32
31
|
DEFAULT_IMAGE = 'default_image'
|
33
|
-
#product field "attributes_merged"
|
32
|
+
# product field "attributes_merged"
|
34
33
|
ATTRIBUTES_MERGED = 'attributes_merged'
|
35
|
-
#product field "categories"
|
34
|
+
# product field "categories"
|
36
35
|
CATEGORIES = 'categories'
|
37
|
-
#product field "inactive_variants"
|
36
|
+
# product field "inactive_variants"
|
38
37
|
INACTIVE_VARIANTS = 'inactive_variants'
|
39
|
-
#product field "max_savings"
|
38
|
+
# product field "max_savings"
|
40
39
|
MAX_SAVINGS = 'max_savings'
|
41
|
-
#product field "max_savings_percentage"
|
40
|
+
# product field "max_savings_percentage"
|
42
41
|
MAX_SAVINGS_PERCENTAGE = 'max_savings_percentage'
|
43
|
-
#product field "tags"
|
42
|
+
# product field "tags"
|
44
43
|
TAGS = 'tags'
|
45
44
|
|
46
45
|
###
|
@@ -52,17 +51,16 @@ module AboutYou
|
|
52
51
|
# * *Returns* :
|
53
52
|
# - a filtered Array of product fields
|
54
53
|
###
|
55
|
-
def self.
|
54
|
+
def self.filter_fields(fields)
|
56
55
|
fields = fields.uniq
|
57
56
|
|
58
57
|
# this simplifies parsing on (pre)fetching facets
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
58
|
+
fields.push(ATTRIBUTES_MERGED) if
|
59
|
+
fields.include?(ATTRIBUTES_MERGED) &&
|
60
|
+
(fields.include?(BRAND) ||
|
61
|
+
fields.include?(VARIANTS) ||
|
62
|
+
fields.include?(DEFAULT_VARIANT))
|
63
|
+
|
66
64
|
fields
|
67
65
|
end
|
68
66
|
|
@@ -75,7 +73,7 @@ module AboutYou
|
|
75
73
|
# * *Returns* :
|
76
74
|
# - a boolean which is true when ap call has to require facets
|
77
75
|
###
|
78
|
-
def self.
|
76
|
+
def self.requires_facets(fields)
|
79
77
|
([BRAND,
|
80
78
|
VARIANTS,
|
81
79
|
DEFAULT_VARIANT,
|
@@ -92,7 +90,7 @@ module AboutYou
|
|
92
90
|
# * *Returns* :
|
93
91
|
# - a boolean which is true when ap call has to require categories
|
94
92
|
###
|
95
|
-
def self.
|
93
|
+
def self.requires_categories(fields)
|
96
94
|
fields.include?(CATEGORIES)
|
97
95
|
end
|
98
96
|
end
|
@@ -47,20 +47,20 @@ module AboutYou
|
|
47
47
|
# a specification of the result which should be fetched from api
|
48
48
|
attr_accessor :result
|
49
49
|
# the session id of a user
|
50
|
-
attr_accessor :
|
50
|
+
attr_accessor :session_id
|
51
51
|
|
52
52
|
###
|
53
53
|
# Constructor for AboutYou::SDK::Criteria::ProductSearchCriteria
|
54
54
|
#
|
55
55
|
# * *Args* :
|
56
|
-
# - +
|
56
|
+
# - +session_id+ -> the session is of an user
|
57
57
|
#
|
58
58
|
# * *Returns* :
|
59
59
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
60
60
|
###
|
61
|
-
def initialize(
|
61
|
+
def initialize(session_id)
|
62
62
|
self.filter = {}
|
63
|
-
self.
|
63
|
+
self.session_id = session_id
|
64
64
|
self.result = {}
|
65
65
|
end
|
66
66
|
|
@@ -74,9 +74,10 @@ module AboutYou
|
|
74
74
|
# * *Returns* :
|
75
75
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
76
76
|
###
|
77
|
-
def
|
77
|
+
def filter_by(key, value)
|
78
78
|
@filter[key] = value
|
79
|
-
|
79
|
+
|
80
|
+
self
|
80
81
|
end
|
81
82
|
|
82
83
|
###
|
@@ -101,12 +102,10 @@ module AboutYou
|
|
101
102
|
# * *Returns* :
|
102
103
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
103
104
|
###
|
104
|
-
def
|
105
|
-
unless sale.is_a?(TrueClass) || sale.is_a?(FalseClass)
|
106
|
-
sale = nil
|
107
|
-
end
|
105
|
+
def filter_by_sale(sale = true)
|
106
|
+
sale = nil unless sale.is_a?(TrueClass) || sale.is_a?(FalseClass)
|
108
107
|
|
109
|
-
|
108
|
+
filter_by(FILTER_SALE, sale)
|
110
109
|
end
|
111
110
|
|
112
111
|
###
|
@@ -118,8 +117,8 @@ module AboutYou
|
|
118
117
|
# * *Returns* :
|
119
118
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
120
119
|
###
|
121
|
-
def
|
122
|
-
|
120
|
+
def filter_by_searchword(searchword)
|
121
|
+
filter_by(FILTER_SEARCHWORD, searchword)
|
123
122
|
end
|
124
123
|
|
125
124
|
###
|
@@ -132,15 +131,14 @@ module AboutYou
|
|
132
131
|
# * *Returns* :
|
133
132
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
134
133
|
###
|
135
|
-
def
|
136
|
-
|
137
|
-
|
138
|
-
end
|
139
|
-
categoryIds = categoryIds.uniq
|
134
|
+
def filter_by_category_ids(category_ids, append = false)
|
135
|
+
category_ids = filter(FILTER_CATEGORY_IDS) + category_ids if
|
136
|
+
append && filter(FILTER_CATEGORY_IDS)
|
140
137
|
|
141
|
-
|
142
|
-
end
|
138
|
+
category_ids = category_ids.uniq
|
143
139
|
|
140
|
+
filter_by(FILTER_CATEGORY_IDS, category_ids)
|
141
|
+
end
|
144
142
|
|
145
143
|
###
|
146
144
|
# sets a filter for filtering by category ids
|
@@ -152,49 +150,48 @@ module AboutYou
|
|
152
150
|
# * *Returns* :
|
153
151
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
154
152
|
###
|
155
|
-
def
|
153
|
+
def filter_by_facet_ids(attributes, append = false)
|
156
154
|
merged = attributes[0]
|
157
|
-
if append &&
|
158
|
-
merged =
|
159
|
-
attributes.each do |
|
160
|
-
if merged.key?(
|
161
|
-
merged[
|
155
|
+
if append && filter(FILTER_ATTRIBUTES)
|
156
|
+
merged = filter(FILTER_ATTRIBUTES)
|
157
|
+
attributes.each do |group_id, facet_ids|
|
158
|
+
if merged.key?(group_id)
|
159
|
+
merged[group_id] = (merged[group_id] + facet_ids).uniq
|
162
160
|
else
|
163
|
-
merged[
|
164
|
-
end
|
161
|
+
merged[group_id] = facet_ids
|
162
|
+
end
|
165
163
|
end
|
166
|
-
attributes = merged
|
167
164
|
end
|
168
|
-
self.filterBy(FILTER_ATTRIBUTES, merged)
|
169
|
-
end
|
170
165
|
|
166
|
+
filter_by(FILTER_ATTRIBUTES, merged)
|
167
|
+
end
|
171
168
|
|
172
169
|
###
|
173
170
|
# sets a filter for filtering by Facet-Group
|
174
171
|
#
|
175
172
|
# * *Args* :
|
176
|
-
# - +
|
173
|
+
# - +facet_group+ -> Instance of AboutYou::SDK::Model::FacetGroup
|
177
174
|
# - +append+ -> determines whether to append the category ids to an already set value or not [optional]
|
178
175
|
#
|
179
176
|
# * *Returns* :
|
180
177
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
181
178
|
###
|
182
|
-
def
|
183
|
-
|
179
|
+
def filter_by_facet_group(facet_group, append = false)
|
180
|
+
filter_by_facet_ids(facet_group.ids, append)
|
184
181
|
end
|
185
182
|
|
186
183
|
###
|
187
184
|
# sets a filter for filtering by Facet-Groupset
|
188
185
|
#
|
189
186
|
# * *Args* :
|
190
|
-
# - +
|
187
|
+
# - +facet_group_set+ -> Instance of AboutYou::SDK::Model::FacetGroupSet
|
191
188
|
# - +append+ -> determines whether to append the category ids to an already set value or not [optional]
|
192
189
|
#
|
193
190
|
# * *Returns* :
|
194
191
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
195
192
|
###
|
196
|
-
def
|
197
|
-
|
193
|
+
def filter_by_facet_group_set(facet_group_set, append = false)
|
194
|
+
filter_by_facet_ids(facet_group_set.ids, append)
|
198
195
|
end
|
199
196
|
|
200
197
|
###
|
@@ -207,15 +204,15 @@ module AboutYou
|
|
207
204
|
# * *Returns* :
|
208
205
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
209
206
|
###
|
210
|
-
def
|
207
|
+
def filter_by_price_range(from = 0, to = 0)
|
211
208
|
from = Integer(from)
|
212
209
|
to = Integer(to)
|
213
210
|
price = {}
|
214
|
-
|
215
|
-
price["from"] = from if from > 0
|
216
|
-
price["to"] = to if to > 0
|
217
211
|
|
218
|
-
|
212
|
+
price['from'] = from if from > 0
|
213
|
+
price['to'] = to if to > 0
|
214
|
+
|
215
|
+
filter_by(FILTER_PRICE, price)
|
219
216
|
end
|
220
217
|
|
221
218
|
###
|
@@ -228,11 +225,12 @@ module AboutYou
|
|
228
225
|
# * *Returns* :
|
229
226
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
230
227
|
###
|
231
|
-
def
|
232
|
-
|
228
|
+
def sort_by(type, direction = SORT_ASC)
|
229
|
+
result['sort'] = {
|
233
230
|
'by' => type,
|
234
|
-
'direction' => direction
|
231
|
+
'direction' => direction
|
235
232
|
}
|
233
|
+
|
236
234
|
self
|
237
235
|
end
|
238
236
|
|
@@ -246,12 +244,13 @@ module AboutYou
|
|
246
244
|
# * *Returns* :
|
247
245
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
248
246
|
###
|
249
|
-
def
|
247
|
+
def set_limit(limit, offset = 0)
|
250
248
|
limit = [[limit, 200].min, 0].max
|
251
|
-
|
249
|
+
result['limit'] = limit
|
252
250
|
|
253
251
|
offset = [offset, 0].max
|
254
|
-
|
252
|
+
result['offset'] = offset
|
253
|
+
|
255
254
|
self
|
256
255
|
end
|
257
256
|
|
@@ -264,13 +263,13 @@ module AboutYou
|
|
264
263
|
# * *Returns* :
|
265
264
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
266
265
|
###
|
267
|
-
def
|
266
|
+
def select_sales(enable = true)
|
268
267
|
if enable
|
269
|
-
|
270
|
-
else
|
271
|
-
|
268
|
+
result['sale'] = true
|
269
|
+
else
|
270
|
+
result['sale'] = nil
|
272
271
|
end
|
273
|
-
|
272
|
+
|
274
273
|
self
|
275
274
|
end
|
276
275
|
|
@@ -283,40 +282,41 @@ module AboutYou
|
|
283
282
|
# * *Returns* :
|
284
283
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
285
284
|
###
|
286
|
-
def
|
287
|
-
if enable
|
288
|
-
|
289
|
-
else
|
290
|
-
|
285
|
+
def select_price_ranges(enable = true)
|
286
|
+
if enable
|
287
|
+
result['price'] = true
|
288
|
+
else
|
289
|
+
result['price'] = nil
|
291
290
|
end
|
292
291
|
|
293
292
|
self
|
294
293
|
end
|
295
294
|
|
296
295
|
###
|
297
|
-
# this method adds a field to the api-request which enables you to
|
296
|
+
# this method adds a field to the api-request which enables you to
|
298
297
|
# receive Facets by a given group id
|
299
298
|
#
|
300
299
|
# * *Args* :
|
301
|
-
# - +
|
300
|
+
# - +group_id+ -> group id which facets you want to receive
|
302
301
|
# - +limit+ -> limits the received facets
|
303
302
|
#
|
304
303
|
# * *Returns* :
|
305
304
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
306
305
|
###
|
307
|
-
def
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
306
|
+
def select_facets_by_group_id(group_id, limit)
|
307
|
+
check_facet_limit(limit)
|
308
|
+
|
309
|
+
fail "InvalidArgumentException! Group id must be an integer or a
|
310
|
+
string containing digits" unless
|
311
|
+
group_id.is_a?(Fixnum) && Integer(group_id)
|
312
|
+
|
313
|
+
result['facets'] = {} unless result['facets']
|
314
|
+
|
315
|
+
result['facets'][String(group_id)] = {
|
316
|
+
'limit' => limit
|
317
|
+
} unless
|
318
|
+
result['facets'][group_id]
|
319
|
+
|
320
320
|
self
|
321
321
|
end
|
322
322
|
|
@@ -329,9 +329,13 @@ module AboutYou
|
|
329
329
|
# * *Returns* :
|
330
330
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
331
331
|
###
|
332
|
-
def
|
333
|
-
|
334
|
-
|
332
|
+
def select_all_facets(limit)
|
333
|
+
check_facet_limit(limit)
|
334
|
+
result['facets'] = {
|
335
|
+
FACETS_ALL => {
|
336
|
+
'limit' => limit
|
337
|
+
}
|
338
|
+
}
|
335
339
|
|
336
340
|
self
|
337
341
|
end
|
@@ -345,13 +349,14 @@ module AboutYou
|
|
345
349
|
# * *Returns* :
|
346
350
|
# - nil if there is no error
|
347
351
|
###
|
348
|
-
def
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
352
|
+
def check_facet_limit(limit)
|
353
|
+
fail 'InvalidArgumentException! limit must be an integer' unless
|
354
|
+
limit.is_a?(Fixnum) || limit.is_a?(Integer)
|
355
|
+
|
356
|
+
fail 'InvalidArgumentException! limit must be positive or -1
|
357
|
+
for unlimited facets' if limit < -1
|
358
|
+
|
359
|
+
nil
|
355
360
|
end
|
356
361
|
|
357
362
|
###
|
@@ -363,11 +368,11 @@ module AboutYou
|
|
363
368
|
# * *Returns* :
|
364
369
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
365
370
|
###
|
366
|
-
def
|
371
|
+
def select_categories(enable = true)
|
367
372
|
if enable
|
368
|
-
|
369
|
-
else
|
370
|
-
|
373
|
+
result['categories'] = true
|
374
|
+
else
|
375
|
+
result['categories'] = nil
|
371
376
|
end
|
372
377
|
|
373
378
|
self
|
@@ -383,17 +388,15 @@ module AboutYou
|
|
383
388
|
# * *Returns* :
|
384
389
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
385
390
|
###
|
386
|
-
def
|
387
|
-
|
388
|
-
ids = ids.map
|
391
|
+
def boost_products(ids)
|
392
|
+
mapped_ids = []
|
393
|
+
ids = ids.map do
|
389
394
|
|val|
|
390
|
-
if val.instance_of?(Product)
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
mappedIds = mappedIds.uniq
|
396
|
-
self.result['boosts'] = ids
|
395
|
+
mapped_ids.push(val.id) if val.instance_of?(Product)
|
396
|
+
mapped_ids.push(val)
|
397
|
+
end
|
398
|
+
mapped_ids = mapped_ids.uniq
|
399
|
+
result['boosts'] = ids
|
397
400
|
|
398
401
|
self
|
399
402
|
end
|
@@ -408,9 +411,9 @@ module AboutYou
|
|
408
411
|
# * *Returns* :
|
409
412
|
# - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
|
410
413
|
###
|
411
|
-
def
|
412
|
-
|
413
|
-
AboutYou::SDK::Criteria::ProductFields.
|
414
|
+
def select_product_fields(fields)
|
415
|
+
result['fields'] =
|
416
|
+
AboutYou::SDK::Criteria::ProductFields.filter_fields(fields)
|
414
417
|
|
415
418
|
self
|
416
419
|
end
|
@@ -421,12 +424,14 @@ module AboutYou
|
|
421
424
|
# * *Returns* :
|
422
425
|
# - a boolean stating whether to fetch categories from api or not
|
423
426
|
###
|
424
|
-
def
|
425
|
-
(
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
427
|
+
def requires_categories
|
428
|
+
(result.key?('fields') &&
|
429
|
+
AboutYou::SDK::Criteria::ProductFields.requires_categories(
|
430
|
+
result['fields']
|
431
|
+
)) || (
|
432
|
+
result.key?('categories') &&
|
433
|
+
result['categories']
|
434
|
+
)
|
430
435
|
end
|
431
436
|
|
432
437
|
###
|
@@ -435,35 +440,35 @@ module AboutYou
|
|
435
440
|
# * *Returns* :
|
436
441
|
# - a boolean stating whether to fetch facets from api or not
|
437
442
|
###
|
438
|
-
def
|
439
|
-
(
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
443
|
+
def requires_facets
|
444
|
+
(result.key?('fields') &&
|
445
|
+
AboutYou::SDK::Criteria::ProductFields.requires_facets(
|
446
|
+
result['fields']
|
447
|
+
)) || (
|
448
|
+
result.key?('facets') &&
|
449
|
+
!result['facets'].empty?
|
450
|
+
)
|
444
451
|
end
|
445
452
|
|
446
453
|
###
|
447
454
|
# this method turns an instance of
|
448
|
-
# AboutYou::SDK::Criteria::
|
449
|
-
# be passed directly to the api
|
455
|
+
# AboutYou::SDK::Criteria::product_search_criteria in an Array which can
|
456
|
+
# be passed directly to the api
|
450
457
|
#
|
451
458
|
# * *Returns* :
|
452
459
|
# - an Array containing all the parameters set on the instance
|
453
460
|
###
|
454
|
-
def
|
455
|
-
params = {
|
461
|
+
def to_array
|
462
|
+
params = {
|
463
|
+
'session_id' => session_id
|
464
|
+
}
|
456
465
|
|
457
|
-
if
|
458
|
-
|
459
|
-
end
|
460
|
-
unless @filter.empty?
|
461
|
-
params['filter'] = @filter
|
462
|
-
end
|
466
|
+
params['result'] = result if result
|
467
|
+
params['filter'] = @filter unless @filter.empty?
|
463
468
|
|
464
469
|
params
|
465
470
|
end
|
466
471
|
end
|
467
472
|
end
|
468
473
|
end
|
469
|
-
end
|
474
|
+
end
|