aboutyou-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +15 -0
  2. data/lib/aboutyou-sdk.rb +545 -0
  3. data/lib/aboutyou-sdk/Client.rb +125 -0
  4. data/lib/aboutyou-sdk/Constants.rb +48 -0
  5. data/lib/aboutyou-sdk/Criteria/ProductFields.rb +54 -0
  6. data/lib/aboutyou-sdk/Criteria/ProductSearchCriteria.rb +436 -0
  7. data/lib/aboutyou-sdk/Factory/DefaultModelFactory.rb +454 -0
  8. data/lib/aboutyou-sdk/Model/AbstractModel.rb +26 -0
  9. data/lib/aboutyou-sdk/Model/App.rb +35 -0
  10. data/lib/aboutyou-sdk/Model/Autocomplete.rb +92 -0
  11. data/lib/aboutyou-sdk/Model/Basket.rb +262 -0
  12. data/lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb +76 -0
  13. data/lib/aboutyou-sdk/Model/Basket/BasketItem.rb +100 -0
  14. data/lib/aboutyou-sdk/Model/Basket/BasketSet.rb +192 -0
  15. data/lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb +46 -0
  16. data/lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb +137 -0
  17. data/lib/aboutyou-sdk/Model/CategoriesResult.rb +15 -0
  18. data/lib/aboutyou-sdk/Model/Category.rb +126 -0
  19. data/lib/aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb +172 -0
  20. data/lib/aboutyou-sdk/Model/CategoryTree.rb +35 -0
  21. data/lib/aboutyou-sdk/Model/Facet.rb +105 -0
  22. data/lib/aboutyou-sdk/Model/FacetGroup.rb +110 -0
  23. data/lib/aboutyou-sdk/Model/FacetGroupSet.rb +247 -0
  24. data/lib/aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb +79 -0
  25. data/lib/aboutyou-sdk/Model/Image.rb +134 -0
  26. data/lib/aboutyou-sdk/Model/ImageSize.rb +21 -0
  27. data/lib/aboutyou-sdk/Model/InitiateOrder.rb +50 -0
  28. data/lib/aboutyou-sdk/Model/Order.rb +17 -0
  29. data/lib/aboutyou-sdk/Model/Product.rb +543 -0
  30. data/lib/aboutyou-sdk/Model/ProductSearchResult.rb +125 -0
  31. data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb +26 -0
  32. data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb +38 -0
  33. data/lib/aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb +49 -0
  34. data/lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb +58 -0
  35. data/lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb +27 -0
  36. data/lib/aboutyou-sdk/Model/ProductsEansResult.rb +43 -0
  37. data/lib/aboutyou-sdk/Model/ProductsResult.rb +52 -0
  38. data/lib/aboutyou-sdk/Model/ResultError.rb +24 -0
  39. data/lib/aboutyou-sdk/Model/Variant.rb +255 -0
  40. data/lib/aboutyou-sdk/Model/VariantsResult.rb +102 -0
  41. data/lib/aboutyou-sdk/Query.rb +261 -0
  42. data/lib/aboutyou-sdk/QueryBuilder.rb +440 -0
  43. data/tests/Sinatra-test/Main.rb +5 -0
  44. data/tests/testApiClient.rb +35 -0
  45. data/tests/testAutocomplete.rb +40 -0
  46. data/tests/testCatFilter.rb +35 -0
  47. data/tests/testCatTree.rb +37 -0
  48. data/tests/testFacets.rb +36 -0
  49. data/tests/testProdCatLongestPath.rb +34 -0
  50. data/tests/testProductSearchResult.rb +35 -0
  51. data/tests/testProductsByIds.rb +34 -0
  52. data/tests/testVariantsByIds.rb +34 -0
  53. metadata +122 -0
@@ -0,0 +1,110 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class FacetGroup
5
+
6
+ # @var Facet[] */
7
+ @facets;
8
+ attr_accessor :facets
9
+
10
+ # @var integer */
11
+ @id;
12
+ attr_accessor :id
13
+
14
+ # @var string */
15
+ @name;
16
+ attr_accessor :name
17
+
18
+ @groupId
19
+ attr_accessor :groupId
20
+
21
+ ###
22
+ # @param integer $id
23
+ # @param string $name
24
+ ###
25
+ def initialize(id, name)
26
+
27
+ self.id = id;
28
+ self.name = name;
29
+ self.facets = Hash.new
30
+ end
31
+
32
+ ###
33
+ # @param Facet $facet
34
+ ###
35
+ def addFacet(facet)
36
+
37
+ self.facets[facet.id] = facet;
38
+ end
39
+
40
+ ###
41
+ # @param Facet[] $facet
42
+ ###
43
+ def addFacets(facets)
44
+
45
+ facets.each do |facet|
46
+ self.addFacet(facet);
47
+ end
48
+ end
49
+
50
+
51
+ ###
52
+ # Returns all facet names separated with the given parameter
53
+ # eg. for size with to size facets "36" and "37" -> "36/37"
54
+ #
55
+ # @param string $separator
56
+ #
57
+ # @return string
58
+ ###
59
+ def facetNames(separator = '/')
60
+
61
+ names = Array(nil);
62
+ self.facets.each do |facet|
63
+ names.push(facetname());
64
+ end
65
+
66
+ return name.join(seperator)
67
+ end
68
+
69
+ ###
70
+ # facet groups are equal, if the ids and all child ids are equal
71
+ #
72
+ # @param FacetGroup $facetGroup
73
+ #
74
+ # @return boolean
75
+ ###
76
+ def isEqual(facetGroup)
77
+
78
+ return false if (self.id != facetGroup.id)
79
+
80
+ return self.uniqueKey() == facetGroup.uniqueKey();
81
+ end
82
+
83
+ ###
84
+ # @see isEqual
85
+ #
86
+ # @return string
87
+ ###
88
+ def uniqueKey()
89
+
90
+ facetIds = self.facets.keys
91
+ facetIds.sort
92
+
93
+ return String(self.id) + ':' + String(facetIds.join(','))
94
+ end
95
+
96
+ def ids()
97
+
98
+ return Hash[self.id => self.facets.keys]
99
+
100
+ end
101
+
102
+
103
+ def contains(facet)
104
+
105
+ return self.facets[facet.id].defined?
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,247 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class FacetGroupSet
5
+
6
+ # @var array */
7
+ attr_accessor :ids;
8
+
9
+ # @var FacetGroup[] */
10
+ attr_accessor :groups;
11
+
12
+ # @var Facet[] */
13
+ attr_accessor :facets;
14
+
15
+ # @var FacetManagerInterface */
16
+ class << self
17
+ attr_accessor :facetManager
18
+ end
19
+
20
+ ###
21
+ # @param array $ids two dimensional array of group ids and array ids
22
+ #
23
+ # @throws \InvalidArgumentException
24
+ ###
25
+ def initialize(ids)
26
+ self.facets = Hash.new
27
+ self.groups = Hash.new
28
+ ids.each do |facetIds|
29
+ if !(facetIds.is_a? Hash)
30
+ raise '\InvalidArgumentException! ids must be an associative array of array: [$groupId => [$facetId,...],...]'
31
+ end
32
+ end
33
+
34
+ self.ids = ids;
35
+ end
36
+
37
+ ###
38
+ # @return boolean
39
+ ###
40
+ def isEmpty()
41
+
42
+ return self.ids.empty?
43
+ end
44
+
45
+ def genLazyGroups()
46
+
47
+ groups = Hash.new
48
+ self.ids.each do |groupId, facetIds|
49
+ group = AboutYou::SDK::Model::FacetGroup.new(groupId, nil);
50
+ facetIds.each do |facetId|
51
+ facet = AboutYou::SDK::Model::Facet.new(facetId, nil, nil, groupId, nil);
52
+ group.addFacet(facet);
53
+ end
54
+ groups[groupId] = group;
55
+ end
56
+
57
+ return groups;
58
+ end
59
+
60
+ def lazyGroups()
61
+
62
+ if !(self.facets.empty?)
63
+ return self.groups;
64
+ else
65
+ return self.genLazyGroups();
66
+ end
67
+ end
68
+
69
+ def fetch()
70
+
71
+ if !(self.facets.empty?)
72
+ return;
73
+ end
74
+ self.ids.each do |idPair|
75
+
76
+ idPair.each do |groupId, facetIds|
77
+ facet = self.class.facetManager.facet(groupId, facetIds);
78
+
79
+ if !(facet)
80
+ # TODO: error handling
81
+ next
82
+ end
83
+
84
+ if (self.groups[groupId])
85
+ group = self.groups[groupId];
86
+ else
87
+ group = AboutYou::SDK::Model::FacetGroup.new(groupId, facet.groupName());
88
+ self.groups[groupId] = group;
89
+ end
90
+
91
+ group.addFacet(facet);
92
+ self.facets[facet.uniqueKey] = facet;
93
+ end
94
+ end
95
+ end
96
+
97
+ ###
98
+ # @return FacetGroup[]
99
+ ###
100
+ def groups()
101
+
102
+ if (@groups.empty?)
103
+ self.fetch();
104
+ end
105
+
106
+ return(@groups);
107
+ end
108
+
109
+ ###
110
+ # @param $groupId
111
+ #
112
+ # @return FacetGroup|null
113
+ ###
114
+ def group(groupId)
115
+
116
+ groups = self.groups();
117
+ if (groups["groupId"])
118
+ return groups[groupId];
119
+ end
120
+
121
+ return nil;
122
+ end
123
+
124
+ ###
125
+ # @param $groupId
126
+ #
127
+ # @return bool
128
+ ###
129
+ def hasGroup(groupId)
130
+
131
+ return !(self.ids[groupId].empty?);
132
+ end
133
+
134
+
135
+ ###
136
+ # @param string $key
137
+ #
138
+ # @return Facet|null
139
+ ###
140
+ def facetByKey(key)
141
+
142
+ self.fetch();
143
+
144
+ self.facets[key] ? self.facets[key] : nil
145
+ end
146
+
147
+
148
+ def facet(facetGroupId, facetId)
149
+
150
+ if (self.facets.empty?)
151
+ self.fetch();
152
+ end
153
+
154
+ if (self.facets[String(facetGroupId)+':'+String(facetId)])
155
+ return(self.facets[String(facetGroupId)+':'+String(facetId)]);
156
+ end
157
+ end
158
+
159
+ # ###
160
+ # # set are equal, if all groups are equal
161
+ # # which means, that all included facet ids per group must be the same
162
+ # #
163
+ # # @return string
164
+ # ###
165
+ # def uniqueKey()
166
+ #
167
+ # ids = self.ids;
168
+ # asort($ids);
169
+ # array_walk($ids, 'sort');
170
+ #
171
+ # return json_encode($ids);
172
+ # end
173
+
174
+ ###
175
+ # @param FacetUniqueKeyInterface $facetCompable
176
+ #
177
+ # @return boolean
178
+ ###
179
+ def contains(facetCompable)
180
+
181
+ if (facetCompable.is_a? self.class)
182
+ return self.containsFacetGroupSet(facetCompable);
183
+ end
184
+
185
+ # if (facetCompable.is_a? AboutYou::SDK::Model::FacetGetGroupInterface)
186
+ # return $this->containsFacetGetGroupInterface($facetCompable);
187
+ # }
188
+
189
+ return false;
190
+ end
191
+
192
+ # private function containsFacetGetGroupInterface(FacetGetGroupInterface $facet)
193
+ # {
194
+ # $myLazyGroups = $this->getLazyGroups();
195
+ # $id = $facet->getGroupId();
196
+ #
197
+ # if (isset($myLazyGroups[$id])) {
198
+ # return $myLazyGroups[$id]->getUniqueKey() === $facet->getUniqueKey();
199
+ # }
200
+ #
201
+ # return false;
202
+ # }
203
+
204
+ def containsFacetGroupSet(facetGroupSet)
205
+
206
+ if (self.uniqueKey() == facetGroupSet.uniqueKey())
207
+ return true;
208
+ end
209
+
210
+ myLazyGroups = self.lazyGroups();
211
+ self.facetGroupSet.lazyGroups.each do |id, group|
212
+ if ((myLazyGroups["id"]) || myLazyGroups[id].uniqueKey() != group.uniqueKey())
213
+ return false;
214
+ end
215
+ end
216
+
217
+ return true;
218
+ end
219
+
220
+ def self.mergeFacetIds(facetIdsArray)
221
+
222
+ ids = Array(nil);
223
+ facetIdsArray.each do |facetIds|
224
+ facetIds.each do |groupId,facetIds|
225
+ if (ids[Integer(groupId)])
226
+ ids[Integer(groupId)] = ids[Integer(groupId)] + facetIds;
227
+ else
228
+ ids[Integer(groupId)] = facetIds;
229
+ end
230
+ end
231
+ end
232
+
233
+ return ids;
234
+ end
235
+
236
+ ###
237
+ # @return array
238
+ ###
239
+ def groupIds()
240
+
241
+ return self.ids.keys
242
+ end
243
+
244
+ end
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,79 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ module FacetManager
5
+ class DefaultFacetManager
6
+
7
+ DEFAULT_CACHE_DURATION = 7200;
8
+
9
+ # @var Facet[][] */
10
+ @facets
11
+ attr_accessor :facets
12
+
13
+ # @var Cache */
14
+ @cache;
15
+ attr_accessor :cache
16
+
17
+ # @var string */
18
+ @cacheKey;
19
+ attr_accessor :cacheKey
20
+
21
+ ###
22
+ # @param Cache $cache
23
+ # @param string $appId
24
+ ###
25
+ def initialize(cache = nil, appId = '')
26
+
27
+ self.cache = cache;
28
+ self.cacheKey = 'AY:SDK:' + String(appId) + ':facets';
29
+ self.facets = Hash.new
30
+
31
+ self.loadCachedFacets();
32
+ end
33
+
34
+ def loadCachedFacets()
35
+
36
+ if (self.cache)
37
+ self.facets = (self.cache.fetch(self.cacheKey)) ? self.cache.fetch(self.cacheKey): nil;
38
+ end
39
+ end
40
+
41
+ def cacheFacets()
42
+
43
+ if (self.cache)
44
+ self.cache.save(self.cacheKey, self.facets, DEFAULT_CACHE_DURATION);
45
+ end
46
+ end
47
+
48
+ def clearCache()
49
+
50
+ if (self.cache)
51
+ self.cache.delete(self.cacheKey);
52
+ end
53
+ end
54
+
55
+ def isEmpty()
56
+
57
+ return (self.facets.empty?);
58
+ end
59
+
60
+ def facets=(facets)
61
+
62
+ @facets = facets;
63
+ self.cacheFacets();
64
+ end
65
+
66
+ ###
67
+ # {@inheritdoc}
68
+ ###
69
+ def facet(groupId, id)
70
+
71
+ lookupKey = AboutYou::SDK::Model::Facet.new(0, "", [], 0, "").uniqueKey(groupId, id);
72
+
73
+ return (self.facets[lookupKey]) ? self.facets[lookupKey] : nil;
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,134 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class Image
5
+ MIN_WIDTH = 50;
6
+ MIN_HEIGHT = 50;
7
+ MAX_WIDTH = 1400;
8
+ MAX_HEIGHT = 2000;
9
+
10
+ @@baseUrl
11
+ class << self
12
+ attr_accessor :baseUrl
13
+ end
14
+
15
+ # @var null|string[] */
16
+ @additionalItems;
17
+ attr_accessor :additionalItems
18
+
19
+ # @var null|string */
20
+ @angle;
21
+ attr_accessor :angle
22
+
23
+ # @var null|string */
24
+ @background;
25
+ attr_accessor :background
26
+
27
+ # @var null|string[] */
28
+ @color;
29
+ attr_accessor :color
30
+
31
+ # @var null|string */
32
+ @ext;
33
+ attr_accessor :ext
34
+
35
+ # @var null|string */
36
+ @gender;
37
+ attr_accessor :gender
38
+
39
+ # @var string */
40
+ @hash;
41
+ attr_accessor :hash
42
+
43
+ # @var ImageSize */
44
+ @imageSize;
45
+ attr_accessor :imageSize
46
+
47
+ # @var integer */
48
+ @fileSize;
49
+ attr_accessor :fileSize
50
+
51
+ # @var null|string */
52
+ @focus;
53
+ attr_accessor :focus
54
+
55
+ # @var string */
56
+ @mimeType;
57
+ attr_accessor :mimeType
58
+
59
+ # @var null|\stdClass */
60
+ @modelData;
61
+ attr_accessor :modelData
62
+
63
+ # @var null|integer */
64
+ @nextDetailLevel;
65
+ attr_accessor :nextDetailLevel
66
+
67
+ # @var null|string */
68
+ @preparation;
69
+ attr_accessor :preparation
70
+
71
+ # @var null|array */
72
+ @tags;
73
+ attr_accessor :tags
74
+
75
+ # @var null|string */
76
+ @type;
77
+ attr_accessor :type
78
+
79
+ # @var string */
80
+ @view;
81
+ attr_accessor :view
82
+
83
+
84
+ ###
85
+ # @param \stdClass $jsonObject
86
+ #
87
+ # @return static
88
+ ###
89
+ def self.createFromJson(jsonObject)
90
+
91
+ image = self.new
92
+
93
+ image.additionalItems = (jsonObject["additional_items"]) ? jsonObject["additional_items"] : nil;
94
+ image.angle = (jsonObject["angle"]) ? jsonObject["angle"] : nil;
95
+ image.background = (jsonObject["background"]) ? jsonObject["background"] : nil;
96
+ image.color = (jsonObject["color"]) ? jsonObject["color"] : nil;
97
+ image.ext = (jsonObject["ext"]) ? jsonObject["ext"] : nil;
98
+ image.fileSize = (jsonObject["size"]) ? jsonObject["size"] : 0;
99
+ image.focus = (jsonObject["focus"]) ? jsonObject["focus"] : nil;
100
+ image.gender = (jsonObject["gender"]) ? jsonObject["gender"] : nil;
101
+ image.hash = (jsonObject["hash"]) ? jsonObject["hash"] : nil;
102
+ image.mimeType = (jsonObject["mime"]) ? jsonObject["mime"] : nil;
103
+ image.modelData = (jsonObject["model_data"]) ? jsonObject["model_data"] : nil;
104
+ image.nextDetailLevel = (jsonObject["next_detail_level"]) ? jsonObject["next_detail_level"] : nil;
105
+ image.preparation = (jsonObject["preparation"]) ? jsonObject["preparation"] : nil;
106
+ image.tags = (jsonObject["tags"]) ? jsonObject["tags"] : nil;
107
+ image.type = (jsonObject["type"]) ? jsonObject["type"] : nil;
108
+ image.view = (jsonObject["view"]) ? jsonObject["view"] : nil;
109
+
110
+
111
+ image.imageSize = ImageSize.new(Integer(jsonObject["image"]["width"]), Integer(jsonObject["image"]["height"]));
112
+
113
+ return image;
114
+ end
115
+
116
+
117
+
118
+ ###
119
+ # @param int $width
120
+ # @param int $height
121
+ #
122
+ # @return string returns the relative url
123
+ ###
124
+ def url(width = 200, height = 200)
125
+
126
+ width = [[width, MAX_WIDTH].min, MIN_WIDTH].max;
127
+ height = [[height, MAX_HEIGHT].min, MIN_HEIGHT].max;
128
+
129
+ self.class.baseUrl + '/' + self.hash + '?width=' + String(width) + '&height=' + String(height);
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end