aboutyou-sdk 0.0.7 → 0.0.8
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.rb +443 -489
- data/lib/aboutyou-sdk/Client.rb +86 -111
- data/lib/aboutyou-sdk/Constants.rb +34 -34
- data/lib/aboutyou-sdk/Criteria/ProductSearchCriteria.rb +1 -1
- data/lib/aboutyou-sdk/Query.rb +219 -218
- data/lib/aboutyou-sdk/QueryBuilder.rb +414 -432
- data/tests/testAutocomplete.rb +0 -1
- data/tests/testFacets.rb +2 -1
- metadata +2 -2
data/lib/aboutyou-sdk/Client.rb
CHANGED
@@ -2,124 +2,99 @@ module AboutYou
|
|
2
2
|
module SDK
|
3
3
|
class Client
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@apiEndPoint = API_END_POINT_STAGE;
|
49
|
-
when apiEndPoint=='sandbox'
|
50
|
-
@apiEndPoint = API_END_POINT_SANDBOX;
|
51
|
-
when apiEndPoint=='live'
|
52
|
-
@apiEndPoint = API_END_POINT_LIVE;
|
53
|
-
else
|
54
|
-
@apiEndPoint = apiEndPoint;
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
###
|
60
|
-
# @return string
|
61
|
-
###
|
62
|
-
def getPageId()
|
63
|
-
|
64
|
-
@pageId;
|
5
|
+
API_END_POINT_STAGE = 'http://shop-api.staging.aboutyou.de/api'
|
6
|
+
API_END_POINT_SANDBOX = 'http://shop-api.sandbox.aboutyou.de/api'
|
7
|
+
API_END_POINT_LIVE = 'https://shop-api.aboutyou.de/api'
|
8
|
+
|
9
|
+
attr_accessor :appId
|
10
|
+
attr_accessor :appPassword
|
11
|
+
attr_accessor :apiEndPoint
|
12
|
+
attr_accessor :pageId
|
13
|
+
|
14
|
+
def initialize(appId, appPassword, apiEndPoint = 'stage', logger = nil)
|
15
|
+
|
16
|
+
self.appId = appId
|
17
|
+
self.appPassword = appPassword
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
###
|
22
|
+
# @param appId the app id for client authentication
|
23
|
+
# @param appPassword the app password/token for client authentication.
|
24
|
+
###
|
25
|
+
def appCredentials=(appId, appPassword)
|
26
|
+
|
27
|
+
self.appId= appId
|
28
|
+
self.appPassword= appPassword
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
###
|
33
|
+
# @param apiEndPoint the endpoint can be the string 'stage' or 'live',
|
34
|
+
# then the default endpoints will be used or
|
35
|
+
# an absolute url
|
36
|
+
###
|
37
|
+
def apiEndpoint=(apiEndPoint)
|
38
|
+
|
39
|
+
case
|
40
|
+
when apiEndPoint=='stage'
|
41
|
+
self.apiEndPoint = API_END_POINT_STAGE
|
42
|
+
when apiEndPoint=='sandbox'
|
43
|
+
self.apiEndPoint = API_END_POINT_SANDBOX
|
44
|
+
when apiEndPoint=='live'
|
45
|
+
self.apiEndPoint = API_END_POINT_LIVE
|
46
|
+
else
|
47
|
+
self.apiEndPoint = apiEndPoint
|
65
48
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
if (@pageId)
|
89
|
-
request = {
|
90
|
-
:body=>body,
|
91
|
-
:basic_auth => { :username => @appId , :password => @appPassword},
|
92
|
-
:headers => { 'Content-Type' => 'application/json',
|
93
|
-
'Accept-Encoding' => 'gzip,deflate',
|
94
|
-
'X-Page-ID'=> @pageId }
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
###
|
53
|
+
# Builds a JSON string representing the request data via Guzzle.
|
54
|
+
# Executes the API request.
|
55
|
+
#
|
56
|
+
# @param body the queries as json string
|
57
|
+
###
|
58
|
+
def request(body)
|
59
|
+
|
60
|
+
if self.pageId
|
61
|
+
request = {
|
62
|
+
:body=>body,
|
63
|
+
:basic_auth => {
|
64
|
+
:username => self.appId,
|
65
|
+
:password => self.appPassword
|
66
|
+
},
|
67
|
+
:headers => {
|
68
|
+
'Content-Type' => 'application/json',
|
69
|
+
'Accept-Encoding' => 'gzip,deflate',
|
70
|
+
'X-Page-ID'=> self.pageId
|
95
71
|
}
|
96
|
-
|
97
|
-
|
72
|
+
}
|
73
|
+
else
|
74
|
+
request = {
|
98
75
|
:body=>body,
|
99
|
-
:basic_auth => {
|
100
|
-
|
101
|
-
|
76
|
+
:basic_auth => {
|
77
|
+
:username => self.appId,
|
78
|
+
:password => self.appPassword
|
79
|
+
},
|
80
|
+
:headers => {
|
81
|
+
'Content-Type' => 'application/json',
|
82
|
+
'Accept-Encoding' => 'gzip,deflate'
|
83
|
+
}
|
102
84
|
}
|
103
|
-
|
85
|
+
end
|
104
86
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
if (response.is_a? Array)
|
112
|
-
raise 'result is not array'
|
113
|
-
end
|
114
|
-
rescue
|
115
|
-
raise
|
116
|
-
end
|
117
|
-
rescue
|
118
|
-
raise
|
87
|
+
response = HTTParty.post("https://shop-api.aboutyou.de/api", request)
|
88
|
+
|
89
|
+
unless response.code >= 200 && response.code < 300 || response.code == 304
|
90
|
+
raise String(response.code)
|
91
|
+
unless response.is_a? Array
|
92
|
+
raise 'result is not array'
|
119
93
|
end
|
120
|
-
|
121
|
-
return JSON.parse(response.body)
|
122
94
|
end
|
95
|
+
|
96
|
+
JSON.parse(response.body)
|
97
|
+
end
|
123
98
|
end
|
124
99
|
end
|
125
100
|
end
|
@@ -6,43 +6,43 @@
|
|
6
6
|
module AboutYou
|
7
7
|
module SDK
|
8
8
|
module Constants
|
9
|
-
SDK_VERSION = 0.1
|
10
|
-
FACET_BRAND = 0
|
11
|
-
FACET_COLOR = 1
|
12
|
-
FACET_SIZE = 2
|
13
|
-
FACET_GENDERAGE = 3
|
14
|
-
FACET_CUPSIZE = 4
|
15
|
-
FACET_LENGTH = 5
|
16
|
-
FACET_DIMENSION3 = 6
|
17
|
-
FACET_SIZE_CODE = 206
|
18
|
-
FACET_SIZE_RUN = 172
|
19
|
-
FACET_CLOTHING_UNISEX_INT = 173
|
20
|
-
FACET_CLOTHING_UNISEX_INCH = 174
|
21
|
-
FACET_SHOES_UNISEX_EUR = 194
|
22
|
-
FACET_CLOTHING_WOMEN_DE = 175
|
23
|
-
FACET_CLOTHING_UNISEX_ONESIZE = 204
|
24
|
-
FACET_SHOES_UNISEX_ADIDAS_EUR = 195
|
25
|
-
FACET_CLOTHING_WOMEN_BELTS_CM = 181
|
26
|
-
FACET_CLOTHING_WOMEN_INCH = 180
|
27
|
-
FACET_CLOTHING_MEN_BELTS_CM = 190
|
28
|
-
FACET_CLOTHING_MEN_INCH = 189
|
29
|
-
FACET_CLOTHING_MEN_DE = 187
|
30
|
-
FACET_CONDITION = 234
|
31
|
-
FACET_QUANTITY_PER_PACK = 263
|
32
|
-
FACET_SEASON_CODE = 289
|
9
|
+
SDK_VERSION = 0.1
|
10
|
+
FACET_BRAND = 0
|
11
|
+
FACET_COLOR = 1
|
12
|
+
FACET_SIZE = 2
|
13
|
+
FACET_GENDERAGE = 3
|
14
|
+
FACET_CUPSIZE = 4
|
15
|
+
FACET_LENGTH = 5
|
16
|
+
FACET_DIMENSION3 = 6
|
17
|
+
FACET_SIZE_CODE = 206
|
18
|
+
FACET_SIZE_RUN = 172
|
19
|
+
FACET_CLOTHING_UNISEX_INT = 173
|
20
|
+
FACET_CLOTHING_UNISEX_INCH = 174
|
21
|
+
FACET_SHOES_UNISEX_EUR = 194
|
22
|
+
FACET_CLOTHING_WOMEN_DE = 175
|
23
|
+
FACET_CLOTHING_UNISEX_ONESIZE = 204
|
24
|
+
FACET_SHOES_UNISEX_ADIDAS_EUR = 195
|
25
|
+
FACET_CLOTHING_WOMEN_BELTS_CM = 181
|
26
|
+
FACET_CLOTHING_WOMEN_INCH = 180
|
27
|
+
FACET_CLOTHING_MEN_BELTS_CM = 190
|
28
|
+
FACET_CLOTHING_MEN_INCH = 189
|
29
|
+
FACET_CLOTHING_MEN_DE = 187
|
30
|
+
FACET_CONDITION = 234
|
31
|
+
FACET_QUANTITY_PER_PACK = 263
|
32
|
+
FACET_SEASON_CODE = 289
|
33
33
|
|
34
|
-
SORT_RELEVANCE = 'relevance'
|
35
|
-
SORT_UPDATED = 'updated_date'
|
36
|
-
SORT_CREATED = 'created_date'
|
37
|
-
SORT_MOST_VIEWED = 'most_viewed'
|
38
|
-
SORT_PRICE = 'price'
|
34
|
+
SORT_RELEVANCE = 'relevance'
|
35
|
+
SORT_UPDATED = 'updated_date'
|
36
|
+
SORT_CREATED = 'created_date'
|
37
|
+
SORT_MOST_VIEWED = 'most_viewed'
|
38
|
+
SORT_PRICE = 'price'
|
39
39
|
|
40
|
-
TYPE_PRODUCTS = 'products'
|
41
|
-
TYPE_CATEGORIES = 'categories'
|
40
|
+
TYPE_PRODUCTS = 'products'
|
41
|
+
TYPE_CATEGORIES = 'categories'
|
42
42
|
|
43
|
-
API_ENVIRONMENT_STAGE = 'stage'
|
44
|
-
API_ENVIRONMENT_SANDBOX = 'sandbox'
|
45
|
-
API_ENVIRONMENT_LIVE = 'live'
|
43
|
+
API_ENVIRONMENT_STAGE = 'stage'
|
44
|
+
API_ENVIRONMENT_SANDBOX = 'sandbox'
|
45
|
+
API_ENVIRONMENT_LIVE = 'live'
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
data/lib/aboutyou-sdk/Query.rb
CHANGED
@@ -1,261 +1,262 @@
|
|
1
|
-
|
1
|
+
require_relative 'QueryBuilder.rb'
|
2
|
+
|
2
3
|
module AboutYou
|
3
4
|
module SDK
|
4
5
|
class Query
|
5
6
|
include AboutYou::SDK::QueryBuilder
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
attr_accessor :client
|
11
|
-
attr_accessor :query
|
12
|
-
attr_accessor :mapping
|
13
|
-
attr_accessor :factory
|
14
|
-
attr_accessor :ghostQuery
|
15
|
-
attr_accessor :allQuery
|
16
|
-
|
8
|
+
QUERY_TREE = 'category_tree'
|
9
|
+
QUERY_FACETS = 'facets'
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
self.client = client
|
25
|
-
self.query=Array(nil)
|
26
|
-
self.ghostQuery = Array(nil)
|
27
|
-
self.allQuery = Array(nil)
|
28
|
-
self.factory=factory
|
29
|
-
self.mapping = Hash[
|
30
|
-
'autocompletion' => 'createAutocomplete',
|
31
|
-
'basket' => 'createBasket',
|
32
|
-
'category' => 'createCategoriesResult',
|
33
|
-
'category_tree' => 'createCategoryTree',
|
34
|
-
'facets' => 'createFacetsList',
|
35
|
-
'facet' => 'createFacetList',
|
36
|
-
'facet_types' => 'createFacetTypes',
|
37
|
-
'products' => 'createProductsResult',
|
38
|
-
'products_eans' => 'createProductsEansResult',
|
39
|
-
'product_search' => 'createProductSearchResult',
|
40
|
-
'suggest' => 'createSuggest',
|
41
|
-
'get_order' => 'createOrder',
|
42
|
-
'initiate_order' => 'initiateOrder',
|
43
|
-
'child_apps' => 'createChildApps',
|
44
|
-
'live_variant' => 'createVariantsResult'
|
45
|
-
]
|
46
|
-
end
|
47
|
-
|
48
|
-
###
|
49
|
-
# @param string $searchword The prefix search word to search for.
|
50
|
-
# @param int $limit Maximum number of results.
|
51
|
-
# @param array $types Array of types to search for (Constants::TYPE_...).
|
52
|
-
#
|
53
|
-
# @return $this
|
54
|
-
#
|
55
|
-
# @throws \InvalidArgumentException
|
56
|
-
###
|
57
|
-
def fetchAutocomplete(searchword,limit = nil,types = nil)
|
58
|
-
|
59
|
-
super(searchword, limit, types);
|
11
|
+
attr_accessor :client
|
12
|
+
attr_accessor :query
|
13
|
+
attr_accessor :mapping
|
14
|
+
attr_accessor :factory
|
15
|
+
attr_accessor :ghostQuery
|
16
|
+
attr_accessor :allQuery
|
60
17
|
|
61
|
-
self.requireCategoryTree;
|
62
|
-
self.requireFacets;
|
63
18
|
|
64
|
-
|
65
|
-
|
19
|
+
def initialize(client, factory)
|
20
|
+
self.client = client
|
21
|
+
self.query= []
|
22
|
+
self.ghostQuery = []
|
23
|
+
self.allQuery = []
|
24
|
+
self.factory=factory
|
25
|
+
self.mapping = {
|
26
|
+
'autocompletion' => 'createAutocomplete',
|
27
|
+
'basket' => 'createBasket',
|
28
|
+
'category' => 'createCategoriesResult',
|
29
|
+
'category_tree' => 'createCategoryTree',
|
30
|
+
'facets' => 'createFacetsList',
|
31
|
+
'facet' => 'createFacetList',
|
32
|
+
'facet_types' => 'createFacetTypes',
|
33
|
+
'products' => 'createProductsResult',
|
34
|
+
'products_eans' => 'createProductsEansResult',
|
35
|
+
'product_search' => 'createProductSearchResult',
|
36
|
+
'suggest' => 'createSuggest',
|
37
|
+
'get_order' => 'createOrder',
|
38
|
+
'initiate_order' => 'initiateOrder',
|
39
|
+
'child_apps' => 'createChildApps',
|
40
|
+
'live_variant' => 'createVariantsResult'
|
41
|
+
}
|
42
|
+
end
|
66
43
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
44
|
+
###
|
45
|
+
# @param string $searchword The prefix search word to search for.
|
46
|
+
# @param int $limit Maximum number of results.
|
47
|
+
# @param array $types Array of types to search for (Constants::TYPE_...).
|
48
|
+
#
|
49
|
+
# @return $this
|
50
|
+
#
|
51
|
+
# @throws \InvalidArgumentException
|
52
|
+
###
|
53
|
+
def fetchAutocomplete(searchword, limit = nil, types = nil)
|
75
54
|
|
76
|
-
|
77
|
-
self.requireFacets;
|
55
|
+
super(searchword, limit, types)
|
78
56
|
|
79
|
-
|
80
|
-
|
57
|
+
self.requireCategoryTree
|
58
|
+
self.requireFacets
|
81
59
|
|
82
|
-
|
83
|
-
|
84
|
-
# @param array $fields
|
85
|
-
#
|
86
|
-
# @return $this
|
87
|
-
###
|
88
|
-
def fetchProductsByIds(ids,fields = Array(nil))
|
89
|
-
super(ids, fields);
|
90
|
-
if (AboutYou::SDK::Criteria::ProductFields.requiresCategories(fields))
|
91
|
-
self.requireCategoryTree();
|
92
|
-
end
|
93
|
-
if (AboutYou::SDK::Criteria::ProductFields.requiresFacets(fields))
|
94
|
-
self.requireFacets();
|
95
|
-
end
|
60
|
+
return self
|
61
|
+
end
|
96
62
|
|
97
|
-
|
98
|
-
|
63
|
+
###
|
64
|
+
# @param string $sessionId Free to choose ID of the current website visitor.
|
65
|
+
#
|
66
|
+
# @return $this
|
67
|
+
###
|
68
|
+
def fetchBasket(sessionId)
|
99
69
|
|
100
|
-
|
101
|
-
# @param string[] $eans
|
102
|
-
# @param array $fields
|
103
|
-
#
|
104
|
-
# @return $this
|
105
|
-
###
|
106
|
-
def fetchProductsByEans(eans,fields = Array(nil))
|
107
|
-
super(eans, fields);
|
108
|
-
|
109
|
-
if (AboutYou::SDK::Criteria::ProductFields.requiresCategories(fields))
|
110
|
-
self.requireCategoryTree();
|
111
|
-
end
|
112
|
-
if (AboutYou::SDK::Criteria::ProductFields.requiresFacets(fields))
|
113
|
-
self.requireFacets();
|
114
|
-
end
|
70
|
+
super(sessionId)
|
115
71
|
|
116
|
-
|
72
|
+
self.requireCategoryTree
|
73
|
+
self.requireFacets
|
74
|
+
|
75
|
+
return self
|
76
|
+
end
|
77
|
+
|
78
|
+
###
|
79
|
+
# @param string[]|int[] $ids
|
80
|
+
# @param array $fields
|
81
|
+
#
|
82
|
+
# @return $this
|
83
|
+
###
|
84
|
+
def fetchProductsByIds(ids,fields = [])
|
85
|
+
|
86
|
+
super(ids, fields)
|
87
|
+
|
88
|
+
if AboutYou::SDK::Criteria::ProductFields.requiresCategories(fields)
|
89
|
+
self.requireCategoryTree
|
90
|
+
end
|
91
|
+
if AboutYou::SDK::Criteria::ProductFields.requiresFacets(fields)
|
92
|
+
self.requireFacets
|
117
93
|
end
|
118
94
|
|
119
|
-
|
120
|
-
|
121
|
-
#
|
122
|
-
# @return $this
|
123
|
-
###
|
124
|
-
def fetchProductSearch(criteria)
|
95
|
+
return self
|
96
|
+
end
|
125
97
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
98
|
+
###
|
99
|
+
# @param string[] $eans
|
100
|
+
# @param array $fields
|
101
|
+
#
|
102
|
+
# @return $this
|
103
|
+
###
|
104
|
+
def fetchProductsByEans(eans,fields = [])
|
105
|
+
|
106
|
+
super(eans, fields)
|
133
107
|
|
134
|
-
|
108
|
+
if AboutYou::SDK::Criteria::ProductFields.requiresCategories(fields)
|
109
|
+
self.requireCategoryTree
|
110
|
+
end
|
111
|
+
if AboutYou::SDK::Criteria::ProductFields.requiresFacets(fields)
|
112
|
+
self.requireFacets
|
135
113
|
end
|
136
114
|
|
137
|
-
|
138
|
-
|
139
|
-
return self
|
140
|
-
end
|
115
|
+
return self
|
116
|
+
end
|
141
117
|
|
142
|
-
|
143
|
-
|
118
|
+
###
|
119
|
+
# @param ProductSearchCriteria $criteria
|
120
|
+
#
|
121
|
+
# @return $this
|
122
|
+
###
|
123
|
+
def fetchProductSearch(criteria)
|
144
124
|
|
145
|
-
|
125
|
+
super(criteria)
|
126
|
+
|
127
|
+
if criteria.requiresCategories
|
128
|
+
self.requireCategoryTree
|
129
|
+
end
|
130
|
+
if criteria.requiresFacets
|
131
|
+
self.requireFacets
|
146
132
|
end
|
147
133
|
|
148
|
-
|
149
|
-
|
150
|
-
return self;
|
151
|
-
end
|
152
|
-
self.ghostQuery.push(Hash[QUERY_FACETS => Hash[
|
153
|
-
'facets' => Hash.new]])
|
134
|
+
return self
|
135
|
+
end
|
154
136
|
|
155
|
-
|
156
|
-
end
|
137
|
+
def requireCategoryTree(fetchForced = false)
|
157
138
|
|
158
|
-
|
159
|
-
|
160
|
-
###
|
161
|
-
def queryString()
|
162
|
-
result = Array(nil)
|
163
|
-
self.ghostQuery.each do |ghostQuery|
|
164
|
-
(ghostQuery.is_a? Hash) ? result.push(ghostQuery[ghostQuery.keys[0]]) : nil
|
165
|
-
end
|
166
|
-
self.allQuery = result + self.query
|
167
|
-
return (result + self.query).to_json
|
139
|
+
unless fetchForced || self.factory.categoryManager.isEmpty
|
140
|
+
return self
|
168
141
|
end
|
169
142
|
|
143
|
+
self.ghostQuery.push({QUERY_TREE => {
|
144
|
+
'category_tree' => {
|
145
|
+
'version' => '2'
|
146
|
+
}}})
|
170
147
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
if (self.query.empty? && self.ghostQuery.empty?)
|
179
|
-
return Array(nil);
|
180
|
-
end
|
181
|
-
queryString = queryString()
|
182
|
-
result = self.client.request(queryString);
|
183
|
-
parseResult(result, self.query.count > 1)
|
148
|
+
return self
|
149
|
+
end
|
150
|
+
|
151
|
+
def requireFacets(fetchForced = false)
|
152
|
+
unless fetchForced || self.factory.facetManager.isEmpty
|
153
|
+
return self
|
184
154
|
end
|
155
|
+
self.ghostQuery.push({QUERY_FACETS => {
|
156
|
+
'facets' => {}
|
157
|
+
}})
|
185
158
|
|
186
|
-
|
187
|
-
|
188
|
-
#
|
189
|
-
# @return mixed
|
190
|
-
###
|
191
|
-
def executeSingle()
|
159
|
+
return self
|
160
|
+
end
|
192
161
|
|
193
|
-
|
194
|
-
|
162
|
+
###
|
163
|
+
# @return string
|
164
|
+
###
|
165
|
+
def queryString
|
166
|
+
result = []
|
167
|
+
self.ghostQuery.each do |ghostQuery|
|
168
|
+
(ghostQuery.is_a? Hash) ? result.push(ghostQuery[ghostQuery.keys[0]]) : nil
|
195
169
|
end
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
if (jsonResponse == false || !(jsonResponse.is_a? Array) || jsonResponse.count != self.allQuery.count)
|
200
|
-
|
201
|
-
raise 'UnexpectedResultException!'
|
202
|
-
end
|
170
|
+
self.allQuery = result + self.query
|
171
|
+
return (result + self.query).to_json
|
172
|
+
end
|
203
173
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
174
|
+
|
175
|
+
###
|
176
|
+
# request the queries and returns an array of the results
|
177
|
+
#
|
178
|
+
# @return array
|
179
|
+
###
|
180
|
+
def execute
|
181
|
+
|
182
|
+
if self.query.empty? && self.ghostQuery.empty?
|
183
|
+
return []
|
184
|
+
end
|
185
|
+
parseResult(self.client.request(queryString), self.query.count > 1)
|
186
|
+
end
|
187
|
+
|
188
|
+
###
|
189
|
+
# request the current query and returns the first result
|
190
|
+
#
|
191
|
+
# @return mixed
|
192
|
+
###
|
193
|
+
def executeSingle
|
194
|
+
|
195
|
+
execute[-1]
|
196
|
+
end
|
197
|
+
|
198
|
+
def checkResponse(jsonResponse)
|
199
|
+
|
200
|
+
if jsonResponse == false || !(jsonResponse.is_a? Array) || jsonResponse.count != self.allQuery.count
|
201
|
+
raise 'UnexpectedResultException!'
|
202
|
+
end
|
203
|
+
|
204
|
+
(0..jsonResponse.count-1).each do |index|
|
205
|
+
currentQuery = self.allQuery[index]
|
206
|
+
responseKey = jsonResponse[index].keys[0]
|
207
|
+
queryKey = currentQuery.keys[0]
|
208
|
+
|
209
|
+
if responseKey != queryKey
|
210
|
+
raise 'UnexpectedResultException! result ' + String(queryKey) + ' expected,
|
211
|
+
but ' + String(responseKey) + ' given on position ' + String(index) +
|
212
|
+
' - query: ' + currentQuery.to_json
|
213
|
+
end
|
214
|
+
|
215
|
+
unless self.mapping.key? responseKey
|
216
|
+
raise 'UnexpectedResultException! internal error, ' + String(responseKey) + ' is unknown result'
|
217
|
+
end
|
219
218
|
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def parseResult(jsonResponse, isMultiRequest=true)
|
222
|
+
|
223
|
+
self.checkResponse(jsonResponse)
|
224
|
+
results = []
|
225
|
+
queryIds = []
|
220
226
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
227
|
+
self.allQuery.each do |query|
|
228
|
+
queryIds.push(query.keys[0])
|
229
|
+
end
|
230
|
+
|
231
|
+
jsonResponse.each_with_index do |responseObject, index|
|
232
|
+
currentQuery = self.allQuery[index]
|
233
|
+
resultKey = responseObject.keys[0]
|
234
|
+
jsonObject = responseObject[resultKey]
|
235
|
+
queryKey = currentQuery.keys[0]
|
236
|
+
factory = self.factory
|
237
|
+
|
238
|
+
if (jsonObject.is_a? Hash) && jsonObject['error_code']
|
239
|
+
result = factory.preHandleError(jsonObject, resultKey, isMultiRequest)
|
240
|
+
if result != false
|
241
|
+
results.push({resultKey=> result})
|
242
|
+
next
|
228
243
|
end
|
244
|
+
end
|
229
245
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
query = currentQuery[queryKey];
|
246
|
-
queryId = queryIds[index];
|
247
|
-
if (queryId == QUERY_FACETS)
|
248
|
-
factory.updateFacetManager(jsonObject, query);
|
249
|
-
elsif (queryId == QUERY_TREE)
|
250
|
-
factory.initializeCategoryManager(jsonObject);
|
251
|
-
else
|
252
|
-
method = self.mapping[resultKey];
|
253
|
-
result = factory.send(method, jsonObject, query)
|
254
|
-
results.push(result)
|
255
|
-
end
|
256
|
-
end
|
246
|
+
query = currentQuery[queryKey]
|
247
|
+
queryId = queryIds[index]
|
248
|
+
if queryId == QUERY_FACETS
|
249
|
+
factory.updateFacetManager(jsonObject, query)
|
250
|
+
elsif queryId == QUERY_TREE
|
251
|
+
factory.initializeCategoryManager(jsonObject)
|
252
|
+
else
|
253
|
+
method = self.mapping[resultKey]
|
254
|
+
result = factory.send(method, jsonObject, query)
|
255
|
+
results.push(result)
|
256
|
+
end
|
257
|
+
end
|
257
258
|
|
258
|
-
|
259
|
+
return results
|
259
260
|
end
|
260
261
|
end
|
261
262
|
end
|