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,26 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ module AbstractModel
5
+ # @var ShopApi #
6
+ @shopApi
7
+
8
+ ###
9
+ # @param ShopApi $shopApi
10
+ ###
11
+ def shopApi=(shopApi)
12
+
13
+ @shopApi = shopApi;
14
+ end
15
+
16
+ ###
17
+ # @return ShopApi
18
+ ###
19
+ def shopApi()
20
+
21
+ @shopApi;
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class App
5
+
6
+ attr_accessor :id
7
+ attr_accessor :logoUrl
8
+ attr_accessor :name
9
+ attr_accessor :url
10
+ attr_accessor :privacyStatementUrl
11
+ attr_accessor :tosUrl
12
+
13
+
14
+ ###
15
+ # @param \stdClass $json
16
+ #
17
+ # @return static
18
+ ###
19
+ def self.createFromJson(json)
20
+
21
+ app = self.new
22
+
23
+ app.id = json["id"];
24
+ app.logoUrl = json["logo_url"]
25
+ app.name = json["name"]
26
+ app.url = json["url"]
27
+ app.privacyStatementUrl = json["privacy_statement_url"]
28
+ app.tosUrl = json["tos_url"]
29
+
30
+ return app;
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,92 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class Autocomplete
5
+
6
+ NOT_REQUESTED = nil;
7
+
8
+ ###
9
+ # @var Product[]
10
+ ###
11
+ attr_accessor :products
12
+
13
+ ###
14
+ # @var Category[]
15
+ ###
16
+ attr_accessor :categories
17
+
18
+ def initialize(categories = nil, products = nil)
19
+
20
+ self.categories = categories;
21
+ self.products = products;
22
+ end
23
+
24
+ ###
25
+ # @param \stdClass $jsonObject The autocomplete data.
26
+ # @param ModelFactoryInterface $factory
27
+ #
28
+ # @return static
29
+ ###
30
+ def self.createFromJson(jsonObject, factory)
31
+
32
+ autocomplete = self.new(parseCategories(jsonObject, factory), parseProducts(jsonObject, factory))
33
+
34
+ return autocomplete;
35
+ end
36
+
37
+ ###
38
+ # parse autocompleted categories.
39
+ #
40
+ #
41
+ # @param \stdClass $jsonObject
42
+ # @param ModelFactoryInterface $factory
43
+ #
44
+ # @return Category[]|null
45
+ ###
46
+ def self.parseCategories(jsonObject, factory)
47
+
48
+ if !(jsonObject.key?('categories'))
49
+ return NOT_REQUESTED;
50
+ end
51
+
52
+ if (jsonObject["categories"] == nil)
53
+ return Array(nil);
54
+ end
55
+
56
+ categories = Array(nil)
57
+ jsonObject["categories"].each do |category|
58
+ categories.push(factory.createCategory(category))
59
+ end
60
+
61
+ return categories;
62
+ end
63
+
64
+ ###
65
+ # parse autocompleted products.
66
+ #
67
+ # @param \stdClass $jsonObject
68
+ # @param ModelFactoryInterface $factory
69
+ #
70
+ # @return Products[]
71
+ ###
72
+ def self.parseProducts(jsonObject, factory)
73
+
74
+ if !(jsonObject.key?('products'))
75
+ return NOT_REQUESTED;
76
+ end
77
+
78
+ if (jsonObject["products"] == nil)
79
+ return Array(nil);
80
+ end
81
+
82
+ products = Array(nil);
83
+ jsonObject["products"].each do |product|
84
+ products.push(factory.createProduct(product))
85
+ end
86
+
87
+ return products;
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,262 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class Basket
5
+
6
+ attr_accessor :items
7
+ attr_accessor :errors
8
+ attr_accessor :uniqueVariantCount
9
+ attr_accessor :products
10
+ attr_accessor :totalPrice
11
+ attr_accessor :totalNet
12
+ attr_accessor :totalVat
13
+ attr_accessor :totalAmount
14
+ attr_accessor :deletedItems
15
+ attr_accessor :updatesItems
16
+
17
+
18
+ ###
19
+ # @param object $jsonObject
20
+ # @param ModelFactoryInterface $factory
21
+ #
22
+ # @return Basket
23
+ ###
24
+ def self.createFromJson(jsonObject, factory)
25
+
26
+ basket = self.new
27
+ basket.errors = Hash.new
28
+ basket.deletedItems = Hash.new
29
+ basket.updatedItems = Hash.new
30
+ basket.totalPrice = jsonObject["total_price"];
31
+ basket.totalNet = jsonObject["total_net"];
32
+ basket.totalVat = jsonObject["total_vat"]
33
+ basket.parseItems(jsonObject, factory);
34
+ basket.totalAmount = self.items.count
35
+
36
+ return basket;
37
+ end
38
+
39
+ ###
40
+ # @return boolean
41
+ ###
42
+ def hasErrors()
43
+
44
+ return self.errors.count > 0;
45
+ end
46
+
47
+ ###
48
+ # @param $itemId
49
+ #
50
+ # @return BasketItem|BasketSet|null
51
+ ###
52
+ def item(itemId)
53
+
54
+ if (self.items.key?(itemId))
55
+ return self.items[itemId]
56
+ else
57
+ return nil
58
+ end
59
+ end
60
+
61
+ def collectedItems()
62
+
63
+ items = self.items;
64
+ itemsMerged = Hash.new
65
+ items.each do |item|
66
+ key = item.uniqueKey();
67
+ if (itemsMerged.key?(key))
68
+ amount = itemsMerged[key]['amount'] + 1;
69
+ itemsMerged[key] = Hash[
70
+ 'item' => item,
71
+ 'price' => (item.totalPrice() * amount),
72
+ 'amount' => amount
73
+ ]
74
+ else
75
+ itemsMerged[key] = Hash[
76
+ 'item' => item,
77
+ 'price' => item.totalPrice(),
78
+ 'amount' => 1
79
+ ]
80
+ end
81
+ end
82
+
83
+ return itemsMerged
84
+ end
85
+
86
+ ###
87
+ # build order line for update query
88
+ # @return array
89
+ ###
90
+ def orderLinesArray()
91
+
92
+ orderLines = Array(nil)
93
+
94
+ (self.deletedItems.uniq).each do |itemId|
95
+ orderLines.push(Hash['delete' =>itemId])
96
+ end
97
+
98
+ self.updatedItems.each do |item|
99
+ orderLines.push(item)
100
+ end
101
+
102
+ return orderLines
103
+ end
104
+
105
+ def parseItems(jsonObject, factory)
106
+
107
+ products = Hash.new
108
+ if (jsonObject["products"])
109
+ jsonObject["products"].each do |key, jsonProduct|
110
+ products[key] = factory.createProduct(jsonProduct);
111
+ end
112
+ end
113
+
114
+ self.products = products;
115
+
116
+ vids = Array(nil)
117
+ if (jsonObject["order_lines"])
118
+ jsonObject["order_lines"].each do |key, jsonItem|
119
+ if (jsonItem["set_items"])
120
+ item = factory.createBasketSet(jsonItem, products);
121
+ else
122
+ vids.push(jsonItem["variantId"])
123
+ item = factory.createBasketItem(jsonItem, products);
124
+ end
125
+
126
+ if (item.hasErrors)
127
+ self.errors[key] = item;
128
+ else
129
+ self.items[item.id] = item;
130
+ end
131
+ end
132
+ end
133
+
134
+ vids = vids.uniq
135
+ self.uniqueVariantCount = vids.count;
136
+ end
137
+
138
+ ###
139
+ # Methods to manipulate basket
140
+ #
141
+ # this api is unstable method names and signatures may be changed in the future
142
+ ###
143
+
144
+
145
+ ###
146
+ # @param string $itemId
147
+ #
148
+ # @return $this
149
+ ###
150
+ def deleteItem(itemId)
151
+
152
+ self.deletedItems[itemId] = itemId;
153
+ return self
154
+ end
155
+
156
+ ###
157
+ # @param string[] $itemIds
158
+ #
159
+ # @return $this
160
+ ###
161
+ def deleteItems(itemIds)
162
+
163
+ itemIds.each do |itemId|
164
+ self.deletedItems[itemId] = itemId
165
+ end
166
+ return self
167
+ end
168
+
169
+ ###
170
+ # @return $this
171
+ ###
172
+ def deleteAllItems()
173
+
174
+ items = self.items
175
+
176
+ if !(items.empty?)
177
+ ids = Array(nil);
178
+
179
+ items.each do |item|
180
+ ids.push = item.id
181
+ end
182
+
183
+ self.deleteItems(ids)
184
+ end
185
+
186
+ return self;
187
+ end
188
+
189
+ ###
190
+ # @param BasketItem $basketItem
191
+ #
192
+ # @return $this
193
+ ###
194
+ def updateItem(basketItem)
195
+
196
+ item = Hash[
197
+ 'id' => basketItem.id,
198
+ 'variant_id' => basketItem.variantId(),
199
+ 'app_id' => basketItem.appId()
200
+ ]
201
+ additionalData = basketItem.additionalData();
202
+ if (additionalData)
203
+ self.checkAdditionData(additionalData);
204
+ item['additional_data'] = additionalData;
205
+ end
206
+
207
+ self.updatedItems[basketItem.id] = item;
208
+
209
+ return self
210
+ end
211
+
212
+ ###
213
+ # @param BasketSet $basketSet
214
+ #
215
+ # @return $this
216
+ ###
217
+ def updateItemSet(basketSet)
218
+
219
+ items = basketSet.items;
220
+
221
+ if (items.empty?)
222
+ raise 'InvalidArgumentException! BasketSet needs at least one item'
223
+ end
224
+
225
+ itemSet = Array(nil);
226
+ items.each do |subItem|
227
+ item = Hash[
228
+ 'variant_id' => subItem.variantId(),
229
+ 'app_id' => subItem.appId()
230
+ ]
231
+ additionalData = subItem.additionalData();
232
+ if (additionalData)
233
+ checkAdditionData(additionalData);
234
+ item['additional_data'] = additionalData;
235
+ end
236
+ itemSet.push = item;
237
+ end
238
+
239
+ self.updatedItems[basketSet.id] = Hash[
240
+ 'id' => basketSet.id,
241
+ 'additional_data' => basketSet.additionalData,
242
+ 'set_items' => itemSet
243
+ ]
244
+
245
+ return self;
246
+ end
247
+
248
+
249
+ def checkAdditionData(additionalData = nil, imageUrlRequired = false)
250
+
251
+ if (additionalData && !additionalData.key?('description'))
252
+ raise 'InvalidArgumentException! description is required in additional data'
253
+ end
254
+
255
+ if (additionalData.key?('internal_infos') && !(additionalData['internal_infos'].is_a? Array))
256
+ raise 'InvalidArgumentException! internal_infos must be an array'
257
+ end
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,76 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ module AbstractBasketItem
5
+
6
+ IMAGE_URL_REQUIRED = false;
7
+ ###
8
+ # Additional data are transmitted to the merchant untouched.
9
+ # If set (array not empty), a key "description" must exist. This description
10
+ # must be a string that describes the variant. If you want to pass a different image URL,
11
+ # you can add a key "image_url" to the $additionalData that contains the URL to the image.
12
+ #
13
+ # @var array $additionalData additional data for this variant
14
+ ###
15
+ attr_accessor :additionalData;
16
+ attr_accessor :isChanged
17
+
18
+ ###
19
+ # @return string|null
20
+ ###
21
+ def description()
22
+
23
+ return (self.additionalData) ?
24
+ self.additionalData['description'] :
25
+ nil
26
+ end
27
+
28
+ ###
29
+ # Additional data are transmitted to the merchant untouched.
30
+ # If set (array not empty), a key "description" must exist. This description
31
+ # must be a string that describes the variant. If you want to pass an image URL that
32
+ # represents this item set,
33
+ # you can add a key "image_url" to the $additionalData that contains the URL to the image.
34
+ #
35
+ # @return array|null additional data
36
+ ###
37
+ def additionalData()
38
+
39
+ return (self.additionalData) ?
40
+ self.additionalData :
41
+ nil
42
+ end
43
+
44
+ ###
45
+ # Additional data are transmitted to the merchant untouched.
46
+ # If set (array not empty), a key "description" must exist. This description
47
+ # must be a string that describes the variant. If you want to pass a different image URL,
48
+ # you can add a key "image_url" to the $additionalData that contains the URL to the image.
49
+ #
50
+ # @param array $additionalData additional data for this variant
51
+ #
52
+ # @throws \InvalidArgumentException
53
+ ###
54
+ def additionData=(additionalData)
55
+
56
+ self.checkAdditionData(additionalData);
57
+ self.isChanged = true;
58
+
59
+ self.additionalData = additionalData;
60
+ end
61
+
62
+ def self.checkAdditionData(additionalData = nil)
63
+
64
+ if (additionalData || IMAGE_URL_REQUIRED)
65
+ if (additionalData.key?('description'))
66
+ raise '\InvalidArgumentException! description is required in additional data'
67
+ end
68
+ if (IMAGE_URL_REQUIRED && !(additionalData.key?('image_url')))
69
+ raise '\InvalidArgumentException! image_url is required in additional data'
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end