aboutyou-sdk 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/aboutyou-sdk/Model/Product.rb +11 -11
- data/tests/testProductsByIds.rb +4 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjIwODhmODg5MDU3ZTU5YTYwMTZjMTU2ZGUyOGMxMjEwNDYxZmQ1NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzBkNjZiNzZlODM0ZDljYjc3YzIwMTJlNDk3ZDU3YmRiNTMzYWQ0YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTM5Nzg4OTI0YTNkMzE3ZTQ4MmEzYzNkMmYxYjY5ODIzODFmN2M4OWZmYmM4
|
10
|
+
MTJlNWQwN2Q4ZjZhNGQ4MjIxOGU2N2I0N2IxYjBlOTcyNjMxZmE4NWRmZDc0
|
11
|
+
ZTAyNWM2NDZjMDBlNGMwZmIzZjQwMThlMTBhNzUwYjFhNDA0YjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzY2ZGEwMmU4NTI1MmUwNjgwOTU5YWQ2OTBlN2Q0MTgzNTI5ZTFhOWFkMzE4
|
14
|
+
NzcwMDAzOTI3NGFmYjBlNDcwMDY5Yzc5YjlmYzRhNmEyNThkMTZlN2JmODk0
|
15
|
+
YTllYzNjNzBiODNjODU3ZjA3Y2RhODdlYTlhNTliNTZkNmU4ZDA=
|
@@ -33,8 +33,8 @@ module AboutYou
|
|
33
33
|
attr_accessor :activeLeafCategories
|
34
34
|
|
35
35
|
|
36
|
-
def createFromJson(jsonObject, factory, appId)
|
37
|
-
product = self.new
|
36
|
+
def self.createFromJson(jsonObject, factory, appId)
|
37
|
+
product = self.new
|
38
38
|
|
39
39
|
# these are required fields
|
40
40
|
raise 'MalformedJsonException!' unless jsonObject["id"] || jsonObject["name"]
|
@@ -56,8 +56,8 @@ module AboutYou
|
|
56
56
|
product.maxSavingsPrice = jsonObject["max_savings"] ? jsonObject["max_savings"] : nil
|
57
57
|
product.maxSavingsPercentage = jsonObject["max_savings_percentage"] ? jsonObject["max_savings_percentage"] : nil
|
58
58
|
|
59
|
-
product.defaultImage = jsonObject["default_image"] ? jsonObject["default_image"] : nil
|
60
|
-
product.defaultVariant = jsonObject["default_variant"] ? jsonObject["default_variant"] : nil
|
59
|
+
product.defaultImage = jsonObject["default_image"] ? factory.createImage(jsonObject["default_image"]) : nil
|
60
|
+
product.defaultVariant = jsonObject["default_variant"] ? factory.createVariant(jsonObject["default_variant"]) : nil
|
61
61
|
|
62
62
|
product.variants = product.parseVariants(jsonObject, factory, product)
|
63
63
|
product.inactiveVariants = product.parseVariants(jsonObject, factory, product, 'inactive_variants')
|
@@ -66,15 +66,15 @@ module AboutYou
|
|
66
66
|
key = 'categories.' + String(appId)
|
67
67
|
product.categoryIdPaths = jsonObject["key"] ? jsonObject["key"] : []
|
68
68
|
|
69
|
-
product.facetIds
|
69
|
+
product.facetIds = product.parseFacetIds(jsonObject)
|
70
70
|
|
71
71
|
product
|
72
72
|
end
|
73
73
|
|
74
74
|
def parseVariants(jsonObject, factory, product, attributeName = 'variants')
|
75
75
|
variants = {}
|
76
|
-
|
77
|
-
jsonObject[
|
76
|
+
if jsonObject.key?(attributeName) && !jsonObject[attributeName].empty?
|
77
|
+
jsonObject[attributeName].each do |jsonVariant|
|
78
78
|
variants[jsonVariant["id"]] = factory.createVariant(jsonVariant, product)
|
79
79
|
end
|
80
80
|
end
|
@@ -84,7 +84,7 @@ module AboutYou
|
|
84
84
|
|
85
85
|
def parseStyles(jsonObject, factory)
|
86
86
|
styles = []
|
87
|
-
|
87
|
+
if jsonObject.key?("styles") && !jsonObject["styles"].empty?
|
88
88
|
jsonObject["styles"].each do |style|
|
89
89
|
styles.push(factory.createProduct(style))
|
90
90
|
end
|
@@ -109,15 +109,15 @@ module AboutYou
|
|
109
109
|
def parseFacetIds(jsonObject)
|
110
110
|
ids = self.parseFacetIdsInAttributesMerged(jsonObject)
|
111
111
|
|
112
|
-
ids = self.parseFacetIdsInVariants(jsonObject) if ids ===
|
112
|
+
ids = self.parseFacetIdsInVariants(jsonObject) if ids === nil
|
113
113
|
|
114
|
-
ids = self.parseFacetIdsInBrand(jsonObject) if $ids ===
|
114
|
+
ids = self.parseFacetIdsInBrand(jsonObject) if $ids === nil
|
115
115
|
|
116
116
|
ids != nil ? ids : []
|
117
117
|
end
|
118
118
|
|
119
119
|
def parseFacetIdsInAttributesMerged(jsonObject)
|
120
|
-
return nil
|
120
|
+
return nil unless jsonObject["attributes_merged"]
|
121
121
|
|
122
122
|
self.parseAttributesJson(jsonObject["attributes_merged"])
|
123
123
|
end
|
data/tests/testProductsByIds.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'sinatra'
|
2
|
-
require '
|
2
|
+
require 'pry_debug'
|
3
|
+
require_relative '../lib/aboutyou-sdk.rb'
|
3
4
|
|
4
5
|
class AY
|
5
6
|
attr_accessor :result
|
@@ -26,8 +27,8 @@ shop.result = ""
|
|
26
27
|
productsResult = shop.fetchProductsByIds([661132, 660971, 661367, 661361, 661350, 661345],["default_image", "variants"])
|
27
28
|
productsResult.products.each do |key, prod|
|
28
29
|
shop.result = shop.result + '<ul>' + '<li>' + String(prod.id) + ' : ' + prod.name + '</br>' + '<img src="' + prod.defaultImage.url + '">'
|
29
|
-
prod.variants.
|
30
|
-
shop.result = shop.result + '<ul>' + '<li>' + 'Variante: '
|
30
|
+
prod.variants.each do |key, var|
|
31
|
+
shop.result = shop.result + '<ul>' + '<li>' + 'Variante: ' + String(var.id) + '</ul>'
|
31
32
|
end
|
32
33
|
shop.result = shop.result + '</li>' + '</ul>'
|
33
34
|
end
|