aboutyou-sdk 0.0.29 → 0.0.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/AboutYou/CacheProvider/dalli.rb +3 -0
- data/lib/AboutYou/Criteria/product_fields.rb +3 -0
- data/lib/AboutYou/Criteria/product_search_criteria.rb +8 -8
- data/lib/AboutYou/Factory/default_model_factory.rb +15 -2
- data/lib/AboutYou/Model/Basket/abstract_basket_item.rb +25 -20
- data/lib/AboutYou/Model/Basket/basket_item.rb +27 -27
- data/lib/AboutYou/Model/Basket/basket_set.rb +60 -62
- data/lib/AboutYou/Model/Basket/basket_set_item.rb +8 -9
- data/lib/AboutYou/Model/Basket/basket_variant_item.rb +55 -21
- data/lib/AboutYou/Model/ProductSearchResult/facet_count.rb +0 -2
- data/lib/AboutYou/Model/ProductSearchResult/price_range.rb +2 -2
- data/lib/AboutYou/Model/abstract_model.rb +5 -3
- data/lib/AboutYou/Model/app.rb +0 -2
- data/lib/AboutYou/Model/autocomplete.rb +0 -2
- data/lib/AboutYou/Model/basket.rb +91 -19
- data/lib/AboutYou/Model/brand.rb +8 -4
- data/lib/AboutYou/Model/categories_result.rb +13 -2
- data/lib/AboutYou/Model/category.rb +45 -19
- data/lib/AboutYou/Model/category_tree.rb +21 -7
- data/lib/AboutYou/Model/facet.rb +44 -22
- data/lib/AboutYou/Model/facet_group.rb +55 -21
- data/lib/AboutYou/Model/facet_group_set.rb +106 -23
- data/lib/AboutYou/Model/image.rb +36 -25
- data/lib/AboutYou/Model/image_size.rb +8 -5
- data/lib/AboutYou/Model/initiate_order.rb +26 -7
- data/lib/AboutYou/Model/order.rb +12 -2
- data/lib/AboutYou/Model/product.rb +261 -5
- data/lib/AboutYou/Model/product_search_result.rb +40 -10
- data/lib/AboutYou/Model/{products_ean_result.rb → products_eans_result.rb} +11 -5
- data/lib/AboutYou/Model/products_result.rb +13 -14
- data/lib/AboutYou/Model/result_error.rb +18 -2
- data/lib/AboutYou/Model/variant.rb +87 -26
- data/lib/AboutYou/Model/variants_result.rb +31 -15
- data/lib/AboutYou/client.rb +7 -0
- data/lib/AboutYou/query.rb +7 -2
- data/lib/AboutYou/query_builder.rb +22 -3
- data/lib/aboutyou-sdk.rb +7 -0
- metadata +3 -3
@@ -3,23 +3,22 @@ module AboutYou
|
|
3
3
|
module Model
|
4
4
|
###
|
5
5
|
# BasketSetItem is a class used for adding a variant set item into the basket
|
6
|
-
#
|
7
|
-
# @see \Collins\ShopApi\Model\Variant
|
8
|
-
# @see \Collins\ShopApi\Model\Basket
|
9
|
-
# @see \Collins\ShopApi
|
10
6
|
###
|
11
7
|
class BasketSetItem
|
12
8
|
include AboutYou::SDK::Model::BasketVariantItem
|
13
|
-
|
9
|
+
# erorr code if a product is not included
|
14
10
|
ERROR_CODE_PRODUCT_NOT_INCLUDED = 1001
|
15
11
|
|
16
12
|
###
|
17
|
-
#
|
18
|
-
#
|
13
|
+
# This method is used for creating a basket set item from a given api json
|
14
|
+
# response. It is best practice to use this method.
|
19
15
|
#
|
20
|
-
#
|
16
|
+
# * *Args* :
|
17
|
+
# - +json_object+ -> the api response key
|
18
|
+
# - +products+ -> Array of products
|
21
19
|
#
|
22
|
-
#
|
20
|
+
# * *Returns* :
|
21
|
+
# - an instance of AboutYou::SDK::Model::BasketSetItem
|
23
22
|
###
|
24
23
|
def create_from_json(json_object, products)
|
25
24
|
item = new(
|
@@ -3,23 +3,29 @@ module AboutYou
|
|
3
3
|
module Model
|
4
4
|
###
|
5
5
|
# BasketVairantItem is a class representing a basket variant item
|
6
|
-
#
|
7
|
-
# @see \Collins\ShopApi\Model\Variant
|
8
|
-
# @see \Collins\ShopApi\Model\Basket
|
9
|
-
# @see \Collins\ShopApi
|
10
6
|
###
|
11
7
|
module BasketVariantItem
|
8
|
+
# the json object from which this instance was created from
|
12
9
|
attr_accessor :json_object
|
10
|
+
# the product of this variant item
|
13
11
|
attr_accessor :product
|
12
|
+
# the variant of this variant item
|
14
13
|
attr_accessor :variant
|
14
|
+
# the variant id of this variant item
|
15
15
|
attr_accessor :variant_id
|
16
|
+
# the app id of this variant item
|
16
17
|
attr_accessor :app_id
|
17
18
|
|
18
19
|
###
|
19
|
-
# Constructor
|
20
|
+
# Constructor for the AboutYou::SDK::Model::BasketVariantItem class
|
20
21
|
#
|
21
|
-
#
|
22
|
-
#
|
22
|
+
# * *Args* :
|
23
|
+
# - +variant_id+ -> the id of the variant item
|
24
|
+
# - +additional_data+ -> additional data of the variant item
|
25
|
+
# - +app_id+ -> the app id for the variant item
|
26
|
+
#
|
27
|
+
# * *Returns* :
|
28
|
+
# - an instance of AboutYou::SDK::Model::BasketVariantItem
|
23
29
|
###
|
24
30
|
def initialize(variant_id, additional_data = nil, app_id = nil)
|
25
31
|
check_variant_id(variant_id)
|
@@ -27,66 +33,79 @@ module AboutYou
|
|
27
33
|
self.variant_od = variant_id
|
28
34
|
self.additional_data = additional_data
|
29
35
|
|
30
|
-
return unless app_id
|
36
|
+
return self unless app_id
|
31
37
|
|
32
38
|
check_app_id(app_id)
|
33
39
|
self.app_id = app_id
|
40
|
+
|
41
|
+
self
|
34
42
|
end
|
35
43
|
|
36
44
|
###
|
37
|
-
#
|
45
|
+
# This method checks if there are errors in the variant item
|
46
|
+
#
|
47
|
+
# * *Returns* :
|
48
|
+
# - Boolean determining whether there are errors or not
|
38
49
|
###
|
39
50
|
def errors?
|
40
51
|
error_code > 0
|
41
52
|
end
|
42
53
|
|
43
54
|
###
|
44
|
-
#
|
55
|
+
# Getter for the total price
|
45
56
|
#
|
46
|
-
#
|
57
|
+
# * *Returns* :
|
58
|
+
# - an Integer containing the total price
|
47
59
|
###
|
48
60
|
def total_price
|
49
61
|
json_object['total_price']
|
50
62
|
end
|
51
63
|
|
52
64
|
###
|
53
|
-
#
|
65
|
+
# Getter for the tax
|
54
66
|
#
|
55
|
-
#
|
67
|
+
# * *Returns* :
|
68
|
+
# - an Integer containing the tax
|
56
69
|
###
|
57
70
|
def tax
|
58
71
|
json_object['tax']
|
59
72
|
end
|
60
73
|
|
61
74
|
###
|
62
|
-
#
|
75
|
+
# Getter for the total vat
|
63
76
|
#
|
64
|
-
#
|
77
|
+
# * *Returns* :
|
78
|
+
# - an Integer containing the total vat
|
65
79
|
###
|
66
80
|
def total_vat
|
67
81
|
json_object['total_vat']
|
68
82
|
end
|
69
83
|
|
70
84
|
###
|
71
|
-
#
|
85
|
+
# Getter for the total net
|
86
|
+
#
|
87
|
+
# * *Returns* :
|
88
|
+
# - an Integer containing the total net
|
72
89
|
###
|
73
90
|
def total_net
|
74
91
|
json_object['total_net']
|
75
92
|
end
|
76
93
|
|
77
94
|
###
|
78
|
-
#
|
95
|
+
# Getter for the old price of the variant
|
79
96
|
#
|
80
|
-
#
|
97
|
+
# * *Returns* :
|
98
|
+
# - an Integer containing the old price of the variant
|
81
99
|
###
|
82
100
|
def old_price
|
83
101
|
variant.old_price
|
84
102
|
end
|
85
103
|
|
86
104
|
###
|
87
|
-
#
|
105
|
+
# Getter for the variant
|
88
106
|
#
|
89
|
-
#
|
107
|
+
# * *Returns* :
|
108
|
+
# - an instance of AboutYou::SDK::Model::Variant
|
90
109
|
###
|
91
110
|
def variant
|
92
111
|
self.variant = product.variant_by_id(variant_id) unless
|
@@ -96,7 +115,10 @@ module AboutYou
|
|
96
115
|
end
|
97
116
|
|
98
117
|
###
|
99
|
-
#
|
118
|
+
# This method is used for creating a unique key for the basket set
|
119
|
+
#
|
120
|
+
# * *Returns* :
|
121
|
+
# - a String containing a unique key for the basket set
|
100
122
|
###
|
101
123
|
def unique_key
|
102
124
|
key = variant_id
|
@@ -108,11 +130,23 @@ module AboutYou
|
|
108
130
|
key
|
109
131
|
end
|
110
132
|
|
133
|
+
###
|
134
|
+
# This method checks if a variant id is valid
|
135
|
+
#
|
136
|
+
# * *Fails* :
|
137
|
+
# - if variant_id is not an integer
|
138
|
+
###
|
111
139
|
def check_variant_id(variant_id)
|
112
140
|
fail '\InvalidArgumentException! the variant id must be
|
113
141
|
an integer' unless variant_id.is_a?(Integer)
|
114
142
|
end
|
115
143
|
|
144
|
+
###
|
145
|
+
# This method checks if an app id is valid
|
146
|
+
#
|
147
|
+
# * *Fails* :
|
148
|
+
# - if app_id is not an integer
|
149
|
+
###
|
116
150
|
def check_app_id(app_id)
|
117
151
|
fail '\InvalidArgumentException! the app id must be
|
118
152
|
an integer' unless app_id.is_a?(Integer)
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module AboutYou
|
2
2
|
module SDK
|
3
|
+
###
|
4
|
+
# The Model namespace
|
5
|
+
###
|
3
6
|
module Model
|
4
7
|
###
|
5
|
-
# This Module
|
6
|
-
#
|
7
|
-
# author:: Collins GmbH & Co KG
|
8
|
+
# This Module represents a model which has a shop_api attribute
|
8
9
|
###
|
9
10
|
module AbstractModel
|
11
|
+
# instance of AY
|
10
12
|
attr_accessor :shop_api
|
11
13
|
end
|
12
14
|
end
|
data/lib/AboutYou/Model/app.rb
CHANGED
@@ -3,28 +3,38 @@ module AboutYou
|
|
3
3
|
module Model
|
4
4
|
###
|
5
5
|
# This Class represents a basket model
|
6
|
-
#
|
7
|
-
# author:: Collins GmbH & Co KG
|
8
6
|
###
|
9
7
|
class Basket
|
10
8
|
# array of items in the basket
|
11
9
|
attr_accessor :items
|
12
10
|
# errors of the basket
|
13
11
|
attr_accessor :errors
|
12
|
+
# Integer count of unique variants
|
14
13
|
attr_accessor :unique_variant_count
|
14
|
+
# Array of products
|
15
15
|
attr_accessor :products
|
16
|
+
# Integer containing the total price of the basket
|
16
17
|
attr_accessor :total_price
|
18
|
+
# Integer containing the total net woth of the basket
|
17
19
|
attr_accessor :total_net
|
20
|
+
# Integer containing the total vat woth of the basket
|
18
21
|
attr_accessor :total_vat
|
22
|
+
# Integer containing the total amount of the basket
|
19
23
|
attr_accessor :total_amount
|
24
|
+
# Array containing the deleted items in the basket
|
20
25
|
attr_accessor :deleted_items
|
26
|
+
# Array containing the updated items in the basket
|
21
27
|
attr_accessor :updated_items
|
22
28
|
|
23
29
|
###
|
24
|
-
#
|
25
|
-
# @param ModelFactoryInterface $factory
|
30
|
+
# This method is used for creating an instance of this class by a json_object.
|
26
31
|
#
|
27
|
-
#
|
32
|
+
# * *Args* :
|
33
|
+
# - +json_object+ -> the json_object received from the api
|
34
|
+
# - +factory+ -> instance of AboutYou::SDK::Factory::DefaultModelFactory
|
35
|
+
#
|
36
|
+
# * *Returns* :
|
37
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
28
38
|
###
|
29
39
|
def self.create_from_json(json_object, factory)
|
30
40
|
basket = new
|
@@ -41,21 +51,38 @@ module AboutYou
|
|
41
51
|
end
|
42
52
|
|
43
53
|
###
|
44
|
-
#
|
54
|
+
# This method checks if there are errors in the basket set
|
55
|
+
#
|
56
|
+
# * *Returns* :
|
57
|
+
# - Boolean determining whether there are errors or not
|
45
58
|
###
|
46
59
|
def errors?
|
47
60
|
errors.count > 0
|
48
61
|
end
|
49
62
|
|
50
63
|
###
|
51
|
-
#
|
64
|
+
# This method gets an item from the basket for a given item id
|
65
|
+
#
|
66
|
+
# * *Args* :
|
67
|
+
# - +item_id+ -> the id used for searching in the basket
|
52
68
|
#
|
53
|
-
#
|
69
|
+
# * *Returns* :
|
70
|
+
# - instance of AboutYou::SDK::Model::BasketItem or null if not found
|
54
71
|
###
|
55
72
|
def item(item_id)
|
56
73
|
return items[item_id] if items.key?(item_id)
|
57
74
|
end
|
58
75
|
|
76
|
+
###
|
77
|
+
# This methods creates a Hash containing pairs of
|
78
|
+
# unique_item_key => instance of AboutYou::SDK::Model::BasketItem
|
79
|
+
# It only contains 1 entry per unique_item_key and will increase the amount
|
80
|
+
# if more items are given
|
81
|
+
#
|
82
|
+
# * *Returns* :
|
83
|
+
# - Hash containing pairs of
|
84
|
+
# unique_item_key => instance of AboutYou::SDK::Model::BasketItem
|
85
|
+
###
|
59
86
|
def collected_items
|
60
87
|
items = self.items
|
61
88
|
items_merged = {}
|
@@ -81,8 +108,11 @@ module AboutYou
|
|
81
108
|
end
|
82
109
|
|
83
110
|
###
|
84
|
-
#
|
85
|
-
#
|
111
|
+
# This method builds the order lines for the update query
|
112
|
+
#
|
113
|
+
# * *Returns* :
|
114
|
+
# - Array containing either Hashes with pairs of 'delete' => item_id
|
115
|
+
# or instances of AboutYou::SDK::Model::BasketItem
|
86
116
|
###
|
87
117
|
def order_lines_array
|
88
118
|
order_lines = []
|
@@ -98,6 +128,16 @@ module AboutYou
|
|
98
128
|
order_lines
|
99
129
|
end
|
100
130
|
|
131
|
+
###
|
132
|
+
# This method is used for parsing the items in the basket
|
133
|
+
#
|
134
|
+
# * *Args* :
|
135
|
+
# - +json_object+ -> the json object received from the api
|
136
|
+
# - +factory+ -> Instance of AboutYou::SDK::Factory::DefaultModelFactory
|
137
|
+
#
|
138
|
+
# * *Returns* :
|
139
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
140
|
+
###
|
101
141
|
def parse_items(json_object, factory)
|
102
142
|
products = {}
|
103
143
|
|
@@ -125,12 +165,18 @@ module AboutYou
|
|
125
165
|
|
126
166
|
vids = vids.uniq
|
127
167
|
self.uniqueVariantCount = vids.count
|
168
|
+
|
169
|
+
self
|
128
170
|
end
|
129
171
|
|
130
172
|
###
|
131
|
-
#
|
173
|
+
# This method is used for deleting an item from the basket
|
174
|
+
#
|
175
|
+
# * *Args* :
|
176
|
+
# - +item_id+ -> the item_id for which the item should be deleted
|
132
177
|
#
|
133
|
-
#
|
178
|
+
# * *Returns* :
|
179
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
134
180
|
###
|
135
181
|
def delete_item(item_id)
|
136
182
|
deleted_items[item_id] = item_id
|
@@ -139,9 +185,13 @@ module AboutYou
|
|
139
185
|
end
|
140
186
|
|
141
187
|
###
|
142
|
-
#
|
188
|
+
# This method is used for deleting items from the basket
|
143
189
|
#
|
144
|
-
#
|
190
|
+
# * *Args* :
|
191
|
+
# - +item_ids+ -> Array containing item ids for which items should be deleted
|
192
|
+
#
|
193
|
+
# * *Returns* :
|
194
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
145
195
|
###
|
146
196
|
def delete_items(item_ids)
|
147
197
|
item_ids.each do |item_id|
|
@@ -152,7 +202,10 @@ module AboutYou
|
|
152
202
|
end
|
153
203
|
|
154
204
|
###
|
155
|
-
#
|
205
|
+
# This method is used for deleting all items from the basket
|
206
|
+
#
|
207
|
+
# * *Returns* :
|
208
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
156
209
|
###
|
157
210
|
def delete_all_items
|
158
211
|
items = self.items
|
@@ -168,9 +221,13 @@ module AboutYou
|
|
168
221
|
end
|
169
222
|
|
170
223
|
###
|
171
|
-
#
|
224
|
+
# This method is used for updating an item in the basket
|
225
|
+
#
|
226
|
+
# * *Args* :
|
227
|
+
# - +basket_item+ -> instance of AboutYou::SDK::Model::BasketItem
|
172
228
|
#
|
173
|
-
#
|
229
|
+
# * *Returns* :
|
230
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
174
231
|
###
|
175
232
|
def update_item(basket_item)
|
176
233
|
item = {
|
@@ -189,9 +246,13 @@ module AboutYou
|
|
189
246
|
end
|
190
247
|
|
191
248
|
###
|
192
|
-
#
|
249
|
+
# This method is used for updating an item set in the basket
|
193
250
|
#
|
194
|
-
#
|
251
|
+
# * *Args* :
|
252
|
+
# - +basket_item+ -> instance of AboutYou::SDK::Model::BasketSet
|
253
|
+
#
|
254
|
+
# * *Returns* :
|
255
|
+
# - Instance of AboutYou::SDK::Model::Basket
|
195
256
|
###
|
196
257
|
def update_item_set(basket_set)
|
197
258
|
items = basket_set.items
|
@@ -222,6 +283,17 @@ module AboutYou
|
|
222
283
|
self
|
223
284
|
end
|
224
285
|
|
286
|
+
###
|
287
|
+
# checks if certain additional_data is valid to set for a basket or not
|
288
|
+
#
|
289
|
+
# * *Args* :
|
290
|
+
# - +add_data+ -> the desired data to check
|
291
|
+
# - +_img_url_required+ -> unused operator
|
292
|
+
#
|
293
|
+
# * *Fails* :
|
294
|
+
# - if add_data doesnt have a description
|
295
|
+
# - if add_data doesnt have valid internal infos
|
296
|
+
###
|
225
297
|
def check_additional_data(add_data = nil, _img_url_required = false)
|
226
298
|
fail 'InvalidArgumentException! description is required
|
227
299
|
in additional data' if add_data && !add_data.key?('description')
|