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
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzgzNjUwZmE3ZTRhOTE4ZjdmMzdlYzQyZDhiN2JjMGEwODlkZjI5Mg==
4
+ ZWRiNTIyMzA5N2MxYjdhM2YyZThlMThmMWYxYTY3ODZlMDQ5MDI5Mw==
5
5
  data.tar.gz: !binary |-
6
- YTljNGU5NWZhMWY1OTc3NTc0OGVmZWI2ZjEzODJjMWMzYTE4MzM4ZA==
6
+ ZTM5OGU3Yjk0NzU4NjFiNGQxZmYyZjdiMjE0MThmZjlkNzM0ZjUxZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWYzMWExMTNlOGEzOGMyYWUyMTY0NmIxOWFkNmI1ZDNkOTViZjBhZDgxMGI4
10
- MDIyNGY0MDI3ZmI0NzMwODI2ZjY2ODExYTdhZWZmYTZiMzkyZjBlN2ZhZWUy
11
- MjNiNDczZWU4NjZmNmNmN2RhYzU3YmRmMjcyZjc3ZmE4NGI5OWM=
9
+ MWNhNTBkYWRhNjNjZWM1NjdjZWE4ZWMzNTg4MDc2YjM4M2IxYTI3MzhmNjli
10
+ YzA3N2Q4ZDkwMmEzZTcwM2EwNmI0YmUwOGFkZjVlYjc4MDlmMzE4ZjQ2ZmVh
11
+ N2U2N2IyNDM5ZWFiYWZiNTJkOTdjMjIwODI5MzI5NzMxMzRkZTQ=
12
12
  data.tar.gz: !binary |-
13
- YjBlMzFiNWZhNTJjZGYwY2YyYmI5NzhkNDUzNWEyM2Q4YjE5YmIyNjVlOTQ1
14
- MTEzM2IyMGQ5ODViNWI4Y2NlY2NhYWM4MzM3MDdiYTYyYzdhOGZhOGI3NzI1
15
- YWM1Y2VlNTI0YmI0ZDk1NmVhMzYxYTlmMDU5MWQzYjdmOTlkNjk=
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 successfull of not
38
+ # - True/False determining whether the setting was successful of not
40
39
  ###
41
40
  def set(key, value, duration)
42
- self.client.set(key, value, duration)
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
- self.client.get(key)
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 successfull or not
64
+ # - True/False determining whether the deletion was successful or not
66
65
  ###
67
66
  def delete(key)
68
- self.client.delete(key)
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
- self.client.get(key) != nil
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 successfull of not
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
- self.client.set(key, value)
44
- self.client.expire(key, duration)
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(self.client.get(key))
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 successfull or not
66
+ # - True/False determining whether the deletion was successful or not
68
67
  ###
69
68
  def delete(key)
70
- self.client.del(key)
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
- self.client.exists(key)
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.filterFields(fields)
54
+ def self.filter_fields(fields)
56
55
  fields = fields.uniq
57
56
 
58
57
  # this simplifies parsing on (pre)fetching facets
59
- if (fields.include? ATTRIBUTES_MERGED) && (
60
- fields.include?(BRAND) ||
61
- fields.include?(VARIANTS) ||
62
- fields.include?(DEFAULT_VARIANT)
63
- )
64
- fields.push(ATTRIBUTES_MERGED)
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.requiresFacets(fields)
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.requiresCategories(fields)
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 :sessionId
50
+ attr_accessor :session_id
51
51
 
52
52
  ###
53
53
  # Constructor for AboutYou::SDK::Criteria::ProductSearchCriteria
54
54
  #
55
55
  # * *Args* :
56
- # - +sessionId+ -> the session is of an user
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(sessionId)
61
+ def initialize(session_id)
62
62
  self.filter = {}
63
- self.sessionId = sessionId
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 filterBy(key, value)
77
+ def filter_by(key, value)
78
78
  @filter[key] = value
79
- return self
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 filterBySale(sale = true)
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
- self.filterBy(FILTER_SALE, sale)
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 filterBySearchword(searchword)
122
- self.filterBy(FILTER_SEARCHWORD, searchword)
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 filterByCategoryIds(categoryIds, append = false)
136
- if append && self.filter[FILTER_CATEGORY_IDS]
137
- categoryIds = self.filter[FILTER_CATEGORY_IDS] + categoryIds
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
- self.filterBy(FILTER_CATEGORY_IDS, categoryIds);
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 filterByFacetIds(attributes, append = false)
153
+ def filter_by_facet_ids(attributes, append = false)
156
154
  merged = attributes[0]
157
- if append && self.filter[FILTER_ATTRIBUTES]
158
- merged = self.filter[FILTER_ATTRIBUTES]
159
- attributes.each do |groupId, facetIds|
160
- if merged.key?(groupId)
161
- merged[groupId] = (merged[groupId] + facetIds).uniq
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[groupId] = facetIds
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
- # - +facetGroup+ -> Instance of AboutYou::SDK::Model::FacetGroup
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 filterByFacetGroup(facetGroup, append = false)
183
- self.filterByFacetIds(facetGroup.ids, append)
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
- # - +facetGroupSet+ -> Instance of AboutYou::SDK::Model::FacetGroupSet
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 filterByFacetGroupSet(facetGroupSet, append = false)
197
- self.filterByFacetIds(facetGroupSet.ids, append)
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 filterByPriceRange(from = 0, to = 0)
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
- self.filterBy(FILTER_PRICE, price)
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 sortBy(type, direction = SORT_ASC)
232
- self.result['sort'] = {
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 setLimit(limit, offset = 0)
247
+ def set_limit(limit, offset = 0)
250
248
  limit = [[limit, 200].min, 0].max
251
- self.result['limit'] = limit
249
+ result['limit'] = limit
252
250
 
253
251
  offset = [offset, 0].max
254
- self.result['offset'] = offset
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 selectSales(enable = true)
266
+ def select_sales(enable = true)
268
267
  if enable
269
- self.result['sale'] = true
270
- else
271
- self.result['sale'] = nil
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 selectPriceRanges(enable = true)
287
- if enable
288
- self.result['price'] = true
289
- else
290
- self.result['price'] = nil
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
- # - +groupId+ -> group id which facets you want to receive
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 selectFacetsByGroupId(groupId, limit)
308
- self.checkFacetLimit(limit)
309
- unless groupId.is_a?(Fixnum) && Integer(groupId)
310
- raise "InvalidArgumentException! Group id must be an integer or a
311
- string containing digits"
312
- end
313
- unless self.result['facets']
314
- self.result['facets'] = {}
315
- end
316
- unless self.result['facets'][groupId]
317
- self.result['facets'][String(groupId)] = {'limit' => limit}
318
- end
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 selectAllFacets(limit)
333
- self.checkFacetLimit(limit)
334
- self.result['facets'] = {self::FACETS_ALL => {'limit' => limit}}
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 checkFacetLimit(limit)
349
- unless limit.is_a?(Fixnum) || limit.is_a?(Integer)
350
- raise 'InvalidArgumentException! limit must be an integer'
351
- end
352
- if limit < -1
353
- raise 'InvalidArgumentException! limit must be positive or -1 for unlimited facets'
354
- end
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 selectCategories(enable = true)
371
+ def select_categories(enable = true)
367
372
  if enable
368
- self.result['categories'] = true
369
- else
370
- self.result['categories'] = nil
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 boostProducts(ids)
387
- mappedIds = []
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
- mappedIds.push(val.id)
392
- end
393
- mappedIds.push(val)
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 selectProductFields(fields)
412
- self.result['fields'] =
413
- AboutYou::SDK::Criteria::ProductFields.filterFields(fields)
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 requiresCategories
425
- (self.result.has_key?('fields') &&
426
- AboutYou::SDK::Criteria::ProductFields.
427
- requiresCategories(self.result['fields'])) ||
428
- (self.result.has_key?('categories') &&
429
- self.result['categories'])
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 requiresFacets
439
- (self.result.key?('fields') &&
440
- AboutYou::SDK::Criteria::ProductFields.
441
- requiresFacets(self.result['fields'])) ||
442
- (self.result.key?('facets') &&
443
- !self.result['facets'].empty?)
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::productSearchCriteria in an Array which can
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 toArray
455
- params = {'session_id' => self.sessionId}
461
+ def to_array
462
+ params = {
463
+ 'session_id' => session_id
464
+ }
456
465
 
457
- if self.result
458
- params['result'] = self.result
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