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.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/lib/AboutYou/CacheProvider/dalli.rb +3 -0
  3. data/lib/AboutYou/Criteria/product_fields.rb +3 -0
  4. data/lib/AboutYou/Criteria/product_search_criteria.rb +8 -8
  5. data/lib/AboutYou/Factory/default_model_factory.rb +15 -2
  6. data/lib/AboutYou/Model/Basket/abstract_basket_item.rb +25 -20
  7. data/lib/AboutYou/Model/Basket/basket_item.rb +27 -27
  8. data/lib/AboutYou/Model/Basket/basket_set.rb +60 -62
  9. data/lib/AboutYou/Model/Basket/basket_set_item.rb +8 -9
  10. data/lib/AboutYou/Model/Basket/basket_variant_item.rb +55 -21
  11. data/lib/AboutYou/Model/ProductSearchResult/facet_count.rb +0 -2
  12. data/lib/AboutYou/Model/ProductSearchResult/price_range.rb +2 -2
  13. data/lib/AboutYou/Model/abstract_model.rb +5 -3
  14. data/lib/AboutYou/Model/app.rb +0 -2
  15. data/lib/AboutYou/Model/autocomplete.rb +0 -2
  16. data/lib/AboutYou/Model/basket.rb +91 -19
  17. data/lib/AboutYou/Model/brand.rb +8 -4
  18. data/lib/AboutYou/Model/categories_result.rb +13 -2
  19. data/lib/AboutYou/Model/category.rb +45 -19
  20. data/lib/AboutYou/Model/category_tree.rb +21 -7
  21. data/lib/AboutYou/Model/facet.rb +44 -22
  22. data/lib/AboutYou/Model/facet_group.rb +55 -21
  23. data/lib/AboutYou/Model/facet_group_set.rb +106 -23
  24. data/lib/AboutYou/Model/image.rb +36 -25
  25. data/lib/AboutYou/Model/image_size.rb +8 -5
  26. data/lib/AboutYou/Model/initiate_order.rb +26 -7
  27. data/lib/AboutYou/Model/order.rb +12 -2
  28. data/lib/AboutYou/Model/product.rb +261 -5
  29. data/lib/AboutYou/Model/product_search_result.rb +40 -10
  30. data/lib/AboutYou/Model/{products_ean_result.rb → products_eans_result.rb} +11 -5
  31. data/lib/AboutYou/Model/products_result.rb +13 -14
  32. data/lib/AboutYou/Model/result_error.rb +18 -2
  33. data/lib/AboutYou/Model/variant.rb +87 -26
  34. data/lib/AboutYou/Model/variants_result.rb +31 -15
  35. data/lib/AboutYou/client.rb +7 -0
  36. data/lib/AboutYou/query.rb +7 -2
  37. data/lib/AboutYou/query_builder.rb +22 -3
  38. data/lib/aboutyou-sdk.rb +7 -0
  39. metadata +3 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWJkYTExNDNlM2QxNjIzZjdjNzdmYWRhYWI1YjBlZjc5ODFjZGMwYQ==
4
+ NGQwY2IxMmM2YzExZDQzYzBjZmJkNzI4ZjIwM2ZmMWZlZjMwODQyOQ==
5
5
  data.tar.gz: !binary |-
6
- OGYwNWE3ZTVmNWQ5NDY2ZDczNTkwMzgxY2ViOGJlYjI1MzUxMDk1NQ==
6
+ MDIxYjY3ODZkMGRiYjE2OGZkZjgyMmVlMGIxNTFiMTRjMDk3MDQyYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmI2OGI0MWE5NTMyNzIyMmRkMDMyNTg5ZTIzODI1YjQ4MTJkNzU3NTFhMzMz
10
- MDRiMzliNDdhYWQ1NGU5M2Q0NmNjYzlmZTFmMzgxZmI5NTc0N2Y5ODQzODgx
11
- M2JjMjMwMWQyZjg5NTg0MjFmNDExNDc0YTFhNzVmZjM0M2E1MDg=
9
+ MWRiZmU3NjhlMzljODkzODYxMTc2ZWQ5ZDJlOTE4YjM0OTQxYjFhMzg2MTVk
10
+ ODM0NzI2MTA4ZGRiMmQzYTliZGZjYzNkMDcyNDhmY2ViYWU4ZjkyNDQ3NTRh
11
+ ODZiZDM3MmEwZDVkOThmMjg5NDZhYzhmMWI5YmFjYzFlM2FmMWU=
12
12
  data.tar.gz: !binary |-
13
- NzgyM2ExY2Q5NmRjMDNmYTY0ZWM0MzY4NDdhNDkyMmY3NzZhZmY4NTQ0YTcx
14
- YzE1MmJkZWYxMjBiODAxNzA2ZDA2ODE3N2NiYTdjYTNlMjBlN2MxYjUxNjZl
15
- MWQwZjY2MzIxZjM1MWRmMWNiYjk4NzczMGFhYWEyMDA2Njk2YzI=
13
+ ZWFiM2ZlNjVjNjA5OTYzOGU2MjUzZTE4MDA5YzA3YjQ3OGU5MTJhYTI1ZDIw
14
+ YzUxYTMwMzZmNDM0NmQ2ODg0Njk3NmQyY2UwNmYxNTRkODc5Nzk0MDEwOTY5
15
+ NGVhYWY5MTQyNGMxOGE3Mzc0YWE5NzIxNzljNDhhM2ZmODYyY2Q=
@@ -1,5 +1,8 @@
1
1
  module AboutYou
2
2
  module SDK
3
+ ###
4
+ # The CacheProvider namespace
5
+ ###
3
6
  module CacheProvider
4
7
  ###
5
8
  # This class is used as an interface for cache operations.
@@ -1,5 +1,8 @@
1
1
  module AboutYou
2
2
  module SDK
3
+ ###
4
+ # The Criteria namespace
5
+ ###
3
6
  module Criteria
4
7
  ###
5
8
  # This class is used for the selection of certain product fields
@@ -29,18 +29,11 @@ module AboutYou
29
29
  SORT_MOST_VIEWED = 'most_viewed'
30
30
  # Sort-argument passed to api for price
31
31
  SORT_PRICE = 'price'
32
-
33
32
  # api-call-name for sorting ascending
34
33
  SORT_ASC = 'asc'
35
34
  # api-call-name for sorting descending
36
35
  SORT_DESC = 'desc'
37
36
 
38
- # api-call name for requiring all facets
39
- FACETS_ALL = '_all'
40
-
41
- # api-call-value for requiring unlimited facets
42
- FACETS_UNLIMITED = -1
43
-
44
37
  # api-call-name for filtering the sale
45
38
  FILTER_SALE = 'sale'
46
39
  # api-call-name for filtering the categories
@@ -310,6 +303,9 @@ module AboutYou
310
303
  # - +group_id+ -> group id which facets you want to receive
311
304
  # - +limit+ -> limits the received facets
312
305
  #
306
+ # * *Fails* :
307
+ # - if group_id is not convertable in an Integer
308
+ #
313
309
  # * *Returns* :
314
310
  # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
315
311
  ###
@@ -318,7 +314,7 @@ module AboutYou
318
314
 
319
315
  fail "InvalidArgumentException! Group id must be an integer or a
320
316
  string containing digits" unless
321
- group_id.is_a?(Fixnum) && Integer(group_id)
317
+ group_id.is_a?(Fixnum) || Integer(group_id)
322
318
 
323
319
  result['facets'] = {} unless result['facets']
324
320
 
@@ -356,6 +352,10 @@ module AboutYou
356
352
  # * *Args* :
357
353
  # - +limit+ -> limit which should be checked
358
354
  #
355
+ # * *Fails* :
356
+ # - if limit is not an integer
357
+ # - if limit is smaller then -1
358
+ #
359
359
  # * *Returns* :
360
360
  # - nil if there is no error
361
361
  ###
@@ -1,5 +1,8 @@
1
1
  module AboutYou
2
2
  module SDK
3
+ ###
4
+ # The Factory namespace
5
+ ###
3
6
  module Factory
4
7
  ###
5
8
  # This class creates model objects from a given api response
@@ -22,7 +25,7 @@ module AboutYou
22
25
  # * *Args* :
23
26
  # - +shop_api+ -> the client which should perform the api calls
24
27
  # - +category_manager+ -> the category manager responsible for managing the categories
25
- # - +:facet_manager+ -> the facet manager responsible for managing the facets
28
+ # - +facet_manager+ -> the facet manager responsible for managing the facets
26
29
  #
27
30
  # * *Returns* :
28
31
  # - an instance of AboutYou::SDK::Factory::DefaultModelFactory
@@ -31,6 +34,13 @@ module AboutYou
31
34
  self.shop_api = shop_api
32
35
  end
33
36
 
37
+ ###
38
+ # this method initializes the managers
39
+ #
40
+ # * *Args* :
41
+ # - +facet_manager+ -> the facet manager responsible for managing the facets
42
+ # - +category_manager+ -> the category manager responsible for managing the categories
43
+ ###
34
44
  def initialize_managers(facet_manager, category_manager)
35
45
  self.category_manager = category_manager
36
46
  self.facet_manager = facet_manager
@@ -657,9 +667,12 @@ module AboutYou
657
667
  # - +json+ -> the api response in json format
658
668
  # - +resultKey+ -> the result key received from the api
659
669
  # - +isMultiRequest+ -> determines whether the api-request was multiquery or not
670
+ #
671
+ # * *Fails* :
672
+ # - if the result_key is not basket and the json response does not contain order_lines
660
673
  ###
661
674
  def pre_handle_error(json, result_key, is_multi_request)
662
- return false if result_key == 'basket' && json['order_lines']
675
+ return if result_key == 'basket' && json['order_lines']
663
676
 
664
677
  fail 'ResultError!' + json + is_multi_request
665
678
  end
@@ -7,34 +7,29 @@ module AboutYou
7
7
  # author:: Collins GmbH & Co KG
8
8
  ###
9
9
  module AbstractBasketItem
10
+ # determines if the image url is required
10
11
  IMAGE_URL_REQUIRED = false
11
- ###
12
- # Additional data are transmitted to the merchant untouched.
13
- # If set (array not empty), a key "description" must exist. This description
14
- # must be a string that describes the variant. If you want to pass a different image URL,
15
- # you can add a key "image_url" to the $additional_data that contains the URL to the image.
16
- #
17
- # @var array $additional_data additional data for this variant
18
- ###
12
+
13
+ # Additional data
19
14
  attr_accessor :additional_data
15
+ # determines whether a basket item is changed or not
20
16
  attr_accessor :is_changed
21
17
 
22
18
  ###
23
- # @return string|null
19
+ # gets the description of the basket item
20
+ #
21
+ # * *Returns* :
22
+ # - a String of null if no description is set
24
23
  ###
25
24
  def description
26
25
  additional_data['description'] if additional_data
27
26
  end
28
27
 
29
28
  ###
30
- # Additional data are transmitted to the merchant untouched.
31
- # If set (array not empty), a key "description" must exist. This description
32
- # must be a string that describes the variant. If you want to pass a different image URL,
33
- # you can add a key "image_url" to the $additional_data that contains the URL to the image.
29
+ # sets additional data for the basket item
34
30
  #
35
- # @param array $additional_data additional data for this variant
36
- #
37
- # @throws \InvalidArgumentException
31
+ # * *Args* :
32
+ # - +additional_data+ -> the desired data to set
38
33
  ###
39
34
  def addition_data=(additional_data)
40
35
  check_additional_data(additional_data)
@@ -43,11 +38,21 @@ module AboutYou
43
38
  self.additional_data = additional_data
44
39
  end
45
40
 
41
+ ###
42
+ # checks if certain additional_data is valid to set for a basket item or not
43
+ #
44
+ # * *Args* :
45
+ # - +additional_data+ -> the desired data to check
46
+ #
47
+ # * *Fails* :
48
+ # - if additional_data doesnt have a description
49
+ # - if additional_data doesnt have an image url and it would be required
50
+ ###
46
51
  def check_additional_data(additional_data = nil)
47
- return false if additional_data || IMAGE_URL_REQUIRED
48
- fail '\InvalidArgumentException! description is required
49
- in additional data' if additional_data.key?('description')
50
- fail '\InvalidArgumentException! image_url is required in
52
+ return unless additional_data || IMAGE_URL_REQUIRED
53
+ fail 'InvalidArgumentException! description is required
54
+ in additional data' unless additional_data.key?('description')
55
+ fail 'InvalidArgumentException! image_url is required in
51
56
  additional data' if
52
57
  IMAGE_URL_REQUIRED && !additional_data.key?('image_url')
53
58
  end
@@ -7,50 +7,45 @@ module AboutYou
7
7
  # If you want to add a variant into a basket, you need to create an instance
8
8
  # of a BasketItem. The BasketItem represents a variant by it's variant_id.
9
9
  # It can contain $additional_data that will be transmitted to the merchant untouched.
10
- #
11
- # Example usage:
12
- # $variant_id = $variant->getId(); // $variant is instance of \Collins\ShopApi\Model\Variant
13
- # $basketItem = new BasketItem('my-personal-identifier', $variant_id);
14
- # $basketItem->setAdditionalData('jeans with engraving 'for you'', ['engraving_text' => 'for you']);
15
- # $shop_api->addItemToBasket(session_id(), $basketItem);
16
- #
17
- # @see \Collins\ShopApi\Model\Variant
18
- # @see \Collins\ShopApi\Model\Basket
19
- # @see \Collins\ShopApi
20
10
  ###
21
11
  class BasketItem
22
12
  include AboutYou::SDK::Model::ResultError
23
13
  include AboutYou::SDK::Model::AbstractBasketItem
24
14
  include AboutYou::SDK::Model::BasketVariantItem
25
15
 
26
- ###
27
- # The ID of this basket item. You can choose this ID by yourself to identify
28
- # your item later.
29
- #
30
- # @var string $id ID of this basket item
31
- ###
16
+ # The ID of this basket item. You can choose this ID by yourself to identify your item later.
32
17
  attr_accessor :id
33
18
 
34
19
  ###
35
- # Constructor.
20
+ # Constructor for the AboutYou::SDK::Model::BasketItem class
36
21
  #
37
- # @param string $id
38
- # @param integer $variant_id
39
- # @param array $additional_data
22
+ # * *Args* :
23
+ # - +id+ -> the basket item id
24
+ # - +variant_id+ -> the id of the variant
25
+ # - +additional_data+ -> additional data of the basket item [optional]
26
+ # - +app_id+ -> the app id [optional]
27
+ #
28
+ # * *Returns* :
29
+ # - an instance of AboutYou::SDK::Model::BasketItem
40
30
  ###
41
31
  def initialize(id, variant_id, additional_data = nil, app_id = nil)
42
32
  check_id(id)
43
33
  self.id = id
44
34
  super(variant_id, additional_data, app_id)
35
+
36
+ self
45
37
  end
46
38
 
47
39
  ###
48
- # @param object $json_object The basket data.
49
- # @param Product[] $products
40
+ # This method is used for creating a basket item with a given api json
41
+ # response. It is best practice to use this method.
50
42
  #
51
- # @return BasketItem
43
+ # * *Args* :
44
+ # - +json_object+ -> the api response key
45
+ # - +products+ -> array of products
52
46
  #
53
- # @throws \Collins\ShopApi\Exception\UnexpectedResultException
47
+ # * *Returns* :
48
+ # - an instance of AboutYou::SDK::Model::BasketItem
54
49
  ###
55
50
  def create_from_json(json_object, products)
56
51
  item = new(
@@ -81,13 +76,18 @@ module AboutYou
81
76
  end
82
77
 
83
78
  ###
84
- # @param mixed $id
85
- # @throws \InvalidArgumentException
79
+ # This method checks whether an basket item id is valid or not
80
+ #
81
+ # * *Args* :
82
+ # - +id+ -> the id which should be checked
83
+ #
84
+ # * *Fails* :
85
+ # - if the id is not a String and has less then 2 characters
86
86
  ###
87
87
  def check_id(id)
88
88
  fail '\InvalidArgumentException! ID of the BasketSetItem must be
89
89
  a String that must contain minimum two characters' unless
90
- id.is_a?(String) || id.length < 2
90
+ id.is_a?(String) && id.length < 2
91
91
  end
92
92
  end
93
93
  end
@@ -10,77 +10,59 @@ module AboutYou
10
10
  # A set can be useful if you want to sell several variants as a single product.
11
11
  # For example, if you offer a pair of shoes and additionally different styles of shoelaces
12
12
  # the customer can choose from, you maybe want to put both - shoes and laces - together.
13
- #
14
- # Example usage:
15
- # $lacesVariantId = $lacesVariant->getId(); // $lacesVariant is instance of \Collins\ShopApi\Model\Variant
16
- # $shoesVariantID = $shoesVariant->getId(); // $lacesVariant is instance of \Collins\ShopApi\Model\Variant
17
- # $basketItem1 = new BasketItem($lacesVariantId);
18
- #
19
- # $basketSet = new BasketItemSet('my-personal-identifier');
20
- # $basketSet->addItem(new BasketSetItem($lacesVariantId));
21
- # $basketSet->addItem(new BasketSetItem($shoesVariantId));
22
- # $basketSet->setAdditionalData(['description' => 'Shoes with laces 'yellow star'', 'image_url' = 'http://myapp.com/shoes_yello_star.png']);
23
- # $basket->updateItemSet($basketSet)
24
- # $shop_api->update_basket(session_id(), $basket);
25
- #
26
- # You can use the static method create as an alternative to generate a basket set:
27
- # $basketSet = BasketItemSet::create(
28
- # 'my-personal-identifier',
29
- # [
30
- # [$lacesVariant->getId()],
31
- # [$shoesVariantID->getId()],
32
- # ]
33
- # );
34
- # @see create()
35
- #
36
- # @see \Collins\ShopApi\Model\Basket
37
- # @see \Collins\ShopApi\Model\Basket\BasketSetItem
38
- # @see \Collins\ShopApi\Model\Variant
39
- # @see \Collins\ShopApi
40
13
  ###
41
14
  class BasketSet
42
15
  include AboutYou::SDK::Model::ResultError
43
16
  include AboutYou::SDK::Model::AbstractBasketItem
44
17
 
18
+ # determines if an image url is required
45
19
  IMAGE_URL_REQUIRED = true
46
20
 
47
- ###
48
- # The ID of this basket item. You can choose this ID by yourself to identify
49
- # your item later.
50
- #
51
- # @var string $id ID of this basket item
52
- ###
21
+ # The ID of this basket item. You can choose this ID by yourself to identify your item later.
53
22
  attr_accessor :id
23
+ # array containing instances of AboutYou::SDK::Model::BasketSetItem
54
24
  attr_accessor :items
25
+ # array containing errors
55
26
  attr_accessor :errors
27
+ # total price of the set
56
28
  attr_accessor :total_price
29
+ # total net worth of the set
57
30
  attr_accessor :total_net
31
+ # total vat worth of the set
58
32
  attr_accessor :total_vat
33
+ # app id of an item
59
34
  attr_accessor :item_app_id
60
35
 
61
36
  ###
62
- # Additional data are transmitted to the merchant untouched.
63
- # If set (array not empty), a key 'description' must exist. This description
64
- # must be a string that describes the variant. If you want to pass an image URL that
65
- # represents this item set,
66
- # you can add a key 'image_url' to the $additional_data that contains the URL to the image.
37
+ # Constructor for the AboutYou::SDK::Model::BasketSet class
67
38
  #
68
- # @param string $id ID of the basket item set.
69
- # @param array $additional_data additional data for this item set
39
+ # * *Args* :
40
+ # - +id+ -> the id of the basket set
41
+ # - +additional_data+ -> additional data of the basket set
42
+ #
43
+ # * *Returns* :
44
+ # - an instance of AboutYou::SDK::Model::BasketSet
70
45
  ###
71
46
  def initialize(id, additional_data = nil)
72
47
  check_id(id)
73
48
  check_additional_data(additional_data, true)
74
49
  self.id = id
75
50
  self.additional_data = additional_data
51
+
52
+ self
76
53
  end
77
54
 
78
55
  ###
79
- # @param \stdClass $json_object
80
- # @param ModelFactoryInterface $factory
81
- # @param Product[] $products
56
+ # This method is used for creating a basket set with a given api json
57
+ # response. It is best practice to use this method.
82
58
  #
83
- # @return BasketSet
59
+ # * *Args* :
60
+ # - +json_object+ -> the api response key
61
+ # - +factory+ -> instance of AboutYou::SDK::Factory::DefaultModelFactory
62
+ # - +products+ -> Array of products
63
+ #
64
+ # * *Returns* :
65
+ # - an instance of AboutYou::SDK::Model::BasketSet
84
66
  ###
85
67
  def create_from_json(json_object, factory, products)
86
68
  set = new(
@@ -116,21 +98,16 @@ module AboutYou
116
98
  end
117
99
 
118
100
  ###
119
- # Create an basket item set from an array, for example:
120
- # BasketSet::create(
121
- # 'identifier4',
122
- # [
123
- # [12312121],
124
- # [7777777, ['description' => 'engravingssens', 'internal_infos' => ['stuff']]]
125
- # ],
126
- # ['description' => 'Wunderschön und so']
127
- # );
101
+ # This method is used for creating a basket set from an array containing
102
+ # instances of AboutYou::SDK::Model::BasketSetItem
128
103
  #
129
- # @param $itemId
130
- # @param $subItems
131
- # @param array $additional_data
104
+ # * *Args* :
105
+ # - +item_id+ -> the id of the set
106
+ # - +sub_items+ -> Array containing instances of AboutYou::SDK::Model::BasketSetItem
107
+ # - +additional_data+ -> additional data of the basket set
132
108
  #
133
- # @return BasketSet
109
+ # * *Returns* :
110
+ # - an instance of AboutYou::SDK::Model::BasketSet
134
111
  ###
135
112
  def create(item_id, sub_items, additional_data = nil)
136
113
  set = new(item_id, additional_data)
@@ -148,7 +125,13 @@ module AboutYou
148
125
  end
149
126
 
150
127
  ###
151
- # @param BasketSetItem $item
128
+ # This method is used for adding items to a basket set
129
+ #
130
+ # * *Args* :
131
+ # - +item+ -> instance of AboutYou::SDK::Model::BasketSetItem
132
+ #
133
+ # * *Fails* :
134
+ # - if the app id of the set and item diverge
152
135
  ###
153
136
  def add_item(item)
154
137
  if items.count == 0
@@ -162,12 +145,21 @@ module AboutYou
162
145
  end
163
146
 
164
147
  ###
165
- # @return boolean
148
+ # This method checks if there are errors in the basket set
149
+ #
150
+ # * *Returns* :
151
+ # - Boolean determining whether there are errors or not
166
152
  ###
167
153
  def errors?
168
154
  error_code || errors.count > 0
169
155
  end
170
156
 
157
+ ###
158
+ # This method is used for creating a unique key for the basket set
159
+ #
160
+ # * *Returns* :
161
+ # - a String containing a unique key for the basket set
162
+ ###
171
163
  def unique_key
172
164
  key = ':'
173
165
  unless additional_data
@@ -185,13 +177,19 @@ module AboutYou
185
177
  end
186
178
 
187
179
  ###
188
- # @param mixed $id
189
- # @throws \InvalidArgumentException
180
+ # This method is used for determining whether a certain id is valid for
181
+ # the basket set or not
182
+ #
183
+ # * *Args* :
184
+ # - +id+ -> the id which should be checked
185
+ #
186
+ # * *Fails* :
187
+ # - if the id is not a String and its length is smaller then 2
190
188
  ###
191
189
  def check_id(id)
192
190
  fail '\InvalidArgumentException! ID of the BasketSetItem must be a
193
191
  String that must contain minimum two characters' unless
194
- id.is_a?(String) || !id.length < 2
192
+ id.is_a?(String) && id.length > 1
195
193
  end
196
194
  end
197
195
  end