suggestgrid 0.1.27 → 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/suggest_grid/api_helper.rb +6 -0
- data/lib/suggest_grid/configuration.rb +1 -0
- data/lib/suggest_grid/controllers/action_controller.rb +94 -142
- data/lib/suggest_grid/controllers/base_controller.rb +3 -2
- data/lib/suggest_grid/controllers/metadata_controller.rb +182 -330
- data/lib/suggest_grid/controllers/recommendation_controller.rb +18 -42
- data/lib/suggest_grid/controllers/similarity_controller.rb +18 -42
- data/lib/suggest_grid/controllers/type_controller.rb +76 -140
- data/lib/suggest_grid/exceptions/delete_error_response_exception.rb +7 -7
- data/lib/suggest_grid/exceptions/detailed_error_response_exception.rb +1 -1
- data/lib/suggest_grid/exceptions/error_response_exception.rb +1 -1
- data/lib/suggest_grid/exceptions/limit_exceeded_error_response_exception.rb +3 -3
- data/lib/suggest_grid/http/faraday_client.rb +3 -1
- data/lib/suggest_grid/http/http_client.rb +4 -2
- data/lib/suggest_grid/models/action.rb +19 -2
- data/lib/suggest_grid/models/actions_response.rb +10 -2
- data/lib/suggest_grid/models/base_model.rb +17 -0
- data/lib/suggest_grid/models/bulk_post_error.rb +10 -2
- data/lib/suggest_grid/models/bulk_post_response.rb +10 -2
- data/lib/suggest_grid/models/delete_success_response.rb +16 -8
- data/lib/suggest_grid/models/get_recommended_items_body.rb +16 -8
- data/lib/suggest_grid/models/get_recommended_users_body.rb +16 -8
- data/lib/suggest_grid/models/get_similar_items_body.rb +15 -7
- data/lib/suggest_grid/models/get_similar_users_body.rb +15 -7
- data/lib/suggest_grid/models/get_type_response.rb +10 -2
- data/lib/suggest_grid/models/get_types_response.rb +8 -9
- data/lib/suggest_grid/models/items_response.rb +10 -2
- data/lib/suggest_grid/models/message_response.rb +10 -2
- data/lib/suggest_grid/models/metadata.rb +19 -10
- data/lib/suggest_grid/models/type_request_body.rb +11 -5
- data/lib/suggest_grid/models/users_response.rb +10 -2
- data/lib/suggest_grid.rb +2 -0
- data/spec/swagger.yaml +122 -194
- metadata +21 -7
@@ -8,71 +8,91 @@ module SuggestGrid
|
|
8
8
|
@@instance
|
9
9
|
end
|
10
10
|
|
11
|
-
#
|
12
|
-
# @param [
|
13
|
-
# @return
|
14
|
-
def
|
11
|
+
# Post a User
|
12
|
+
# @param [Metadata] user Required parameter: The metadata to be saved. Metadata format has its restrictions.
|
13
|
+
# @return MessageResponse response from the API call
|
14
|
+
def post_user(user)
|
15
15
|
|
16
|
-
#
|
16
|
+
# prepare query url
|
17
17
|
_query_builder = Configuration.base_uri.dup
|
18
|
+
_query_builder << '/v1/users'
|
19
|
+
_query_url = APIHelper.clean_url _query_builder
|
18
20
|
|
19
|
-
# prepare
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
24
|
-
'user_id' => user_id
|
21
|
+
# prepare headers
|
22
|
+
_headers = {
|
23
|
+
'accept' => 'application/json',
|
24
|
+
'content-type' => 'application/json; charset=utf-8'
|
25
25
|
}
|
26
26
|
|
27
|
-
#
|
27
|
+
# prepare and execute HttpRequest
|
28
|
+
_request = @http_client.post _query_url, headers: _headers, parameters: user.to_json
|
29
|
+
BasicAuth.apply(_request)
|
30
|
+
_context = execute_request(_request)
|
31
|
+
|
32
|
+
# validate response against endpoint and global error codes
|
33
|
+
if _context.response.status_code == 400
|
34
|
+
raise DetailedErrorResponseException.new 'Metadata is invalid.', _context
|
35
|
+
elsif !_context.response.status_code.between?(200, 208)
|
36
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
37
|
+
end
|
38
|
+
validate_response(_context)
|
39
|
+
|
40
|
+
# return appropriate response type
|
41
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
42
|
+
return MessageResponse.from_hash(decoded)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Post Bulk Users
|
46
|
+
# @param [Collection] users Required parameter: List of user metadata, whose size is limited to 10 thousand.
|
47
|
+
# @return BulkPostResponse response from the API call
|
48
|
+
def post_bulk_users(users)
|
49
|
+
body = ''
|
50
|
+
users.each do |user|
|
51
|
+
body += "#{user.to_json}\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
# prepare query url
|
55
|
+
_query_builder = Configuration.base_uri.dup
|
56
|
+
_query_builder << '/v1/users/_bulk'
|
28
57
|
_query_url = APIHelper.clean_url _query_builder
|
29
58
|
|
30
59
|
# prepare headers
|
31
60
|
_headers = {
|
32
|
-
'accept' => 'application/json'
|
61
|
+
'accept' => 'application/json',
|
62
|
+
'content-type' => 'text/plain; charset=utf-8'
|
33
63
|
}
|
34
64
|
|
35
|
-
#
|
36
|
-
_request = @http_client.
|
37
|
-
|
38
|
-
# apply authentication
|
65
|
+
# prepare and execute HttpRequest
|
66
|
+
_request = @http_client.post _query_url, headers: _headers, parameters: body
|
39
67
|
BasicAuth.apply(_request)
|
40
|
-
|
41
|
-
# execute the request
|
42
68
|
_context = execute_request(_request)
|
43
69
|
|
44
|
-
#
|
45
|
-
if _context.response.status_code ==
|
46
|
-
raise ErrorResponseException.new '
|
47
|
-
elsif _context.response.status_code ==
|
48
|
-
raise
|
70
|
+
# validate response against endpoint and global error codes
|
71
|
+
if _context.response.status_code == 400
|
72
|
+
raise ErrorResponseException.new 'Body is missing.', _context
|
73
|
+
elsif _context.response.status_code == 413
|
74
|
+
raise ErrorResponseException.new 'Bulk request maximum line count exceeded.', _context
|
75
|
+
elsif !_context.response.status_code.between?(200, 208)
|
76
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
49
77
|
end
|
50
|
-
|
51
|
-
# global error handling using HTTP status codes.
|
52
78
|
validate_response(_context)
|
53
79
|
|
54
80
|
# return appropriate response type
|
55
81
|
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
56
|
-
return
|
82
|
+
return BulkPostResponse.from_hash(decoded)
|
57
83
|
end
|
58
84
|
|
59
|
-
#
|
85
|
+
# Get A User
|
60
86
|
# @param [String] user_id Required parameter: The user id to delete its metadata.
|
61
|
-
# @return
|
62
|
-
def
|
87
|
+
# @return Metadata response from the API call
|
88
|
+
def get_user(user_id)
|
63
89
|
|
64
|
-
#
|
90
|
+
# prepare query url
|
65
91
|
_query_builder = Configuration.base_uri.dup
|
66
|
-
|
67
|
-
# prepare query string for API call
|
68
92
|
_query_builder << '/v1/users/{user_id}'
|
69
|
-
|
70
|
-
# process optional query parameters
|
71
93
|
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
72
94
|
'user_id' => user_id
|
73
95
|
}
|
74
|
-
|
75
|
-
# validate and preprocess url
|
76
96
|
_query_url = APIHelper.clean_url _query_builder
|
77
97
|
|
78
98
|
# prepare headers
|
@@ -80,50 +100,38 @@ module SuggestGrid
|
|
80
100
|
'accept' => 'application/json'
|
81
101
|
}
|
82
102
|
|
83
|
-
#
|
84
|
-
_request = @http_client.
|
85
|
-
|
86
|
-
# apply authentication
|
103
|
+
# prepare and execute HttpRequest
|
104
|
+
_request = @http_client.get _query_url, headers: _headers
|
87
105
|
BasicAuth.apply(_request)
|
88
|
-
|
89
|
-
# execute the request
|
90
106
|
_context = execute_request(_request)
|
91
107
|
|
92
|
-
#
|
93
|
-
if _context.response.status_code ==
|
94
|
-
raise ErrorResponseException.new '
|
95
|
-
elsif _context.response.status_code
|
96
|
-
raise
|
108
|
+
# validate response against endpoint and global error codes
|
109
|
+
if _context.response.status_code == 404
|
110
|
+
raise ErrorResponseException.new 'User does not exists.', _context
|
111
|
+
elsif !_context.response.status_code.between?(200, 208)
|
112
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
97
113
|
end
|
98
|
-
|
99
|
-
# global error handling using HTTP status codes.
|
100
114
|
validate_response(_context)
|
101
115
|
|
102
116
|
# return appropriate response type
|
103
117
|
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
104
|
-
return
|
118
|
+
return Metadata.from_hash(decoded)
|
105
119
|
end
|
106
120
|
|
107
121
|
# Get Users
|
108
|
-
# @param [
|
109
|
-
# @param [
|
122
|
+
# @param [Long] size Optional parameter: The number of the users response. Defaults to 10. Must be between 1 and 10,000 inclusive. This parameter must be string represetation of an integer like "1".
|
123
|
+
# @param [Long] from Optional parameter: The number of users to be skipped from the response. Defaults to 0. Must be bigger than or equal to 0. This parameter must be string represetation of an integer like "1".
|
110
124
|
# @return UsersResponse response from the API call
|
111
125
|
def get_users(size = nil,
|
112
126
|
from = nil)
|
113
127
|
|
114
|
-
#
|
128
|
+
# prepare query url
|
115
129
|
_query_builder = Configuration.base_uri.dup
|
116
|
-
|
117
|
-
# prepare query string for API call
|
118
130
|
_query_builder << '/v1/users'
|
119
|
-
|
120
|
-
# process optional query parameters
|
121
131
|
_query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
|
122
132
|
'size' => size,
|
123
133
|
'from' => from
|
124
134
|
}
|
125
|
-
|
126
|
-
# validate and preprocess url
|
127
135
|
_query_url = APIHelper.clean_url _query_builder
|
128
136
|
|
129
137
|
# prepare headers
|
@@ -131,23 +139,15 @@ module SuggestGrid
|
|
131
139
|
'accept' => 'application/json'
|
132
140
|
}
|
133
141
|
|
134
|
-
#
|
142
|
+
# prepare and execute HttpRequest
|
135
143
|
_request = @http_client.get _query_url, headers: _headers
|
136
|
-
|
137
|
-
# apply authentication
|
138
144
|
BasicAuth.apply(_request)
|
139
|
-
|
140
|
-
# execute the request
|
141
145
|
_context = execute_request(_request)
|
142
146
|
|
143
|
-
#
|
144
|
-
if _context.response.status_code ==
|
145
|
-
raise ErrorResponseException.new '
|
146
|
-
elsif _context.response.status_code == 500
|
147
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
147
|
+
# validate response against endpoint and global error codes
|
148
|
+
if _context.response.status_code == 0
|
149
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
148
150
|
end
|
149
|
-
|
150
|
-
# global error handling using HTTP status codes.
|
151
151
|
validate_response(_context)
|
152
152
|
|
153
153
|
# return appropriate response type
|
@@ -155,45 +155,33 @@ module SuggestGrid
|
|
155
155
|
return UsersResponse.from_hash(decoded)
|
156
156
|
end
|
157
157
|
|
158
|
-
#
|
159
|
-
# @param [
|
158
|
+
# Delete a User
|
159
|
+
# @param [String] user_id Required parameter: The user id to delete its metadata.
|
160
160
|
# @return MessageResponse response from the API call
|
161
|
-
def
|
161
|
+
def delete_user(user_id)
|
162
162
|
|
163
|
-
#
|
163
|
+
# prepare query url
|
164
164
|
_query_builder = Configuration.base_uri.dup
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
# validate and preprocess url
|
165
|
+
_query_builder << '/v1/users/{user_id}'
|
166
|
+
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
167
|
+
'user_id' => user_id
|
168
|
+
}
|
170
169
|
_query_url = APIHelper.clean_url _query_builder
|
171
170
|
|
172
171
|
# prepare headers
|
173
172
|
_headers = {
|
174
|
-
'accept' => 'application/json'
|
175
|
-
'content-type' => 'application/json; charset=utf-8'
|
173
|
+
'accept' => 'application/json'
|
176
174
|
}
|
177
175
|
|
178
|
-
#
|
179
|
-
_request = @http_client.
|
180
|
-
|
181
|
-
# apply authentication
|
176
|
+
# prepare and execute HttpRequest
|
177
|
+
_request = @http_client.delete _query_url, headers: _headers
|
182
178
|
BasicAuth.apply(_request)
|
183
|
-
|
184
|
-
# execute the request
|
185
179
|
_context = execute_request(_request)
|
186
180
|
|
187
|
-
#
|
188
|
-
if _context.response.status_code ==
|
189
|
-
raise
|
190
|
-
elsif _context.response.status_code == 429
|
191
|
-
raise ErrorResponseException.new '429 - Too many requests.', _context
|
192
|
-
elsif _context.response.status_code == 500
|
193
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
181
|
+
# validate response against endpoint and global error codes
|
182
|
+
if _context.response.status_code == 0
|
183
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
194
184
|
end
|
195
|
-
|
196
|
-
# global error handling using HTTP status codes.
|
197
185
|
validate_response(_context)
|
198
186
|
|
199
187
|
# return appropriate response type
|
@@ -205,13 +193,9 @@ module SuggestGrid
|
|
205
193
|
# @return MessageResponse response from the API call
|
206
194
|
def delete_all_users
|
207
195
|
|
208
|
-
#
|
196
|
+
# prepare query url
|
209
197
|
_query_builder = Configuration.base_uri.dup
|
210
|
-
|
211
|
-
# prepare query string for API call
|
212
198
|
_query_builder << '/v1/users'
|
213
|
-
|
214
|
-
# validate and preprocess url
|
215
199
|
_query_url = APIHelper.clean_url _query_builder
|
216
200
|
|
217
201
|
# prepare headers
|
@@ -219,23 +203,15 @@ module SuggestGrid
|
|
219
203
|
'accept' => 'application/json'
|
220
204
|
}
|
221
205
|
|
222
|
-
#
|
206
|
+
# prepare and execute HttpRequest
|
223
207
|
_request = @http_client.delete _query_url, headers: _headers
|
224
|
-
|
225
|
-
# apply authentication
|
226
208
|
BasicAuth.apply(_request)
|
227
|
-
|
228
|
-
# execute the request
|
229
209
|
_context = execute_request(_request)
|
230
210
|
|
231
|
-
#
|
232
|
-
if _context.response.status_code ==
|
233
|
-
raise ErrorResponseException.new '
|
234
|
-
elsif _context.response.status_code == 500
|
235
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
211
|
+
# validate response against endpoint and global error codes
|
212
|
+
if _context.response.status_code == 0
|
213
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
236
214
|
end
|
237
|
-
|
238
|
-
# global error handling using HTTP status codes.
|
239
215
|
validate_response(_context)
|
240
216
|
|
241
217
|
# return appropriate response type
|
@@ -243,71 +219,91 @@ module SuggestGrid
|
|
243
219
|
return MessageResponse.from_hash(decoded)
|
244
220
|
end
|
245
221
|
|
246
|
-
#
|
247
|
-
# @param [
|
248
|
-
# @return
|
249
|
-
def
|
222
|
+
# Post an Item
|
223
|
+
# @param [Metadata] item Required parameter: The metadata to be saved. Metadata format has its restrictions.
|
224
|
+
# @return MessageResponse response from the API call
|
225
|
+
def post_item(item)
|
250
226
|
|
251
|
-
#
|
227
|
+
# prepare query url
|
252
228
|
_query_builder = Configuration.base_uri.dup
|
229
|
+
_query_builder << '/v1/items'
|
230
|
+
_query_url = APIHelper.clean_url _query_builder
|
253
231
|
|
254
|
-
# prepare
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
259
|
-
'item_id' => item_id
|
232
|
+
# prepare headers
|
233
|
+
_headers = {
|
234
|
+
'accept' => 'application/json',
|
235
|
+
'content-type' => 'application/json; charset=utf-8'
|
260
236
|
}
|
261
237
|
|
262
|
-
#
|
238
|
+
# prepare and execute HttpRequest
|
239
|
+
_request = @http_client.post _query_url, headers: _headers, parameters: item.to_json
|
240
|
+
BasicAuth.apply(_request)
|
241
|
+
_context = execute_request(_request)
|
242
|
+
|
243
|
+
# validate response against endpoint and global error codes
|
244
|
+
if _context.response.status_code == 400
|
245
|
+
raise DetailedErrorResponseException.new 'Metadata is invalid.', _context
|
246
|
+
elsif !_context.response.status_code.between?(200, 208)
|
247
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
248
|
+
end
|
249
|
+
validate_response(_context)
|
250
|
+
|
251
|
+
# return appropriate response type
|
252
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
253
|
+
return MessageResponse.from_hash(decoded)
|
254
|
+
end
|
255
|
+
|
256
|
+
# Post Bulk Items
|
257
|
+
# @param [Collection] items Required parameter: List of item metadata, whose size is limited to 10 thousand.
|
258
|
+
# @return BulkPostResponse response from the API call
|
259
|
+
def post_bulk_items(items)
|
260
|
+
body = ''
|
261
|
+
items.each do |item|
|
262
|
+
body += "#{item.to_json}\n"
|
263
|
+
end
|
264
|
+
|
265
|
+
# prepare query url
|
266
|
+
_query_builder = Configuration.base_uri.dup
|
267
|
+
_query_builder << '/v1/items/_bulk'
|
263
268
|
_query_url = APIHelper.clean_url _query_builder
|
264
269
|
|
265
270
|
# prepare headers
|
266
271
|
_headers = {
|
267
|
-
'accept' => 'application/json'
|
272
|
+
'accept' => 'application/json',
|
273
|
+
'content-type' => 'text/plain; charset=utf-8'
|
268
274
|
}
|
269
275
|
|
270
|
-
#
|
271
|
-
_request = @http_client.
|
272
|
-
|
273
|
-
# apply authentication
|
276
|
+
# prepare and execute HttpRequest
|
277
|
+
_request = @http_client.post _query_url, headers: _headers, parameters: body
|
274
278
|
BasicAuth.apply(_request)
|
275
|
-
|
276
|
-
# execute the request
|
277
279
|
_context = execute_request(_request)
|
278
280
|
|
279
|
-
#
|
280
|
-
if _context.response.status_code ==
|
281
|
-
raise ErrorResponseException.new '
|
282
|
-
elsif _context.response.status_code ==
|
283
|
-
raise
|
281
|
+
# validate response against endpoint and global error codes
|
282
|
+
if _context.response.status_code == 400
|
283
|
+
raise ErrorResponseException.new 'Body is missing.', _context
|
284
|
+
elsif _context.response.status_code == 413
|
285
|
+
raise ErrorResponseException.new 'Bulk request maximum line count exceeded.', _context
|
286
|
+
elsif !_context.response.status_code.between?(200, 208)
|
287
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
284
288
|
end
|
285
|
-
|
286
|
-
# global error handling using HTTP status codes.
|
287
289
|
validate_response(_context)
|
288
290
|
|
289
291
|
# return appropriate response type
|
290
292
|
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
291
|
-
return
|
293
|
+
return BulkPostResponse.from_hash(decoded)
|
292
294
|
end
|
293
295
|
|
294
|
-
#
|
296
|
+
# Get An Item
|
295
297
|
# @param [String] item_id Required parameter: The item id to delete its metadata.
|
296
|
-
# @return
|
297
|
-
def
|
298
|
+
# @return Metadata response from the API call
|
299
|
+
def get_item(item_id)
|
298
300
|
|
299
|
-
#
|
301
|
+
# prepare query url
|
300
302
|
_query_builder = Configuration.base_uri.dup
|
301
|
-
|
302
|
-
# prepare query string for API call
|
303
303
|
_query_builder << '/v1/items/{item_id}'
|
304
|
-
|
305
|
-
# process optional query parameters
|
306
304
|
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
307
305
|
'item_id' => item_id
|
308
306
|
}
|
309
|
-
|
310
|
-
# validate and preprocess url
|
311
307
|
_query_url = APIHelper.clean_url _query_builder
|
312
308
|
|
313
309
|
# prepare headers
|
@@ -315,50 +311,38 @@ module SuggestGrid
|
|
315
311
|
'accept' => 'application/json'
|
316
312
|
}
|
317
313
|
|
318
|
-
#
|
319
|
-
_request = @http_client.
|
320
|
-
|
321
|
-
# apply authentication
|
314
|
+
# prepare and execute HttpRequest
|
315
|
+
_request = @http_client.get _query_url, headers: _headers
|
322
316
|
BasicAuth.apply(_request)
|
323
|
-
|
324
|
-
# execute the request
|
325
317
|
_context = execute_request(_request)
|
326
318
|
|
327
|
-
#
|
328
|
-
if _context.response.status_code ==
|
329
|
-
raise ErrorResponseException.new '
|
330
|
-
elsif _context.response.status_code
|
331
|
-
raise
|
319
|
+
# validate response against endpoint and global error codes
|
320
|
+
if _context.response.status_code == 404
|
321
|
+
raise ErrorResponseException.new 'Item does not exists.', _context
|
322
|
+
elsif !_context.response.status_code.between?(200, 208)
|
323
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
332
324
|
end
|
333
|
-
|
334
|
-
# global error handling using HTTP status codes.
|
335
325
|
validate_response(_context)
|
336
326
|
|
337
327
|
# return appropriate response type
|
338
328
|
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
339
|
-
return
|
329
|
+
return Metadata.from_hash(decoded)
|
340
330
|
end
|
341
331
|
|
342
332
|
# Get Items
|
343
|
-
# @param [
|
344
|
-
# @param [
|
333
|
+
# @param [Long] size Optional parameter: The number of the users response. Defaults to 10. Must be between 1 and 10,000 inclusive. This parameter must be string represetation of an integer like "1".
|
334
|
+
# @param [Long] from Optional parameter: The number of users to be skipped from the response. Defaults to 0. Must be bigger than or equal to 0. This parameter must be string represetation of an integer like "1".
|
345
335
|
# @return ItemsResponse response from the API call
|
346
336
|
def get_items(size = nil,
|
347
337
|
from = nil)
|
348
338
|
|
349
|
-
#
|
339
|
+
# prepare query url
|
350
340
|
_query_builder = Configuration.base_uri.dup
|
351
|
-
|
352
|
-
# prepare query string for API call
|
353
341
|
_query_builder << '/v1/items'
|
354
|
-
|
355
|
-
# process optional query parameters
|
356
342
|
_query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
|
357
343
|
'size' => size,
|
358
344
|
'from' => from
|
359
345
|
}
|
360
|
-
|
361
|
-
# validate and preprocess url
|
362
346
|
_query_url = APIHelper.clean_url _query_builder
|
363
347
|
|
364
348
|
# prepare headers
|
@@ -366,23 +350,15 @@ module SuggestGrid
|
|
366
350
|
'accept' => 'application/json'
|
367
351
|
}
|
368
352
|
|
369
|
-
#
|
353
|
+
# prepare and execute HttpRequest
|
370
354
|
_request = @http_client.get _query_url, headers: _headers
|
371
|
-
|
372
|
-
# apply authentication
|
373
355
|
BasicAuth.apply(_request)
|
374
|
-
|
375
|
-
# execute the request
|
376
356
|
_context = execute_request(_request)
|
377
357
|
|
378
|
-
#
|
379
|
-
if _context.response.status_code ==
|
380
|
-
raise ErrorResponseException.new '
|
381
|
-
elsif _context.response.status_code == 500
|
382
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
358
|
+
# validate response against endpoint and global error codes
|
359
|
+
if _context.response.status_code == 0
|
360
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
383
361
|
end
|
384
|
-
|
385
|
-
# global error handling using HTTP status codes.
|
386
362
|
validate_response(_context)
|
387
363
|
|
388
364
|
# return appropriate response type
|
@@ -390,45 +366,33 @@ module SuggestGrid
|
|
390
366
|
return ItemsResponse.from_hash(decoded)
|
391
367
|
end
|
392
368
|
|
393
|
-
#
|
394
|
-
# @param [
|
369
|
+
# Delete An Item
|
370
|
+
# @param [String] item_id Required parameter: The item id to delete its metadata.
|
395
371
|
# @return MessageResponse response from the API call
|
396
|
-
def
|
372
|
+
def delete_item(item_id)
|
397
373
|
|
398
|
-
#
|
374
|
+
# prepare query url
|
399
375
|
_query_builder = Configuration.base_uri.dup
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
# validate and preprocess url
|
376
|
+
_query_builder << '/v1/items/{item_id}'
|
377
|
+
_query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
|
378
|
+
'item_id' => item_id
|
379
|
+
}
|
405
380
|
_query_url = APIHelper.clean_url _query_builder
|
406
381
|
|
407
382
|
# prepare headers
|
408
383
|
_headers = {
|
409
|
-
'accept' => 'application/json'
|
410
|
-
'content-type' => 'application/json; charset=utf-8'
|
384
|
+
'accept' => 'application/json'
|
411
385
|
}
|
412
386
|
|
413
|
-
#
|
414
|
-
_request = @http_client.
|
415
|
-
|
416
|
-
# apply authentication
|
387
|
+
# prepare and execute HttpRequest
|
388
|
+
_request = @http_client.delete _query_url, headers: _headers
|
417
389
|
BasicAuth.apply(_request)
|
418
|
-
|
419
|
-
# execute the request
|
420
390
|
_context = execute_request(_request)
|
421
391
|
|
422
|
-
#
|
423
|
-
if _context.response.status_code ==
|
424
|
-
raise
|
425
|
-
elsif _context.response.status_code == 429
|
426
|
-
raise ErrorResponseException.new '429 - Too many requests.', _context
|
427
|
-
elsif _context.response.status_code == 500
|
428
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
392
|
+
# validate response against endpoint and global error codes
|
393
|
+
if _context.response.status_code == 0
|
394
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
429
395
|
end
|
430
|
-
|
431
|
-
# global error handling using HTTP status codes.
|
432
396
|
validate_response(_context)
|
433
397
|
|
434
398
|
# return appropriate response type
|
@@ -440,13 +404,9 @@ module SuggestGrid
|
|
440
404
|
# @return MessageResponse response from the API call
|
441
405
|
def delete_all_items
|
442
406
|
|
443
|
-
#
|
407
|
+
# prepare query url
|
444
408
|
_query_builder = Configuration.base_uri.dup
|
445
|
-
|
446
|
-
# prepare query string for API call
|
447
409
|
_query_builder << '/v1/items'
|
448
|
-
|
449
|
-
# validate and preprocess url
|
450
410
|
_query_url = APIHelper.clean_url _query_builder
|
451
411
|
|
452
412
|
# prepare headers
|
@@ -454,128 +414,20 @@ module SuggestGrid
|
|
454
414
|
'accept' => 'application/json'
|
455
415
|
}
|
456
416
|
|
457
|
-
#
|
417
|
+
# prepare and execute HttpRequest
|
458
418
|
_request = @http_client.delete _query_url, headers: _headers
|
459
|
-
|
460
|
-
# apply authentication
|
461
419
|
BasicAuth.apply(_request)
|
462
|
-
|
463
|
-
# execute the request
|
464
420
|
_context = execute_request(_request)
|
465
421
|
|
466
|
-
#
|
467
|
-
if _context.response.status_code ==
|
468
|
-
raise ErrorResponseException.new '
|
469
|
-
elsif _context.response.status_code == 500
|
470
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
422
|
+
# validate response against endpoint and global error codes
|
423
|
+
if _context.response.status_code == 0
|
424
|
+
raise ErrorResponseException.new 'Unexpected internal error.', _context
|
471
425
|
end
|
472
|
-
|
473
|
-
# global error handling using HTTP status codes.
|
474
426
|
validate_response(_context)
|
475
427
|
|
476
428
|
# return appropriate response type
|
477
429
|
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
478
430
|
return MessageResponse.from_hash(decoded)
|
479
431
|
end
|
480
|
-
|
481
|
-
# Post Bulk Users
|
482
|
-
# @param [Collection] users Required parameter: List of user metadata, whose size is limited to 10 thousand.
|
483
|
-
# @return BulkPostResponse response from the API call
|
484
|
-
def post_bulk_users(users)
|
485
|
-
body = ''
|
486
|
-
users.each do |user|
|
487
|
-
body += "#{user.to_json}\n"
|
488
|
-
end
|
489
|
-
|
490
|
-
# the base uri for api requests
|
491
|
-
_query_builder = Configuration.base_uri.dup
|
492
|
-
|
493
|
-
# prepare query string for API call
|
494
|
-
_query_builder << '/v1/users/_bulk'
|
495
|
-
|
496
|
-
# validate and preprocess url
|
497
|
-
_query_url = APIHelper.clean_url _query_builder
|
498
|
-
|
499
|
-
# prepare headers
|
500
|
-
_headers = {
|
501
|
-
'accept' => 'application/json',
|
502
|
-
'content-type' => 'text/plain; charset=utf-8'
|
503
|
-
}
|
504
|
-
|
505
|
-
# create the HttpRequest object for the call
|
506
|
-
_request = @http_client.post _query_url, headers: _headers, parameters: users
|
507
|
-
|
508
|
-
# apply authentication
|
509
|
-
BasicAuth.apply(_request)
|
510
|
-
|
511
|
-
# execute the request
|
512
|
-
_context = execute_request(_request)
|
513
|
-
|
514
|
-
# endpoint error handling using HTTP status codes.
|
515
|
-
if _context.response.status_code == 400
|
516
|
-
raise ErrorResponseException.new '400 - Body is missing.', _context
|
517
|
-
elsif _context.response.status_code == 429
|
518
|
-
raise ErrorResponseException.new '429 - Too many requests.', _context
|
519
|
-
elsif _context.response.status_code == 500
|
520
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
521
|
-
end
|
522
|
-
|
523
|
-
# global error handling using HTTP status codes.
|
524
|
-
validate_response(_context)
|
525
|
-
|
526
|
-
# return appropriate response type
|
527
|
-
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
528
|
-
return BulkPostResponse.from_hash(decoded)
|
529
|
-
end
|
530
|
-
|
531
|
-
# Post Bulk Items
|
532
|
-
# @param [Collection] items Required parameter: List of item metadata, whose size is limited to 10 thousand.
|
533
|
-
# @return BulkPostResponse response from the API call
|
534
|
-
def post_bulk_items(items)
|
535
|
-
body = ''
|
536
|
-
items.each do |item|
|
537
|
-
body += "#{item.to_json}\n"
|
538
|
-
end
|
539
|
-
|
540
|
-
# the base uri for api requests
|
541
|
-
_query_builder = Configuration.base_uri.dup
|
542
|
-
|
543
|
-
# prepare query string for API call
|
544
|
-
_query_builder << '/v1/items/_bulk'
|
545
|
-
|
546
|
-
# validate and preprocess url
|
547
|
-
_query_url = APIHelper.clean_url _query_builder
|
548
|
-
|
549
|
-
# prepare headers
|
550
|
-
_headers = {
|
551
|
-
'accept' => 'application/json',
|
552
|
-
'content-type' => 'text/plain; charset=utf-8'
|
553
|
-
}
|
554
|
-
|
555
|
-
# create the HttpRequest object for the call
|
556
|
-
_request = @http_client.post _query_url, headers: _headers, parameters: items
|
557
|
-
|
558
|
-
# apply authentication
|
559
|
-
BasicAuth.apply(_request)
|
560
|
-
|
561
|
-
# execute the request
|
562
|
-
_context = execute_request(_request)
|
563
|
-
|
564
|
-
# endpoint error handling using HTTP status codes.
|
565
|
-
if _context.response.status_code == 400
|
566
|
-
raise ErrorResponseException.new '400 - Body is missing.', _context
|
567
|
-
elsif _context.response.status_code == 429
|
568
|
-
raise ErrorResponseException.new '429 - Too many requests.', _context
|
569
|
-
elsif _context.response.status_code == 500
|
570
|
-
raise APIException.new '500 - Unexpected internal error.', _context
|
571
|
-
end
|
572
|
-
|
573
|
-
# global error handling using HTTP status codes.
|
574
|
-
validate_response(_context)
|
575
|
-
|
576
|
-
# return appropriate response type
|
577
|
-
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
578
|
-
return BulkPostResponse.from_hash(decoded)
|
579
|
-
end
|
580
432
|
end
|
581
433
|
end
|