aboutyou-sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,15 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class CategoriesResult
5
+ attr_accessor :categories
6
+ attr_accessor :categoriesNotFound
7
+
8
+ def initialize(categoryManager, ids)
9
+ @ids = ids
10
+ @categories = categoryManager.categories(ids, AboutYou::SDK::Model::Category::ALL)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,126 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class Category
5
+ ALL = false;
6
+ ACTIVE_ONLY = true;
7
+
8
+ # @var integer */
9
+ @id;
10
+ attr_accessor :id
11
+
12
+ # @var string */
13
+ @name;
14
+ attr_accessor :name
15
+
16
+ # @var boolean */
17
+ @isActive;
18
+ attr_accessor :isActive
19
+
20
+ # @var integer */
21
+ @position;
22
+ attr_accessor :position
23
+
24
+ # @var Category */
25
+ @parentId;
26
+ attr_accessor :parentId
27
+
28
+ # @var Category[] */
29
+ @allsubcategories;
30
+ attr_accessor :allsubcategories
31
+
32
+ # @var Category[] */
33
+ @activesubcategories;
34
+ attr_accessor :activesubcategories
35
+
36
+ # @var integer */
37
+ @productCount;
38
+ attr_accessor :productCount
39
+
40
+ @categoryManager
41
+ attr_accessor :categoryManager
42
+
43
+ def initialize()
44
+
45
+ self.allsubcategories = Array(nil);
46
+ self.activesubcategories = Array(nil);
47
+ end
48
+
49
+ ###
50
+ # @param object $jsonObject json as object tree
51
+ # @param ModelFactoryInterface $factory
52
+ # @param Category|null $parent
53
+ #
54
+ # @return static
55
+ ###
56
+ def self.createFromJson(jsonObject, catManager)
57
+ category = self.new
58
+
59
+ category.parentId = jsonObject["parent"];
60
+ category.id = jsonObject["id"];
61
+ category.name = jsonObject["name"];
62
+ category.isActive = jsonObject["active"];
63
+ category.position = jsonObject["position"];
64
+ category.categoryManager = catManager
65
+
66
+ return category;
67
+ end
68
+
69
+
70
+ ###
71
+ # @return boolean
72
+ ###
73
+ def isPathActive()
74
+
75
+ parent = self.parent();
76
+
77
+ return self.isActive && (parent == nil || parent.isPathActive());
78
+ end
79
+
80
+
81
+ ###
82
+ # @return Category|null
83
+ ###
84
+ def parent
85
+
86
+ if (!self.parentId)
87
+ return nil;
88
+ end
89
+
90
+ return self.categoryManager.category(self.parentId);
91
+ end
92
+
93
+ ###
94
+ # @param bool $activeOnly
95
+ #
96
+ # @return Category[]
97
+ ###
98
+ def subcategories(activeOnly = ACTIVE_ONLY)
99
+ subcategories = self.categoryManager.subcategories(self.id, activeOnly);
100
+ if (activeOnly == ALL)
101
+ return subcategories;
102
+ end
103
+ result = Hash.new
104
+
105
+ subcategories.each do |key,subcat|
106
+ if subcat.isActive
107
+ result[key] = subcat
108
+ end
109
+ end;
110
+
111
+ return result
112
+ end
113
+
114
+ ###
115
+ # @return Category[]
116
+ ###
117
+ def breadcrumb()
118
+ breadcrumb = self.parent() ? self.parent().breadcrumb() : Array(nil);
119
+ breadcrumb.push(self)
120
+
121
+ return breadcrumb;
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,172 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ module CategoryManager
5
+ class DefaultCategoryManager
6
+
7
+ DEFAULT_CACHE_DURATION = 7200;
8
+
9
+ # @var Category[] */
10
+ @categories;
11
+ attr_accessor :categories
12
+
13
+ # @var integer[] */
14
+ @parentChildIds;
15
+ attr_accessor :parentChildIds
16
+
17
+ # @var Cache */
18
+ @cache;
19
+ attr_accessor :cache
20
+
21
+ @cacheKey;
22
+ attr_accessor :cacheKey
23
+
24
+ ###
25
+ # @param string $appId This must set, when you use more then one instances with different apps
26
+ # @param CacheProvider $cache
27
+ ###
28
+ def initialize(cache = nil, appId = '')
29
+
30
+ self.cache = cache;
31
+ self.cacheKey = 'AY:SDK:' + String(appId) + ':categories';
32
+
33
+ self.loadCachedCategories();
34
+ end
35
+
36
+ def loadCachedCategories()
37
+
38
+ if (self.cache)
39
+ self.categories = self.cache.fetch(self.cacheKey) ? self.cache.fetch(self.cacheKey): nil;
40
+ end
41
+ end
42
+
43
+ def cacheCategories()
44
+
45
+ if (self.cache)
46
+ self.cache.save(self.cacheKey, self.categories,DEFAULT_CACHE_DURATION);
47
+ end
48
+ end
49
+
50
+ def clearCache()
51
+
52
+ if (self.cache)
53
+ self.cache.delete(self.cacheKey);
54
+ end
55
+ end
56
+
57
+ ###
58
+ # @param \stdObject $jsonObject
59
+ # @param ModelFactoryInterface $factory
60
+ #
61
+ # @return $this
62
+ ###
63
+ def parseJson(jsonObject, factory)
64
+ self.categories = Hash.new
65
+ self.parentChildIds = jsonObject["parent_child"]
66
+
67
+ jsonObject["ids"].each do |id, jsonCategory|
68
+ @categories[id] = factory.createCategory(jsonCategory, self);
69
+ end
70
+ self.cacheCategories();
71
+
72
+ return self
73
+ end
74
+
75
+ ###
76
+ # {@inheritdoc}
77
+ ###
78
+ def isEmpty()
79
+
80
+ return (@categories == nil);
81
+ end
82
+
83
+ ###
84
+ # {@inheritdoc}
85
+ ###
86
+ def categoryTree(activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
87
+
88
+ return self.subcategories(0, activeOnly);
89
+ end
90
+
91
+ ###
92
+ # {@inheritdoc}
93
+ ###
94
+ def category(id)
95
+ if !(self.categories[String(id)])
96
+ return nil;
97
+ end
98
+
99
+ return self.categories[String(id)];
100
+ end
101
+
102
+ ###
103
+ # {@inheritdoc}
104
+ ###
105
+ def categories(ids=nil, activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
106
+ if (ids == nil)
107
+ return @categories
108
+ end
109
+ if !(@categories)
110
+ return Hash.new;
111
+ end
112
+ categories = Hash.new
113
+ ids.each do |id|
114
+ if (@categories[id])
115
+ category = @categories[id];
116
+ if (activeOnly == AboutYou::SDK::Model::Category::ALL || category.isActive)
117
+ categories[id] = category;
118
+ end
119
+ end
120
+ end
121
+ return categories;
122
+ end
123
+
124
+ def allCategories()
125
+
126
+ return self.categories;
127
+ end
128
+
129
+ ###
130
+ # {@inheritdoc}
131
+ ###
132
+ def subcategories(id, activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
133
+ if !(self.parentChildIds.key?(String(id)))
134
+ return Array(nil);
135
+ end
136
+
137
+ ids = self.parentChildIds[String(id)];
138
+ return self.categories(ids, activeOnly);
139
+ end
140
+
141
+ ###
142
+ # {@inheritdoc}
143
+ ###
144
+ def firstCategoryByName(name, activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
145
+
146
+ self.categories.each do |category|
147
+ if (category.name == name && (activeOnly == AboutYou::SDK::Model::Category::ACTIVE_ONLY || category.isActive))
148
+ return category;
149
+ end
150
+ end
151
+
152
+ return nil;
153
+ end
154
+
155
+ ###
156
+ # {@inheritdoc}
157
+ ###
158
+ def categoriesByName(name, activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
159
+
160
+ resultCategories = Array(nil)
161
+ self.categories.each do |category|
162
+ if(category.name == name && (activeOnly == AboutYou::SDK::Model::Category::ALL || category.isActive))
163
+ resultCategories.push(category)
164
+ end
165
+ end
166
+ return resultCategories;
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,35 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class CategoryTree
5
+ # @var CategoryManagerInterface */
6
+ attr_accessor :categoryManager;
7
+
8
+ def initialize(categoryManager)
9
+
10
+ self.categoryManager = categoryManager;
11
+ end
12
+
13
+ ###
14
+ # @param bool $activeOnly if true, then only active categories will returned, otherwise all categories
15
+ #
16
+ # @return array|Category[]
17
+ ###
18
+ def categories(activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
19
+
20
+ return self.categoryManager.categoryTree(activeOnly);
21
+ end
22
+
23
+ ###
24
+ # Count active root all categories
25
+ #
26
+ # {@inheritdoc}
27
+ ###
28
+ def count()
29
+
30
+ return self.categories(true).count;
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,105 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ class Facet
5
+
6
+ @jsonObject
7
+ attr_accessor :jsonObject
8
+
9
+ # @var integer */
10
+ @id;
11
+ attr_accessor :id
12
+
13
+ # @var string */
14
+ @name;
15
+ attr_accessor :name
16
+
17
+ # @var string */
18
+ @value;
19
+ attr_accessor :value
20
+
21
+ # @var integer */
22
+ @groupId;
23
+ attr_accessor :groupId
24
+
25
+ # @var string */
26
+ @groupName;
27
+ attr_accessor :groupName
28
+
29
+ # @var array */
30
+ @options;
31
+ attr_accessor :options
32
+
33
+ ###
34
+ # @param integer $id
35
+ # @param string $name
36
+ # @param string $value
37
+ # @param integer $groupId
38
+ # @param string $groupName
39
+ # @param array $options
40
+ ###
41
+ def initialize(id, name, value, groupId, groupName, options = nil)
42
+
43
+ self.id = id;
44
+ self.name = name;
45
+ self.value = value;
46
+ self.groupId = groupId;
47
+ self.groupName = groupName;
48
+ self.options = options;
49
+ end
50
+
51
+
52
+ ###
53
+ # @param $jsonObject
54
+ #
55
+ # @return static
56
+ ###
57
+ def self.createFromJson(jsonObject)
58
+
59
+ return self.new(
60
+ jsonObject["facet_id"],
61
+ jsonObject["name"],
62
+ (jsonObject["value"]) ? jsonObject["value"] : nil,
63
+ jsonObject["id"],
64
+ jsonObject["group_name"],
65
+ jsonObject["options"] ? jsonObject["options"] : nil
66
+ )
67
+ end
68
+
69
+
70
+ ###
71
+ # a facet is unique with the combination about id and group id
72
+ #
73
+ # @return string
74
+ ###
75
+ def uniqueKey(groupId = nil, facetId = nil)
76
+
77
+ return String(self.groupId) + ':' + String(self.id) if(groupId == nil && facetId == nil)
78
+ return String(groupId) + ':' + String(facetId) if(groupId != nil && facetId != nil)
79
+ return nil
80
+ end
81
+
82
+
83
+ ###
84
+ # Get option value.
85
+ #
86
+ # @param string $key The option key.
87
+ #
88
+ # @return mixed
89
+ ###
90
+ def option(key)
91
+
92
+ if (self.options)
93
+ self.options.each do |option|
94
+ if (option["key"] == key)
95
+ return option["value"];
96
+ end
97
+ end
98
+ end
99
+
100
+ return nil;
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end