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
@@ -1,134 +0,0 @@
1
- module AboutYou
2
- module SDK
3
- ###
4
- # This Class manages the API-Calls
5
- #
6
- # Author:: Collins GmbH & Co KG
7
- ###
8
- class Client
9
-
10
- # url for staging-api-requests
11
- API_END_POINT_STAGE = 'http://shop-api.staging.aboutyou.de/api'
12
- # url for sandbox-api-requests
13
- API_END_POINT_SANDBOX = 'http://shop-api.sandbox.aboutyou.de/api'
14
- # url for live-api-requests
15
- API_END_POINT_LIVE = 'https://shop-api.aboutyou.de/api'
16
-
17
- # the app id of the app which should be represented by an instance of AY
18
- attr_accessor :appId
19
- # the authentifaction token from dev-center for the app id
20
- attr_accessor :appPassword
21
- # the url used for api calls
22
- attr_accessor :apiEndPoint
23
- # the page id of the current page visited by an user
24
- attr_accessor :pageId
25
-
26
-
27
- ###
28
- # the Constructor for the Client class
29
- #
30
- # * *Args* :
31
- # - +appId+ -> The App-Id of the App
32
- # - +appPassword+ -> The Auth-Token of the App
33
- # - +apiEndPoint+ -> Can be either live or staging
34
- # - +logger+ -> Logger-Template
35
- #
36
- # * *Returns* :
37
- # - Instance of AboutYou::SDK::Client
38
- ###
39
- def initialize(appId, appPassword, apiEndPoint = 'stage', logger = nil)
40
-
41
- self.appId = appId
42
- self.appPassword = appPassword
43
- end
44
-
45
-
46
- ###
47
- # Setter for app-credentials
48
- #
49
- # * *Args* :
50
- # - +appId+ -> The App-Id of the App
51
- # - +appPassword+ -> The Auth-Token of the App
52
- ###
53
- def appCredentials=(appId, appPassword)
54
-
55
- self.appId= appId
56
- self.appPassword= appPassword
57
- end
58
-
59
-
60
- ###
61
- # Setter for the api endpoint
62
- #
63
- # * *Args* :
64
- # - +apiEndPoint+ -> Can be either live or staging
65
- ###
66
- def apiEndpoint=(apiEndPoint)
67
-
68
- case
69
- when apiEndPoint=='stage'
70
- self.apiEndPoint = API_END_POINT_STAGE
71
- when apiEndPoint=='sandbox'
72
- self.apiEndPoint = API_END_POINT_SANDBOX
73
- when apiEndPoint=='live'
74
- self.apiEndPoint = API_END_POINT_LIVE
75
- else
76
- self.apiEndPoint = apiEndPoint
77
- end
78
- end
79
-
80
-
81
- ###
82
- # Builds a JSON string representing the request-data
83
- # Executes the API request
84
- # builds a JSON string representing the response-data
85
- #
86
- # * *Args* :
87
- # - +body+ -> the body of the api-call, containing all request data
88
- #
89
- # * *Returns* :
90
- # - Json-String containing the response-body
91
- ###
92
- def request(body)
93
-
94
- if self.pageId
95
- request = {
96
- :body=>body,
97
- :basic_auth => {
98
- :username => self.appId,
99
- :password => self.appPassword
100
- },
101
- :headers => {
102
- 'Content-Type' => 'application/json',
103
- 'Accept-Encoding' => 'gzip,deflate',
104
- 'X-Page-ID'=> self.pageId
105
- }
106
- }
107
- else
108
- request = {
109
- :body=>body,
110
- :basic_auth => {
111
- :username => self.appId,
112
- :password => self.appPassword
113
- },
114
- :headers => {
115
- 'Content-Type' => 'application/json',
116
- 'Accept-Encoding' => 'gzip,deflate'
117
- }
118
- }
119
- end
120
-
121
- response = HTTParty.post("https://shop-api.aboutyou.de/api", request)
122
-
123
- unless response.code >= 200 && response.code < 300 || response.code == 304
124
- raise String(response.code)
125
- unless response.is_a? Array
126
- raise 'result is not array'
127
- end
128
- end
129
-
130
- JSON.parse(response.body)
131
- end
132
- end
133
- end
134
- end
@@ -1,268 +0,0 @@
1
- module AboutYou
2
- module SDK
3
- module Model
4
- ###
5
- # This Class represents a basket model
6
- #
7
- # author:: Collins GmbH & Co KG
8
- ###
9
- class Basket
10
- # array of items in the basket
11
- attr_accessor :items
12
- # errors of the basket
13
- attr_accessor :errors
14
- attr_accessor :uniqueVariantCount
15
- attr_accessor :products
16
- attr_accessor :totalPrice
17
- attr_accessor :totalNet
18
- attr_accessor :totalVat
19
- attr_accessor :totalAmount
20
- attr_accessor :deletedItems
21
- attr_accessor :updatesItems
22
-
23
-
24
- ###
25
- # @param object $jsonObject
26
- # @param ModelFactoryInterface $factory
27
- #
28
- # @return Basket
29
- ###
30
- def self.createFromJson(jsonObject, factory)
31
-
32
- basket = self.new
33
- basket.errors = Hash.new
34
- basket.deletedItems = Hash.new
35
- basket.updatedItems = Hash.new
36
- basket.totalPrice = jsonObject["total_price"];
37
- basket.totalNet = jsonObject["total_net"];
38
- basket.totalVat = jsonObject["total_vat"]
39
- basket.parseItems(jsonObject, factory);
40
- basket.totalAmount = self.items.count
41
-
42
- return basket;
43
- end
44
-
45
- ###
46
- # @return boolean
47
- ###
48
- def hasErrors()
49
-
50
- return self.errors.count > 0;
51
- end
52
-
53
- ###
54
- # @param $itemId
55
- #
56
- # @return BasketItem|BasketSet|null
57
- ###
58
- def item(itemId)
59
-
60
- if (self.items.key?(itemId))
61
- return self.items[itemId]
62
- else
63
- return nil
64
- end
65
- end
66
-
67
- def collectedItems()
68
-
69
- items = self.items;
70
- itemsMerged = Hash.new
71
- items.each do |item|
72
- key = item.uniqueKey();
73
- if (itemsMerged.key?(key))
74
- amount = itemsMerged[key]['amount'] + 1;
75
- itemsMerged[key] = Hash[
76
- 'item' => item,
77
- 'price' => (item.totalPrice() * amount),
78
- 'amount' => amount
79
- ]
80
- else
81
- itemsMerged[key] = Hash[
82
- 'item' => item,
83
- 'price' => item.totalPrice(),
84
- 'amount' => 1
85
- ]
86
- end
87
- end
88
-
89
- return itemsMerged
90
- end
91
-
92
- ###
93
- # build order line for update query
94
- # @return array
95
- ###
96
- def orderLinesArray()
97
-
98
- orderLines = Array(nil)
99
-
100
- (self.deletedItems.uniq).each do |itemId|
101
- orderLines.push(Hash['delete' =>itemId])
102
- end
103
-
104
- self.updatedItems.each do |item|
105
- orderLines.push(item)
106
- end
107
-
108
- return orderLines
109
- end
110
-
111
- def parseItems(jsonObject, factory)
112
-
113
- products = Hash.new
114
- if (jsonObject["products"])
115
- jsonObject["products"].each do |key, jsonProduct|
116
- products[key] = factory.createProduct(jsonProduct);
117
- end
118
- end
119
-
120
- self.products = products;
121
-
122
- vids = Array(nil)
123
- if (jsonObject["order_lines"])
124
- jsonObject["order_lines"].each do |key, jsonItem|
125
- if (jsonItem["set_items"])
126
- item = factory.createBasketSet(jsonItem, products);
127
- else
128
- vids.push(jsonItem["variantId"])
129
- item = factory.createBasketItem(jsonItem, products);
130
- end
131
-
132
- if (item.hasErrors)
133
- self.errors[key] = item;
134
- else
135
- self.items[item.id] = item;
136
- end
137
- end
138
- end
139
-
140
- vids = vids.uniq
141
- self.uniqueVariantCount = vids.count;
142
- end
143
-
144
- ###
145
- # Methods to manipulate basket
146
- #
147
- # this api is unstable method names and signatures may be changed in the future
148
- ###
149
-
150
-
151
- ###
152
- # @param string $itemId
153
- #
154
- # @return $this
155
- ###
156
- def deleteItem(itemId)
157
-
158
- self.deletedItems[itemId] = itemId;
159
- return self
160
- end
161
-
162
- ###
163
- # @param string[] $itemIds
164
- #
165
- # @return $this
166
- ###
167
- def deleteItems(itemIds)
168
-
169
- itemIds.each do |itemId|
170
- self.deletedItems[itemId] = itemId
171
- end
172
- return self
173
- end
174
-
175
- ###
176
- # @return $this
177
- ###
178
- def deleteAllItems()
179
-
180
- items = self.items
181
-
182
- if !(items.empty?)
183
- ids = Array(nil);
184
-
185
- items.each do |item|
186
- ids.push = item.id
187
- end
188
-
189
- self.deleteItems(ids)
190
- end
191
-
192
- return self;
193
- end
194
-
195
- ###
196
- # @param BasketItem $basketItem
197
- #
198
- # @return $this
199
- ###
200
- def updateItem(basketItem)
201
-
202
- item = Hash[
203
- 'id' => basketItem.id,
204
- 'variant_id' => basketItem.variantId(),
205
- 'app_id' => basketItem.appId()
206
- ]
207
- additionalData = basketItem.additionalData();
208
- if (additionalData)
209
- self.checkAdditionData(additionalData);
210
- item['additional_data'] = additionalData;
211
- end
212
-
213
- self.updatedItems[basketItem.id] = item;
214
-
215
- return self
216
- end
217
-
218
- ###
219
- # @param BasketSet $basketSet
220
- #
221
- # @return $this
222
- ###
223
- def updateItemSet(basketSet)
224
-
225
- items = basketSet.items;
226
-
227
- if (items.empty?)
228
- raise 'InvalidArgumentException! BasketSet needs at least one item'
229
- end
230
-
231
- itemSet = Array(nil);
232
- items.each do |subItem|
233
- item = Hash[
234
- 'variant_id' => subItem.variantId(),
235
- 'app_id' => subItem.appId()
236
- ]
237
- additionalData = subItem.additionalData();
238
- if (additionalData)
239
- checkAdditionData(additionalData);
240
- item['additional_data'] = additionalData;
241
- end
242
- itemSet.push = item;
243
- end
244
-
245
- self.updatedItems[basketSet.id] = Hash[
246
- 'id' => basketSet.id,
247
- 'additional_data' => basketSet.additionalData,
248
- 'set_items' => itemSet
249
- ]
250
-
251
- return self;
252
- end
253
-
254
-
255
- def checkAdditionData(additionalData = nil, imageUrlRequired = false)
256
-
257
- if (additionalData && !additionalData.key?('description'))
258
- raise 'InvalidArgumentException! description is required in additional data'
259
- end
260
-
261
- if (additionalData.key?('internal_infos') && !(additionalData['internal_infos'].is_a? Array))
262
- raise 'InvalidArgumentException! internal_infos must be an array'
263
- end
264
- end
265
- end
266
- end
267
- end
268
- end
@@ -1,76 +0,0 @@
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