suggestgrid 0.3.0 → 0.5.0.rc3

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