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,17 +1,16 @@
1
1
  require 'sinatra'
2
- require 'pry_debug'
3
- require_relative '../lib/aboutyou-sdk.rb'
2
+ require_relative '../lib/ay.rb'
4
3
 
5
4
  class AY
6
5
  attr_accessor :result
7
6
 
8
- def putsCatName(category)
7
+ def puts_cat_name(category)
9
8
  category = Array(category)
10
9
  self.result = self.result + '<ul>'
11
10
  category.each do |cat|
12
11
  self.result = self.result + ('<li>'+cat.name+'</li>')
13
- if (cat.subCategories(true))
14
- putsCatName(cat.subCategories(true))
12
+ if (cat.subcategories(true))
13
+ putsCatName(cat.subcategories(true))
15
14
  else
16
15
  puts ""
17
16
  end
@@ -25,7 +24,7 @@ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300')
25
24
 
26
25
  get "/" do
27
26
  shop.result = ""
28
- suggestResult = shop.fetchSuggest("Hose")
27
+ suggestResult = shop.fetch_suggest("Hose")
29
28
  suggestResult.each do |suggest|
30
29
  shop.result = shop.result + suggest + '</br>'
31
30
  end
@@ -1,17 +1,16 @@
1
1
  require 'sinatra'
2
- require 'pry_debug'
3
- require_relative '../lib/aboutyou-sdk.rb'
2
+ require_relative '../lib/ay.rb'
4
3
 
5
4
  class AY
6
5
  attr_accessor :result
7
6
 
8
- def putsCatName(category)
7
+ def puts_cat_name(category)
9
8
  category = Array(category)
10
9
  self.result = self.result + '<ul>'
11
10
  category.each do |cat|
12
11
  self.result = self.result + ('<li>'+cat.name+'</li>')
13
- if (cat.subCategories(true))
14
- putsCatName(cat.subCategories(true))
12
+ if (cat.subcategories(true))
13
+ putsCatName(cat.subcategories(true))
15
14
  else
16
15
  puts ""
17
16
  end
@@ -21,12 +20,12 @@ class AY
21
20
  end
22
21
  end
23
22
 
24
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', "session_id", AboutYou::SDK::CacheProvider::Redis.new(Redis.new))
23
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', "session_id", AboutYou::SDK::CacheProvider::Dalli.new(Dalli::Client.new))
25
24
  shop.result = ""
26
25
 
27
- variantResult = shop.fetchVariantsByIds([7832543])
26
+ variantResult = shop.fetch_variants_by_ids([7832543])
28
27
  variantResult.variants.each do |key, variant|
29
- variant.facetIds.each do |fId|
28
+ variant.facet_ids.each do |fId|
30
29
  shop.result = shop.result + String(fId)
31
30
  end
32
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aboutyou-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferenc Beutel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -58,56 +58,56 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
- - lib/aboutyou-sdk.rb
62
- - lib/aboutyou-sdk/CacheProvider/Dalli.rb
63
- - lib/aboutyou-sdk/CacheProvider/Redis.rb
64
- - lib/aboutyou-sdk/Client.rb
65
- - lib/aboutyou-sdk/Constants.rb
66
- - lib/aboutyou-sdk/Criteria/ProductFields.rb
67
- - lib/aboutyou-sdk/Criteria/ProductSearchCriteria.rb
68
- - lib/aboutyou-sdk/Factory/DefaultModelFactory.rb
69
- - lib/aboutyou-sdk/Model/AbstractModel.rb
70
- - lib/aboutyou-sdk/Model/App.rb
71
- - lib/aboutyou-sdk/Model/Autocomplete.rb
72
- - lib/aboutyou-sdk/Model/Basket.rb
73
- - lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb
74
- - lib/aboutyou-sdk/Model/Basket/BasketItem.rb
75
- - lib/aboutyou-sdk/Model/Basket/BasketSet.rb
76
- - lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb
77
- - lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb
78
- - lib/aboutyou-sdk/Model/CategoriesResult.rb
79
- - lib/aboutyou-sdk/Model/Category.rb
80
- - lib/aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb
81
- - lib/aboutyou-sdk/Model/CategoryTree.rb
82
- - lib/aboutyou-sdk/Model/Facet.rb
83
- - lib/aboutyou-sdk/Model/FacetGroup.rb
84
- - lib/aboutyou-sdk/Model/FacetGroupSet.rb
85
- - lib/aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb
86
- - lib/aboutyou-sdk/Model/Image.rb
87
- - lib/aboutyou-sdk/Model/ImageSize.rb
88
- - lib/aboutyou-sdk/Model/InitiateOrder.rb
89
- - lib/aboutyou-sdk/Model/Order.rb
90
- - lib/aboutyou-sdk/Model/Product.rb
91
- - lib/aboutyou-sdk/Model/ProductSearchResult.rb
92
- - lib/aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb
93
- - lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb
94
- - lib/aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb
95
- - lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb
96
- - lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb
97
- - lib/aboutyou-sdk/Model/ProductsEansResult.rb
98
- - lib/aboutyou-sdk/Model/ProductsResult.rb
99
- - lib/aboutyou-sdk/Model/ResultError.rb
100
- - lib/aboutyou-sdk/Model/Variant.rb
101
- - lib/aboutyou-sdk/Model/VariantsResult.rb
102
- - lib/aboutyou-sdk/Query.rb
103
- - lib/aboutyou-sdk/QueryBuilder.rb
61
+ - lib/AboutYou/CacheProvider/dalli.rb
62
+ - lib/AboutYou/CacheProvider/redis.rb
63
+ - lib/AboutYou/Criteria/product_fields.rb
64
+ - lib/AboutYou/Criteria/product_search_criteria.rb
65
+ - lib/AboutYou/Factory/default_model_factory.rb
66
+ - lib/AboutYou/Model/Basket/abstract_basket_item.rb
67
+ - lib/AboutYou/Model/Basket/basket_item.rb
68
+ - lib/AboutYou/Model/Basket/basket_set.rb
69
+ - lib/AboutYou/Model/Basket/basket_set_item.rb
70
+ - lib/AboutYou/Model/Basket/basket_variant_item.rb
71
+ - lib/AboutYou/Model/CategoryManager/default_category_manager.rb
72
+ - lib/AboutYou/Model/FacetManager/default_facet_manager.rb
73
+ - lib/AboutYou/Model/ProductSearchResult/facet_count.rb
74
+ - lib/AboutYou/Model/ProductSearchResult/facet_counts.rb
75
+ - lib/AboutYou/Model/ProductSearchResult/price_range.rb
76
+ - lib/AboutYou/Model/ProductSearchResult/sale_counts.rb
77
+ - lib/AboutYou/Model/ProductSearchResult/terms_count.rb
78
+ - lib/AboutYou/Model/abstract_model.rb
79
+ - lib/AboutYou/Model/app.rb
80
+ - lib/AboutYou/Model/autocomplete.rb
81
+ - lib/AboutYou/Model/basket.rb
82
+ - lib/AboutYou/Model/categories_result.rb
83
+ - lib/AboutYou/Model/category.rb
84
+ - lib/AboutYou/Model/category_tree.rb
85
+ - lib/AboutYou/Model/facet.rb
86
+ - lib/AboutYou/Model/facet_group.rb
87
+ - lib/AboutYou/Model/facet_group_set.rb
88
+ - lib/AboutYou/Model/image.rb
89
+ - lib/AboutYou/Model/image_size.rb
90
+ - lib/AboutYou/Model/initiate_order.rb
91
+ - lib/AboutYou/Model/order.rb
92
+ - lib/AboutYou/Model/product.rb
93
+ - lib/AboutYou/Model/product_search_result.rb
94
+ - lib/AboutYou/Model/products_ean_result.rb
95
+ - lib/AboutYou/Model/products_result.rb
96
+ - lib/AboutYou/Model/result_error.rb
97
+ - lib/AboutYou/Model/variant.rb
98
+ - lib/AboutYou/Model/variants_result.rb
99
+ - lib/AboutYou/client.rb
100
+ - lib/AboutYou/constants.rb
101
+ - lib/AboutYou/query.rb
102
+ - lib/AboutYou/query_builder.rb
103
+ - lib/ay.rb
104
104
  - tests/Sinatra-test/Main.rb
105
105
  - tests/testApiClient.rb
106
106
  - tests/testAutocomplete.rb
107
107
  - tests/testCatFilter.rb
108
108
  - tests/testCatTree.rb
109
109
  - tests/testCategoryCaching.rb
110
- - tests/testFacetCaching.rb
110
+ - tests/testDalliCache.rb
111
111
  - tests/testFacetTypes.rb
112
112
  - tests/testFacets.rb
113
113
  - tests/testFetchFacet.rb
@@ -1,596 +0,0 @@
1
- require 'httparty'
2
- require 'json'
3
- require 'require_all'
4
-
5
- require_rel 'aboutyou-sdk'
6
-
7
- ###
8
- # Provides access to the Collins Frontend Platform.
9
- # All the public methods cover a single API query.
10
- #
11
- # author:: Collins GmbH & Co KG
12
- ###
13
- class AY
14
-
15
- # url for staging
16
- IMAGE_URL_STAGE = 'http://mndb.staging.aboutyou.de/mmdb/file'
17
- # url for the sandbox
18
- IMAGE_URL_SANDBOX = 'http://mndb.sandbox.aboutyou.de/mmdb/file'
19
- # url for live
20
- IMAGE_URL_LIVE = 'http://cdn.aboutyou.de/file'
21
-
22
- # the client which performs the api calls
23
- attr_accessor :aboutYouClient
24
- # the app id of the app which should be represented by an instance of AY
25
- attr_accessor :appId
26
- # the authentifaction token from dev-center for the app id
27
- attr_accessor :appPassword
28
- # the endpoint used for api calls
29
- attr_accessor :apiEndPoint
30
- # the environment which should be used by the app
31
- attr_accessor :environment
32
- # a logger template
33
- attr_accessor :logger
34
- # the model factory builds model objects based on the api response
35
- attr_accessor :modelFactoryInstance
36
- # the url for getting images
37
- attr_accessor :baseImageUrl
38
- # the session id from a user using this app
39
- attr_accessor :sessionId
40
- # the CacheServer
41
- attr_accessor :cache
42
-
43
- ###
44
- # the Constructor for the AY class
45
- #
46
- # * *Args* :
47
- # - +appId+ -> The App-Id of the App
48
- # - +appPassword+ -> The Auth-Token of the App
49
- # - +sessionId+ -> A String containing the sessionId of the User
50
- # - +apiEndPoint+ -> Can be either live or staging
51
- # - +resultFactory+ -> If nil it will use the DefaultModelFactory with the DefaultFacetManager
52
- # - +logger+ -> Logger-Template
53
- # - +cache+ -> The prefered Caching-Strategy
54
- #
55
- # * *Returns* :
56
- # - Instance of AY
57
- ###
58
- def initialize(
59
- appId,
60
- appPassword,
61
- sessionId = 'SESSION_ID',
62
- cache = nil,
63
- apiEndPoint = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE,
64
- resultFactory = nil,
65
- logger = nil
66
- )
67
-
68
- self.sessionId = sessionId
69
- self.appId = appId
70
- self.appPassword = appPassword
71
- self.aboutYouClient = AboutYou::SDK::Client.new(
72
- appId,
73
- appPassword,
74
- apiEndPoint,
75
- logger
76
- )
77
-
78
- self.cache = cache
79
- if resultFactory
80
- self.modelFactoryInstance = resultFactory
81
- else
82
- initDefaultFactory(self.cache)
83
- end
84
-
85
- if apiEndPoint == AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
86
- self.baseImageUrl = (IMAGE_URL_STAGE)
87
- self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
88
- elsif apiEndPoint == AboutYou::SDK::Constants::API_ENVIRONMENT_SANDBOX
89
- self.baseImageUrl = (IMAGE_URL_SANDBOX)
90
- self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_SANDBOX
91
- elsif apiEndPoint == AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE
92
- self.baseImageUrl = (IMAGE_URL_LIVE)
93
- self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE
94
- end
95
- end
96
-
97
- ###
98
- # Adds a single item into the basket.
99
- # You can specify an amount. Please mind, that an amount > 1 will result
100
- # in #amount basket positions.
101
- # So if you read out the basket again later, it's your job to
102
- # merge the positions again.
103
- #
104
- # * *Args* :
105
- # - +sessionId+ -> A String containing the sessionId of the User
106
- # - +variantId+ -> Id of the Variant which should be added to the basket
107
- # - +amount+ -> The Amount of the Item which should be added to the basket
108
- #
109
- # * *Returns* :
110
- # - Instance of AboutYou::SDK::Model::Basket
111
- ###
112
- def addItemToBasket(sessionId, variantId, amount = 1)
113
-
114
- basket = AboutYou::SDK::Model::Basket.new
115
-
116
- unless variantId.is_a? Long
117
- if variantId.is_a? String && variantId[/\d/]
118
- variantId = Integer(variantId)
119
- else
120
- raise 'the variant id must be an integer or string with digits'
121
- end
122
- end
123
-
124
- amount.times do
125
- basket.updateItem(AboutYou::SDK::Model::Basket::BasketItem.new(generateBasketItemId, variantId))
126
- end
127
-
128
- updateBasket(sessionId, basket)
129
- end
130
-
131
-
132
- ###
133
- # Method to create a unique item id for items in basket
134
- #
135
- # * *Args* :
136
- #
137
- # * *Returns* :
138
- # - an Intger
139
- ###
140
- def generateBasketItemId
141
-
142
- 'i_' + SecureRandom.uuid
143
- end
144
-
145
-
146
- ###
147
- # Method to remove items from basket
148
- #
149
- # * *Args* :
150
- # - +sessionId+ -> A String containing the sessionId of the User
151
- # - +itemIds+ -> an Array of Item ids which should be removed
152
- #
153
- # * *Returns* :
154
- # - Instance of AboutYou::SDK::Model::Basket
155
- ###
156
- def removeItemsFromBasket(sessionId, itemIds)
157
-
158
- basket = AboutYou::SDK::Model::Basket.new
159
- basket.deleteItems(itemIds)
160
-
161
- updateBasket(sessionId, basket)
162
- end
163
-
164
-
165
- ###
166
- # Method to update a given basket
167
- #
168
- # * *Args* :
169
- # - +sessionId+ -> A String containing the sessionId of the User
170
- # - +basket+ -> an Instance of a basket
171
- #
172
- # * *Returns* :
173
- # - Instance of AboutYou::SDK::Model::Basket
174
- ###
175
- def updateBasket(sessionId, basket)
176
-
177
- query.updateBasket(sessionId, basket).executeSingle
178
- end
179
-
180
-
181
- ###
182
- # Method to initiaite the order
183
- #
184
- # * *Args* :
185
- # - +sessionId+ -> A String containing the sessionId of the User
186
- # - +successUrl+ -> callback URL if the order was OK
187
- # - +cancelUrl+ -> callback URL if the order was canceled [optional]
188
- # - +errorUrl+ -> callback URL if the order had any exceptions [optional]
189
- #
190
- # * *Returns* :
191
- # - Instance of AboutYou::SDK::Model::InitiateOrder
192
- ###
193
- def initiateOrder(sessionId,successUrl,cancelUrl = nil,errorUrl = nil)
194
-
195
- query.initiateOrder(sessionId, successUrl, cancelUrl, errorUrl).executeSingle
196
- end
197
-
198
-
199
- ###
200
- # Returns the result of an auto completion API request.
201
- # Auto completion searches for products and categories by
202
- # a given prefix (searchword).
203
- #
204
- # * *Args* :
205
- # - +searchword+ -> The prefix search word to search for
206
- # - +limit+ -> Maximum number of results [optional]
207
- # - +types+ -> Array of types to search for [optional]
208
- #
209
- # * *Returns* :
210
- # - Instance of AboutYou::SDK::Model::Automcomplete
211
- ###
212
- def fetchAutocomplete(searchword, limit = 50, types = [AboutYou::SDK::Constants::TYPE_PRODUCTS, AboutYou::SDK::Constants::TYPE_CATEGORIES])
213
-
214
- query.fetchAutocomplete(searchword, limit, types).executeSingle
215
- end
216
-
217
-
218
- ###
219
- # Fetch the basket of the given sessionId.
220
- #
221
- # * *Args* :
222
- # - +sessionId+ -> A String containing the sessionId of the User
223
- #
224
- # * *Returns* :
225
- # - Instance of AboutYou::SDK::Model::Basket
226
- ###
227
- def fetchBasket(sessionId)
228
-
229
- query.fetchBasket(sessionId).executeSingle
230
- end
231
-
232
-
233
- ###
234
- # Returns the result of a category search API request.
235
- # By passing one or several category ids it will return
236
- # a result of the categories data.
237
- #
238
- # * *Args* :
239
- # - +ids+ -> either a single category ID as integer or an array of IDs [optional]
240
- #
241
- # * *Returns* :
242
- # - Instance of AboutYou::SDK::Model::CategoriesResult
243
- ###
244
- def fetchCategoriesByIds(ids = nil)
245
- # we allow to pass a single ID instead of an array
246
-
247
- if ids
248
- ids = Array(ids)
249
- end
250
-
251
- categoryManager = self.categoryManager
252
- return AboutYou::SDK::Model::CategoriesResult.new(categoryManager, ids)
253
- end
254
-
255
-
256
- ###
257
- # Fetches the Root Categories of the Category Tree
258
- #
259
- # * *Returns* :
260
- # - Instance of AboutYou::SDK::Model::CategoryTree
261
- ###
262
- def fetchCategoryTree
263
-
264
- AboutYou::SDK::Model::CategoryTree.new(self.categoryManager)
265
- end
266
-
267
-
268
- ###
269
- # The Categories will be fetched automatically, if required by any other fetch method
270
- #
271
- # * *Args* :
272
- # - +fetchIfEmpty+ -> defines whether to fetch if empty or not [optional]
273
- #
274
- # * *Returns* :
275
- # - Instance of AboutYou::SDK::CategoryManager::DefaultCategoryManager
276
- ###
277
- def categoryManager(fetchIfEmpty = true)
278
-
279
- categoryManager = self.modelFactory.categoryManager
280
-
281
- if fetchIfEmpty && categoryManager.isEmpty
282
- query.requireCategoryTree.executeSingle
283
- end
284
-
285
- categoryManager
286
- end
287
-
288
-
289
- ###
290
- # Fetches the products for specific ids
291
- #
292
- # * *Args* :
293
- # - +ids+ -> Either a single id or an Array of ids which should be fetched
294
- # - +fields+ -> Additional product fields which should be fetched for each product [optional]
295
- #
296
- # * *Returns* :
297
- # - Instance of AboutYou::SDK::Model::ProductsResult
298
- ###
299
- def fetchProductsByIds(ids , fields = [])
300
- # we allow to pass a single ID instead of an array
301
- ids = Array(ids)
302
- result = query.fetchProductsByIds(ids, fields).executeSingle
303
- productsNotFound = result.productsNotFound
304
-
305
- if !productsNotFound.empty? && self.logger
306
- self.logger.warning('products not found: appid=' + self.appId + ' product ids=[' + productsNotFound.join(',') + ']')
307
- end
308
-
309
- result
310
- end
311
-
312
-
313
- ###
314
- # Fetches variants for specific ids
315
- #
316
- # * *Args* :
317
- # - +ids+ -> Either a single id or an Array of ids which should be fetched
318
- #
319
- # * *Returns* :
320
- # - Instance of AboutYou::SDK::Model::VariantsResult
321
- ###
322
- def fetchVariantsByIds(ids)
323
- # we allow to pass a single ID instead of an array
324
-
325
- ids = Array(ids)
326
- result = query.fetchLiveVariantByIds(ids).executeSingle
327
- variantsNotFound = result.variantsNotFound
328
-
329
- if result.hasVariantsNotFound && self.logger
330
- self.logger.warning('variants or products for variants not found: appid='+self.appId+' variant ids=['+variantsNotFound.join(',')+']')
331
- end
332
-
333
- result
334
- end
335
-
336
-
337
- ###
338
- # Fetches products for specific eans
339
- #
340
- # * *Args* :
341
- # - +eans+ -> Either a single ean or an Array of eans which should be fetched
342
- # - +fields+ -> Additional product fields which should be fetched for each product [optional]
343
- #
344
- # * *Returns* :
345
- # - Instance of AboutYou::SDK::Model::ProductsEanResult
346
- ###
347
- def fetchProductsByEans(eans,fields = [])
348
- # we allow to pass a single ID instead of an array
349
-
350
- eans = Array(eans)
351
-
352
- query.fetchProductsByEans(eans, fields).executeSingle
353
- end
354
-
355
-
356
- ###
357
- # Fetches the response for a product search
358
- #
359
- # * *Args* :
360
- # - +criteria+ -> Hash containing one or multiple search terms
361
- #
362
- # * *Returns* :
363
- # - Instance of AboutYou::SDK::Model::ProductSearchResult
364
- ###
365
- def fetchProductSearch(criteria)
366
-
367
- query.fetchProductSearch(criteria).executeSingle
368
- end
369
-
370
-
371
- ###
372
- # Fetch the facets of the given groupIds
373
- #
374
- # * *Args* :
375
- # - +groupIds+ -> Array of group ids [optional]
376
- #
377
- # * *Returns* :
378
- # - Instance of AboutYou::SDK::Model::Facet
379
- ###
380
- def fetchFacets(groupIds=[])
381
- if self.modelFactoryInstance.facetManager.isEmpty
382
- query.fetchFacets.executeSingle
383
- end
384
- self.modelFactoryInstance.facetManager.facetsByGroupIds(groupIds)
385
- end
386
-
387
-
388
- ###
389
- # Fetches all possible Facet types
390
- #
391
- # * *Returns* :
392
- # - Array with all group ids
393
- ###
394
- def fetchFacetTypes
395
-
396
- query.fetchFacetTypes.executeSingle
397
- end
398
-
399
-
400
- ###
401
- # fetches Order for specific id
402
- #
403
- # * *Args* :
404
- # - +orderId+ -> The id for which an order should be returned
405
- # * *Returns* :
406
- # - Instance of AboutYou::SDK::Model::Order
407
- ###
408
- def fetchOrder(orderId)
409
-
410
- query.fetchOrder(orderId).executeSingle
411
- end
412
-
413
-
414
- ###
415
- # Fetch single facets by id and group id
416
- #
417
- # * *Args* :
418
- # - +params+ -> Hash containing 2 keys: "id", "group_id"
419
- #
420
- # * *Returns* :
421
- # - AboutYou::SDK::Model::Facet
422
- ###
423
- def fetchFacet(params)
424
-
425
- query.fetchFacet(params).executeSingle
426
- end
427
-
428
-
429
- ###
430
- # Returns the result of a suggest API request.
431
- # Suggestions are words that are often searched together
432
- # with the searchword you pass (e.g. "stretch" for "jeans").
433
- #
434
- # * *Args* :
435
- # - +searchword+ -> The search string to search for
436
- # * *Returns* :
437
- # - an Array containing the suggestions
438
- ###
439
- def fetchSuggest(searchword)
440
-
441
- query.fetchSuggest(searchword).executeSingle
442
- end
443
-
444
-
445
- ###
446
- # Returns the list of child apps
447
- #
448
- # * *returns* :
449
- # - an Array containing all child Apps
450
- ###
451
- def fetchChildApps
452
-
453
- query.fetchChildApps.executeSingle
454
- end
455
-
456
-
457
- ###
458
- # Method for getting the query
459
- #
460
- # * *Returns* :
461
- # - an Instance of AboutYou::SDK::Query
462
- ###
463
- def query
464
-
465
- AboutYou::SDK::Query.new(self.aboutYouClient, modelFactory)
466
- end
467
-
468
-
469
- ###
470
- # Method for getting the model factory. If no model factory is set it initializes the default one
471
- #
472
- # * *Returns* :
473
- # - an Instance of AboutYou::SDK::Factory::DefaultModelFactory
474
- ###
475
- def modelFactory
476
-
477
- unless self.modelFactoryInstance
478
- self.initDefaultFactory
479
- end
480
-
481
- self.modelFactoryInstance
482
- end
483
-
484
-
485
- ###
486
- # Method for getting the product search criteria base class, on which you can specify your criteria
487
- #
488
- # * *Args* :
489
- # - +sessionId+ -> a string containing the session id [optional]
490
- # * *Returns* :
491
- # - AboutYou::SDK::Criteria::ProductSearchCriteria
492
- ###
493
- def productSearchCriteria(sessionId=nil)
494
- unless sessionId
495
- sessionId = self.sessionId
496
- end
497
-
498
- AboutYou::SDK::Criteria::ProductSearchCriteria.new(self.sessionId)
499
- end
500
-
501
-
502
- ###
503
- # Returns the URL to the Collins JavaScript file for helper functions
504
- # to add product variants into the basket of AboutYou or auto-resizing
505
- # the Iframe. This URL may be changed in future, so please use this method instead
506
- # of hardcoding the URL into your HTML template.
507
- #
508
- # * *Returns* :
509
- # - a string containing an url to the javascript file
510
- ###
511
- def javaScriptURL
512
-
513
- if self.environment === AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
514
- '//devcenter-staging-www1.pub.collins.kg:81/appjs/'+String(self.appId)+'.js'
515
- else
516
- '//developer.aboutyou.de/appjs/'+String(self.appId)+'.js'
517
- end
518
- end
519
-
520
-
521
- ###
522
- # Returns a HTML script tag that loads the Collins JavaScript fie.
523
- #
524
- # * *Returns* :
525
- # - a string containing an HTML script tag
526
- ###
527
- def javaScriptTag
528
-
529
- '<script type="text/javascript" src="' + self.javaScriptURL + '"></script>'
530
- end
531
-
532
-
533
- ###
534
- # Setter-Method for the app-Credentials
535
- #
536
- # * *Args* :
537
- # - +appId+ -> the id of an app
538
- # - +appPassword+ -> the auth-token for the app
539
- ###
540
- def appCredentials=(appId, appPassword)
541
-
542
- self.appId = appId
543
- self.appPassword = appPassword
544
- self.aboutYouClient.appId= appId
545
- self.aboutYouClient.appPassword = appPassword
546
- end
547
-
548
-
549
- ###
550
- # Setter-Method for the api endpoint
551
- #
552
- # * *Args* :
553
- # - +apiEndPoint+ -> the endpoint can be the string 'stage' or 'live', then the default endpoints will be used or an absolute url
554
- ###
555
- def apiEndpoint=(apiEndPoint)
556
-
557
- self.aboutYouClient.apiEndpoint=(apiEndPoint)
558
- end
559
-
560
-
561
- ###
562
- # Setter-Method for the base image url
563
- #
564
- # * *Args* :
565
- # - +baseImageUrl+ -> nil will reset to the default url, false to get relative urls, otherwise the url prefix
566
- ###
567
- def baseImageUrl= (baseImageUrl = nil)
568
-
569
- if !baseImageUrl
570
- @baseImageUrl = IMAGE_URL_LIVE
571
- elsif baseImageUrl.is_a? String
572
- @baseImageUrl = baseImageUrl.gsub(/[#{'/'}]+$/,'')
573
- else
574
- @baseImageUrl = ''
575
- end
576
-
577
- self.modelFactory.baseImageUrl = self.baseImageUrl
578
- end
579
-
580
-
581
- ###
582
- # initializes the default model factory
583
- #
584
- # * *Args* :
585
- # - +cache+ -> an Instance of the used cache [optional]
586
- ###
587
- def initDefaultFactory(cache = nil)
588
- self.modelFactoryInstance = AboutYou::SDK::Factory::DefaultModelFactory.new(self)
589
-
590
- self.modelFactoryInstance.initializeManagers(
591
- AboutYou::SDK::Model::FacetManager::DefaultFacetManager.new(cache, self.appId, self),
592
- AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager.new(cache, self.appId, self)
593
- )
594
- self.modelFactoryInstance.baseImageUrl=(self.baseImageUrl)
595
- end
596
- end