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,100 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+
5
+ ###
6
+ # BasketItem is a class used for adding a variant item into the basket
7
+ #
8
+ # If you want to add a variant into a basket, you need to create an instance
9
+ # of a BasketItem. The BasketItem represents a variant by it's variantId.
10
+ # It can contain $additionalData that will be transmitted to the merchant untouched.
11
+ #
12
+ # Example usage:
13
+ # $variantId = $variant->getId(); // $variant is instance of \Collins\ShopApi\Model\Variant
14
+ # $basketItem = new BasketItem('my-personal-identifier', $variantId);
15
+ # $basketItem->setAdditionalData('jeans with engraving "for you"', ['engraving_text' => 'for you']);
16
+ # $shopApi->addItemToBasket(session_id(), $basketItem);
17
+ #
18
+ # @see \Collins\ShopApi\Model\Variant
19
+ # @see \Collins\ShopApi\Model\Basket
20
+ # @see \Collins\ShopApi
21
+ ###
22
+ class BasketItem
23
+ include AboutYou::SDK::Model::ResultError
24
+ include AboutYou::SDK::Model::AbstractBasketItem
25
+ include AboutYou::SDK::Model::BasketVariantItem
26
+
27
+ ###
28
+ # The ID of this basket item. You can choose this ID by yourself to identify
29
+ # your item later.
30
+ #
31
+ # @var string $id ID of this basket item
32
+ ###
33
+ attr_accessor :id;
34
+
35
+ ###
36
+ # Constructor.
37
+ #
38
+ # @param string $id
39
+ # @param integer $variantId
40
+ # @param array $additionalData
41
+ ###
42
+ def initialize(id, variantId, additionalData = nil, appId = nil)
43
+
44
+ self.checkId(id);
45
+ self.id = id;
46
+ super(variantId, additionalData, appId);
47
+ end
48
+
49
+ ###
50
+ # @param object $jsonObject The basket data.
51
+ # @param Product[] $products
52
+ #
53
+ # @return BasketItem
54
+ #
55
+ # @throws \Collins\ShopApi\Exception\UnexpectedResultException
56
+ ###
57
+ def self.createFromJson(jsonObject, products)
58
+
59
+ item = self.new(
60
+ jsonObject["id"],
61
+ jsonObject["variant_id"],
62
+ (jsonObject.key?("additional_data")) ? Array(jsonObject["additional_data"]) : nil,
63
+ (jsonObject.key?("app_id")) ? jsonObject["app_id"] : nil
64
+ )
65
+
66
+ item.parseErrorResult(jsonObject);
67
+
68
+ item.jsonObject = jsonObject;
69
+
70
+ if !(jsonObject["product_id"].empty?)
71
+ if (products.key?(jsonObject["product_id"]))
72
+ item.product=(products[jsonObject["product_id"]]);
73
+ else
74
+ raise '\Collins\ShopApi\Exception\UnexpectedResultException! Product with ID '+String(jsonObject["product_id"])+' expected but wasnt received with the basket'
75
+ end
76
+ end
77
+
78
+ jsonObject["id"] = nil
79
+ jsonObject["variant_id"] = nil
80
+ jsonObject["additional_data"] = nil
81
+ jsonObject["product_id"] = nil
82
+
83
+ return item;
84
+ end
85
+
86
+
87
+ ###
88
+ # @param mixed $id
89
+ # @throws \InvalidArgumentException
90
+ ###
91
+ def self.checkId(id)
92
+
93
+ if (!(id.is_a? String) || id.length < 2)
94
+ raise '\InvalidArgumentException! ID of the BasketSetItem must be a String that must contain minimum two characters'
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,192 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+
5
+ ###
6
+ # BasketSet is a class used for adding a set of variant items into the basket
7
+ #
8
+ # If you want to add a set of variant items into a basket, you need to create an instance
9
+ # of a BasketSet. The BasketSet contains BasketSetItems.
10
+ #
11
+ # A set can be useful if you want to sell several variants as a single product.
12
+ # For example, if you offer a pair of shoes and additionally different styles of shoelaces
13
+ # the customer can choose from, you maybe want to put both - shoes and laces - together.
14
+ #
15
+ # Example usage:
16
+ # $lacesVariantId = $lacesVariant->getId(); // $lacesVariant is instance of \Collins\ShopApi\Model\Variant
17
+ # $shoesVariantID = $shoesVariant->getId(); // $lacesVariant is instance of \Collins\ShopApi\Model\Variant
18
+ # $basketItem1 = new BasketItem($lacesVariantId);
19
+ #
20
+ # $basketSet = new BasketItemSet('my-personal-identifier');
21
+ # $basketSet->addItem(new BasketSetItem($lacesVariantId));
22
+ # $basketSet->addItem(new BasketSetItem($shoesVariantId));
23
+ # $basketSet->setAdditionalData(['description' => 'Shoes with laces "yellow star"', 'image_url' = 'http://myapp.com/shoes_yello_star.png']);
24
+ # $basket->updateItemSet($basketSet)
25
+ # $shopApi->updateBasket(session_id(), $basket);
26
+ #
27
+ # You can use the static method create as an alternative to generate a basket set:
28
+ # $basketSet = BasketItemSet::create(
29
+ # 'my-personal-identifier',
30
+ # [
31
+ # [$lacesVariant->getId()],
32
+ # [$shoesVariantID->getId()],
33
+ # ]
34
+ # );
35
+ # @see create()
36
+ #
37
+ # @see \Collins\ShopApi\Model\Basket
38
+ # @see \Collins\ShopApi\Model\Basket\BasketSetItem
39
+ # @see \Collins\ShopApi\Model\Variant
40
+ # @see \Collins\ShopApi
41
+ ###
42
+ class BasketSet
43
+ include AboutYou::SDK::Model::ResultError
44
+ include AboutYou::SDK::Model::AbstractBasketItem
45
+
46
+ IMAGE_URL_REQUIRED = true;
47
+
48
+ ###
49
+ # The ID of this basket item. You can choose this ID by yourself to identify
50
+ # your item later.
51
+ #
52
+ # @var string $id ID of this basket item
53
+ ###
54
+ attr_accessor :id;
55
+ attr_accessor :items
56
+ attr_accessor :errors;
57
+ attr_accessor :totalPrice;
58
+ attr_accessor :totalNet
59
+ attr_accessor :totalVat
60
+ attr_accessor :itemAppId
61
+
62
+
63
+ ###
64
+ # Additional data are transmitted to the merchant untouched.
65
+ # If set (array not empty), a key "description" must exist. This description
66
+ # must be a string that describes the variant. If you want to pass an image URL that
67
+ # represents this item set,
68
+ # you can add a key "image_url" to the $additionalData that contains the URL to the image.
69
+ #
70
+ # @param string $id ID of the basket item set.
71
+ # @param array $additionalData additional data for this item set
72
+ ###
73
+ def initialize(id, additionalData = nil)
74
+
75
+ self.checkId(id);
76
+ self.checkAdditionData(additionalData, true);
77
+ self.id = id;
78
+ self.additionalData = additionalData;
79
+ end
80
+
81
+ ###
82
+ # @param \stdClass $jsonObject
83
+ # @param ModelFactoryInterface $factory
84
+ # @param Product[] $products
85
+ #
86
+ # @return BasketSet
87
+ ###
88
+ def self.createFromJson(jsonObject, factory, products)
89
+
90
+ set = self.new(jsonObject["id"], (jsonObject.key?("additional_data") ? Array(jsonObject["additional_data"]) : nil));
91
+
92
+ set.parseErrorResult(jsonObject);
93
+
94
+ jsonObject["set_items"].each do |index, jsonItem|
95
+ item = factory.createBasketSetItem(jsonItem, products);
96
+ if (item.hasErrors)
97
+ set.errors[index] = item;
98
+ else
99
+ set.items[index] = item;
100
+ end
101
+ end
102
+
103
+ set.totalPrice = (jsonObject.key?("total_price") ? jsonObject["total_price"] : nil)
104
+ set.totalNet = (jsonObject.key?("total_net") ? jsonObject["total_net"] : nil)
105
+ set.totalVat = (jsonObject.key?("total_vat") ? jsonObject["total_vat"] : nil)
106
+
107
+ return set;
108
+ end
109
+
110
+ ###
111
+ # Create an basket item set from an array, for example:
112
+ # BasketSet::create(
113
+ # 'identifier4',
114
+ # [
115
+ # [12312121],
116
+ # [7777777, ['description' => 'engravingssens', 'internal_infos' => ['stuff']]]
117
+ # ],
118
+ # ['description' => 'Wunderschön und so']
119
+ # );
120
+ #
121
+ # @param $itemId
122
+ # @param $subItems
123
+ # @param array $additionalData
124
+ #
125
+ # @return BasketSet
126
+ ###
127
+ def self.create(itemId, subItems, additionalData = nil)
128
+
129
+ set = self.new(itemId, additionalData);
130
+ subItems.each do |itemData|
131
+ set.addItem(AboutYou::SDK::Model::BasketSetItem.new(itemData[0], (itemData[1]) ? itemData[1] : nil));
132
+ end
133
+
134
+ return set;
135
+ end
136
+
137
+ ###
138
+ # @param BasketSetItem $item
139
+ ###
140
+ def addItem(item)
141
+
142
+ if (self.items.count == 0)
143
+ self.itemAppId= item.appId();
144
+ elsif (self.itemAppId != item.appId)
145
+ raise '\InvalidArgumentException! you can not set different app ids for items in an item-set.'
146
+ end
147
+
148
+ self.items.push(item);
149
+ end
150
+
151
+
152
+ ###
153
+ # @return boolean
154
+ ###
155
+ def hasErrors()
156
+
157
+ return self.errorCode || self.errors.count > 0;
158
+ end
159
+
160
+
161
+ def uniqueKey()
162
+
163
+ key = ':';
164
+ additionalData = self.additionalData;
165
+ if !(additionalData)
166
+ additionalData.sort!
167
+ key = key + ':' + additionalData.to_json
168
+ end
169
+
170
+ items = Array(nil);
171
+ self.items.each do |item|
172
+ items.push(item.uniqueKey);
173
+ end
174
+ key = key + items.to_json;
175
+
176
+ return key;
177
+ end
178
+
179
+ ###
180
+ # @param mixed $id
181
+ # @throws \InvalidArgumentException
182
+ ###
183
+ def checkId(id)
184
+
185
+ if (!(id.is_a? String) || id.length < 2)
186
+ raise '\InvalidArgumentException! ID of the BasketSetItem must be a String that must contain minimum two characters'
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,46 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class BasketSetItem
5
+ include AboutYou::SDK::Model::BasketVariantItem
6
+
7
+ ERROR_CODE_PRODUCT_NOT_INCLUDED = 1001;
8
+
9
+ ###
10
+ # @param object $jsonObject The basket data.
11
+ # @param Product[] $products
12
+ #
13
+ # @return BasketVariantItem
14
+ #
15
+ # @throws \Collins\ShopApi\Exception\UnexpectedResultException
16
+ ###
17
+ def self.createFromJson(jsonObject, products)
18
+
19
+ item = self.new(
20
+ jsonObject["variant_id"],
21
+ (jsonObject.key?("additional_data") ? Array(jsonObject["additional_data"]) :nil),
22
+ (jsonObject.key?("app_id") ? jsonObject["app_id"] :nil)
23
+ );
24
+
25
+ item.parseErrorResult(jsonObject);
26
+
27
+ item.jsonObject = jsonObject;
28
+
29
+ if (jsonObject["product_id"] != nil)
30
+ if (products.key?(jsonObject["product_id"]))
31
+ item.product=(products[jsonObject["product_id"]]);
32
+ else
33
+ item.errorCode = ERROR_CODE_PRODUCT_NOT_INCLUDED;
34
+ item.errorMessage = 'Product with ID '+jsonObject["product_id"]+' expected but wasnt received with the basket';
35
+ end
36
+ end
37
+ jsonObject["variant_id"] = nil
38
+ jsonObject["additional_data"] = nil
39
+ jsonObject["product_id"] = nil
40
+
41
+ return item;
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,137 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ module BasketVariantItem
5
+
6
+ attr_accessor :jsonObject
7
+ attr_accessor :product
8
+ attr_accessor :variant
9
+ attr_accessor :variantId
10
+ attr_accessor :appId
11
+
12
+ ###
13
+ # Constructor.
14
+ #
15
+ # @param integer $variantId
16
+ # @param array $additionalData
17
+ ###
18
+ def initialize(variantId, additionalData = nil, appId = nil)
19
+
20
+ self.checkVariantId(variantId);
21
+ self.checkAdditionData(additionalData);
22
+ self.variantId = variantId;
23
+ self.additionalData = additionalData;
24
+
25
+ if (appId)
26
+ self.checkAppId(appId);
27
+ self.appId = appId;
28
+ end
29
+ end
30
+
31
+ ###
32
+ # @return boolean
33
+ ###
34
+ def hasErrors()
35
+
36
+ return self.errorCode > 0;
37
+ end
38
+
39
+ ###
40
+ # Get the total price.
41
+ #
42
+ # @return integer
43
+ ###
44
+ def totalPrice()
45
+
46
+ return self.jsonObject["total_price"];
47
+ end
48
+
49
+ ###
50
+ # Get the tax.
51
+ #
52
+ # @return integer
53
+ ###
54
+ def tax()
55
+
56
+ return self.jsonObject["tax"];
57
+ end
58
+
59
+
60
+ ###
61
+ # Get the value added tax.
62
+ #
63
+ # @return integer
64
+ ###
65
+ def totalVat()
66
+
67
+ return self.jsonObject["total_vat"];
68
+ end
69
+
70
+ ###
71
+ # @return integer
72
+ ###
73
+ def totalNet()
74
+
75
+ return self.jsonObject["total_net"];
76
+ end
77
+
78
+
79
+ ###
80
+ # Get the variant old price in euro cents.
81
+ #
82
+ # @return integer
83
+ ###
84
+ def oldPrice()
85
+
86
+ return self.variant.oldPrice();
87
+ end
88
+
89
+
90
+ ###
91
+ # Get the product variant.
92
+ #
93
+ # @return Variant
94
+ ###
95
+ def variant()
96
+
97
+ if !(self.variant)
98
+ self.variant = (self.product) ?
99
+ self.product.variantById(self.variantId) :
100
+ nil
101
+ end
102
+
103
+ return self.variant;
104
+ end
105
+
106
+
107
+ ###
108
+ # @return string
109
+ ###
110
+ def uniqueKey()
111
+
112
+ key = self.variantId();
113
+ additionalData = self.additionalData
114
+ if(additionalData)
115
+ additionalData.sort!
116
+ key = key + ':' + additionalData.to_json;
117
+ end
118
+ return key;
119
+ end
120
+
121
+ def checkVariantId(variantId)
122
+
123
+ if !(Integer(variantId))
124
+ raise '\InvalidArgumentException! the variant id must be an integer'
125
+ end
126
+ end
127
+
128
+ def checkAppId(appId)
129
+
130
+ if !(Integer(appId))
131
+ raise '\InvalidArgumentException! the app id must be an integer'
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end