algoliasearch 1.20.1 → 1.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +4 -1
- data/lib/algolia/client.rb +104 -68
- data/lib/algolia/index.rb +221 -155
- data/lib/algolia/protocol.rb +12 -16
- data/lib/algolia/version.rb +1 -1
- data/spec/client_spec.rb +1 -1
- metadata +2 -2
data/lib/algolia/index.rb
CHANGED
@@ -11,21 +11,25 @@ module Algolia
|
|
11
11
|
self.client = client || Algolia.client
|
12
12
|
end
|
13
13
|
|
14
|
+
#
|
14
15
|
# Delete an index
|
15
16
|
#
|
17
|
+
# @param request_options contains extra parameters to send with your query
|
18
|
+
#
|
16
19
|
# return an hash of the form { "deletedAt" => "2013-01-18T15:33:13.556Z", "taskID" => "42" }
|
17
20
|
#
|
18
|
-
# @param request_options contains extra parameters to send with your query
|
19
21
|
def delete(request_options = {})
|
20
22
|
client.delete(Protocol.index_uri(name), :write, request_options)
|
21
23
|
end
|
22
24
|
alias_method :delete_index, :delete
|
23
25
|
|
26
|
+
#
|
24
27
|
# Delete an index and wait until the deletion has been processed
|
25
28
|
#
|
29
|
+
# @param request_options contains extra parameters to send with your query
|
30
|
+
#
|
26
31
|
# return an hash of the form { "deletedAt" => "2013-01-18T15:33:13.556Z", "taskID" => "42" }
|
27
32
|
#
|
28
|
-
# @param request_options contains extra parameters to send with your query
|
29
33
|
def delete!(request_options = {})
|
30
34
|
res = delete(request_options)
|
31
35
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
@@ -33,55 +37,64 @@ module Algolia
|
|
33
37
|
end
|
34
38
|
alias_method :delete_index!, :delete!
|
35
39
|
|
40
|
+
#
|
36
41
|
# Add an object in this index
|
37
42
|
#
|
38
|
-
# @param
|
43
|
+
# @param object the object to add to the index.
|
39
44
|
# The object is represented by an associative array
|
40
45
|
# @param objectID (optional) an objectID you want to attribute to this object
|
41
46
|
# (if the attribute already exist the old object will be overridden)
|
42
47
|
# @param request_options contains extra parameters to send with your query
|
43
|
-
|
44
|
-
|
48
|
+
#
|
49
|
+
def add_object(object, objectID = nil, request_options = {})
|
50
|
+
check_object(object)
|
45
51
|
if objectID.nil? || objectID.to_s.empty?
|
46
|
-
client.post(Protocol.index_uri(name),
|
52
|
+
client.post(Protocol.index_uri(name), object.to_json, :write, request_options)
|
47
53
|
else
|
48
|
-
client.put(Protocol.object_uri(name, objectID),
|
54
|
+
client.put(Protocol.object_uri(name, objectID), object.to_json, :write, request_options)
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
58
|
+
#
|
52
59
|
# Add an object in this index and wait end of indexing
|
53
60
|
#
|
54
|
-
# @param
|
61
|
+
# @param object the object to add to the index.
|
55
62
|
# The object is represented by an associative array
|
56
63
|
# @param objectID (optional) an objectID you want to attribute to this object
|
57
64
|
# (if the attribute already exist the old object will be overridden)
|
58
65
|
# @param Request options object. Contains extra URL parameters or headers
|
59
|
-
|
60
|
-
|
66
|
+
#
|
67
|
+
def add_object!(object, objectID = nil, request_options = {})
|
68
|
+
res = add_object(object, objectID, request_options)
|
61
69
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
62
70
|
res
|
63
71
|
end
|
64
72
|
|
73
|
+
#
|
65
74
|
# Add several objects in this index
|
66
75
|
#
|
67
|
-
# @param
|
76
|
+
# @param objects the array of objects to add inside the index.
|
68
77
|
# Each object is represented by an associative array
|
69
78
|
# @param request_options contains extra parameters to send with your query
|
70
|
-
|
71
|
-
|
79
|
+
#
|
80
|
+
def add_objects(objects, request_options = {})
|
81
|
+
batch(build_batch('addObject', objects, false), request_options)
|
72
82
|
end
|
73
83
|
|
84
|
+
#
|
74
85
|
# Add several objects in this index and wait end of indexing
|
75
86
|
#
|
76
|
-
# @param
|
87
|
+
# @param objects the array of objects to add inside the index.
|
77
88
|
# Each object is represented by an associative array
|
78
89
|
# @param request_options contains extra parameters to send with your query
|
79
|
-
|
80
|
-
|
90
|
+
#
|
91
|
+
def add_objects!(objects, request_options = {})
|
92
|
+
res = add_objects(objects, request_options)
|
81
93
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
82
94
|
res
|
83
95
|
end
|
84
96
|
|
97
|
+
#
|
85
98
|
# Search inside the index
|
86
99
|
#
|
87
100
|
# @param query the full text query
|
@@ -144,8 +157,9 @@ module Algolia
|
|
144
157
|
# For example, if the chosen attribute is show_name and several hits have the same value for show_name, then only the best
|
145
158
|
# one is kept and others are removed.
|
146
159
|
# @param request_options contains extra parameters to send with your query
|
160
|
+
#
|
147
161
|
def search(query, params = {}, request_options = {})
|
148
|
-
encoded_params = Hash[params.map { |k,v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
|
162
|
+
encoded_params = Hash[params.map { |k, v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
|
149
163
|
encoded_params[:query] = query
|
150
164
|
client.post(Protocol.search_post_uri(name), { :params => Protocol.to_query(encoded_params) }.to_json, :search, request_options)
|
151
165
|
end
|
@@ -184,19 +198,19 @@ module Algolia
|
|
184
198
|
#
|
185
199
|
# @DEPRECATED:
|
186
200
|
# @param page Pagination parameter used to select the page to retrieve.
|
187
|
-
# @param
|
201
|
+
# @param hits_per_page Pagination parameter used to select the number of hits per page. Defaults to 1000.
|
188
202
|
#
|
189
|
-
def browse(
|
203
|
+
def browse(page_or_query_parameters = nil, hits_per_page = nil, request_options = {}, &block)
|
190
204
|
params = {}
|
191
|
-
if
|
192
|
-
params.merge!(
|
205
|
+
if page_or_query_parameters.is_a?(Hash)
|
206
|
+
params.merge!(page_or_query_parameters)
|
193
207
|
else
|
194
|
-
params[:page] =
|
208
|
+
params[:page] = page_or_query_parameters unless page_or_query_parameters.nil?
|
195
209
|
end
|
196
|
-
if
|
197
|
-
params.merge!(
|
210
|
+
if hits_per_page.is_a?(Hash)
|
211
|
+
params.merge!(hits_per_page)
|
198
212
|
else
|
199
|
-
params[:hitsPerPage] =
|
213
|
+
params[:hitsPerPage] = hits_per_page unless hits_per_page.nil?
|
200
214
|
end
|
201
215
|
|
202
216
|
if block_given?
|
@@ -212,23 +226,24 @@ module Algolia
|
|
212
226
|
# Browse a single page from a specific cursor
|
213
227
|
#
|
214
228
|
# @param request_options contains extra parameters to send with your query
|
215
|
-
|
216
|
-
|
229
|
+
#
|
230
|
+
def browse_from(cursor, hits_per_page = 1000, request_options = {})
|
231
|
+
client.get(Protocol.browse_uri(name, { :cursor => cursor, :hitsPerPage => hits_per_page }), :read, request_options)
|
217
232
|
end
|
218
233
|
|
219
234
|
#
|
220
235
|
# Get an object from this index
|
221
236
|
#
|
222
237
|
# @param objectID the unique identifier of the object to retrieve
|
223
|
-
# @param
|
238
|
+
# @param attributes_to_retrieve (optional) if set, contains the list of attributes to retrieve as an array of strings of a string separated by ","
|
224
239
|
# @param request_options contains extra parameters to send with your query
|
225
240
|
#
|
226
|
-
def get_object(objectID,
|
227
|
-
|
228
|
-
if
|
241
|
+
def get_object(objectID, attributes_to_retrieve = nil, request_options = {})
|
242
|
+
attributes_to_retrieve = attributes_to_retrieve.join(',') if attributes_to_retrieve.is_a?(Array)
|
243
|
+
if attributes_to_retrieve.nil?
|
229
244
|
client.get(Protocol.object_uri(name, objectID, nil), :read, request_options)
|
230
245
|
else
|
231
|
-
client.get(Protocol.object_uri(name, objectID, {:attributes =>
|
246
|
+
client.get(Protocol.object_uri(name, objectID, { :attributes => attributes_to_retrieve }), :read, request_options)
|
232
247
|
end
|
233
248
|
end
|
234
249
|
|
@@ -236,19 +251,20 @@ module Algolia
|
|
236
251
|
# Get a list of objects from this index
|
237
252
|
#
|
238
253
|
# @param objectIDs the array of unique identifier of the objects to retrieve
|
239
|
-
# @param
|
254
|
+
# @param attributes_to_retrieve (optional) if set, contains the list of attributes to retrieve as an array of strings of a string separated by ","
|
240
255
|
# @param request_options contains extra parameters to send with your query
|
241
256
|
#
|
242
|
-
def get_objects(objectIDs,
|
243
|
-
|
257
|
+
def get_objects(objectIDs, attributes_to_retrieve = nil, request_options = {})
|
258
|
+
attributes_to_retrieve = attributes_to_retrieve.join(',') if attributes_to_retrieve.is_a?(Array)
|
244
259
|
requests = objectIDs.map do |objectID|
|
245
|
-
req = {:indexName => name, :objectID => objectID.to_s}
|
246
|
-
req[:attributesToRetrieve] =
|
260
|
+
req = { :indexName => name, :objectID => objectID.to_s }
|
261
|
+
req[:attributesToRetrieve] = attributes_to_retrieve unless attributes_to_retrieve.nil?
|
247
262
|
req
|
248
263
|
end
|
249
264
|
client.post(Protocol.objects_uri, { :requests => requests }.to_json, :read, request_options)['results']
|
250
265
|
end
|
251
266
|
|
267
|
+
#
|
252
268
|
# Check the status of a task on the server.
|
253
269
|
# All server task are asynchronous and you can check the status of a task with this method.
|
254
270
|
#
|
@@ -259,61 +275,66 @@ module Algolia
|
|
259
275
|
client.get(Protocol.task_uri(name, taskID), :read, request_options)['status']
|
260
276
|
end
|
261
277
|
|
278
|
+
#
|
262
279
|
# Wait the publication of a task on the server.
|
263
280
|
# All server task are asynchronous and you can check with this method that the task is published.
|
264
281
|
#
|
265
282
|
# @param taskID the id of the task returned by server
|
266
|
-
# @param
|
283
|
+
# @param time_before_retry the time in milliseconds before retry (default = 100ms)
|
267
284
|
# @param request_options contains extra parameters to send with your query
|
268
285
|
#
|
269
|
-
def wait_task(taskID,
|
286
|
+
def wait_task(taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {})
|
270
287
|
loop do
|
271
288
|
status = get_task_status(taskID, request_options)
|
272
289
|
if status == 'published'
|
273
290
|
return
|
274
291
|
end
|
275
|
-
sleep(
|
292
|
+
sleep(time_before_retry.to_f / 1000)
|
276
293
|
end
|
277
294
|
end
|
278
295
|
|
296
|
+
#
|
279
297
|
# Override the content of an object
|
280
298
|
#
|
281
|
-
# @param
|
282
|
-
# @param objectID the associated objectID, if nil '
|
299
|
+
# @param object the object to save
|
300
|
+
# @param objectID the associated objectID, if nil 'object' must contain an 'objectID' key
|
283
301
|
# @param request_options contains extra parameters to send with your query
|
284
302
|
#
|
285
|
-
def save_object(
|
286
|
-
client.put(Protocol.object_uri(name, get_objectID(
|
303
|
+
def save_object(object, objectID = nil, request_options = {})
|
304
|
+
client.put(Protocol.object_uri(name, get_objectID(object, objectID)), object.to_json, :write, request_options)
|
287
305
|
end
|
288
306
|
|
307
|
+
#
|
289
308
|
# Override the content of object and wait end of indexing
|
290
309
|
#
|
291
|
-
# @param
|
292
|
-
# @param objectID the associated objectID, if nil '
|
310
|
+
# @param object the object to save
|
311
|
+
# @param objectID the associated objectID, if nil 'object' must contain an 'objectID' key
|
293
312
|
# @param request_options contains extra parameters to send with your query
|
294
313
|
#
|
295
|
-
def save_object!(
|
296
|
-
res = save_object(
|
314
|
+
def save_object!(object, objectID = nil, request_options = {})
|
315
|
+
res = save_object(object, objectID, request_options)
|
297
316
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
298
317
|
res
|
299
318
|
end
|
300
319
|
|
320
|
+
#
|
301
321
|
# Override the content of several objects
|
302
322
|
#
|
303
|
-
# @param
|
323
|
+
# @param objects the array of objects to save, each object must contain an 'objectID' key
|
304
324
|
# @param request_options contains extra parameters to send with your query
|
305
325
|
#
|
306
|
-
def save_objects(
|
307
|
-
batch(build_batch('updateObject',
|
326
|
+
def save_objects(objects, request_options = {})
|
327
|
+
batch(build_batch('updateObject', objects, true), request_options)
|
308
328
|
end
|
309
329
|
|
330
|
+
#
|
310
331
|
# Override the content of several objects and wait end of indexing
|
311
332
|
#
|
312
|
-
# @param
|
333
|
+
# @param objects the array of objects to save, each object must contain an objectID attribute
|
313
334
|
# @param request_options contains extra parameters to send with your query
|
314
335
|
#
|
315
|
-
def save_objects!(
|
316
|
-
res = save_objects(
|
336
|
+
def save_objects!(objects, request_options = {})
|
337
|
+
res = save_objects(objects, request_options)
|
317
338
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
318
339
|
res
|
319
340
|
end
|
@@ -321,39 +342,39 @@ module Algolia
|
|
321
342
|
#
|
322
343
|
# Update partially an object (only update attributes passed in argument)
|
323
344
|
#
|
324
|
-
# @param
|
325
|
-
# @param objectID the associated objectID, if nil '
|
345
|
+
# @param object the object attributes to override
|
346
|
+
# @param objectID the associated objectID, if nil 'object' must contain an 'objectID' key
|
326
347
|
# @param create_if_not_exits a boolean, if true creates the object if this one doesn't exist
|
327
348
|
# @param request_options contains extra parameters to send with your query
|
328
349
|
#
|
329
|
-
def partial_update_object(
|
330
|
-
client.post(Protocol.partial_object_uri(name, get_objectID(
|
350
|
+
def partial_update_object(object, objectID = nil, create_if_not_exits = true, request_options = {})
|
351
|
+
client.post(Protocol.partial_object_uri(name, get_objectID(object, objectID), create_if_not_exits), object.to_json, :write, request_options)
|
331
352
|
end
|
332
353
|
|
333
354
|
#
|
334
|
-
# Partially
|
355
|
+
# Partially override the content of several objects
|
335
356
|
#
|
336
|
-
# @param
|
357
|
+
# @param objects an array of objects to update (each object must contains a objectID attribute)
|
337
358
|
# @param create_if_not_exits a boolean, if true create the objects if they don't exist
|
338
359
|
# @param request_options contains extra parameters to send with your query
|
339
360
|
#
|
340
|
-
def partial_update_objects(
|
361
|
+
def partial_update_objects(objects, create_if_not_exits = true, request_options = {})
|
341
362
|
if create_if_not_exits
|
342
|
-
batch(build_batch('partialUpdateObject',
|
363
|
+
batch(build_batch('partialUpdateObject', objects, true), request_options)
|
343
364
|
else
|
344
|
-
batch(build_batch('partialUpdateObjectNoCreate',
|
365
|
+
batch(build_batch('partialUpdateObjectNoCreate', objects, true), request_options)
|
345
366
|
end
|
346
367
|
end
|
347
368
|
|
348
369
|
#
|
349
|
-
# Partially
|
370
|
+
# Partially override the content of several objects and wait end of indexing
|
350
371
|
#
|
351
|
-
# @param
|
372
|
+
# @param objects an array of objects to update (each object must contains a objectID attribute)
|
352
373
|
# @param create_if_not_exits a boolean, if true create the objects if they don't exist
|
353
374
|
# @param request_options contains extra parameters to send with your query
|
354
375
|
#
|
355
|
-
def partial_update_objects!(
|
356
|
-
res = partial_update_objects(
|
376
|
+
def partial_update_objects!(objects, create_if_not_exits = true, request_options = {})
|
377
|
+
res = partial_update_objects(objects, create_if_not_exits, request_options)
|
357
378
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
358
379
|
res
|
359
380
|
end
|
@@ -361,13 +382,13 @@ module Algolia
|
|
361
382
|
#
|
362
383
|
# Update partially an object (only update attributes passed in argument) and wait indexing
|
363
384
|
#
|
364
|
-
# @param
|
365
|
-
# @param objectID the associated objectID, if nil '
|
385
|
+
# @param object the attributes to override
|
386
|
+
# @param objectID the associated objectID, if nil 'object' must contain an 'objectID' key
|
366
387
|
# @param create_if_not_exits a boolean, if true creates the object if this one doesn't exist
|
367
388
|
# @param request_options contains extra parameters to send with your query
|
368
389
|
#
|
369
|
-
def partial_update_object!(
|
370
|
-
res = partial_update_object(
|
390
|
+
def partial_update_object!(object, objectID = nil, create_if_not_exits = true, request_options = {})
|
391
|
+
res = partial_update_object(object, objectID, create_if_not_exits, request_options)
|
371
392
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
372
393
|
res
|
373
394
|
end
|
@@ -398,22 +419,22 @@ module Algolia
|
|
398
419
|
#
|
399
420
|
# Delete several objects
|
400
421
|
#
|
401
|
-
# @param
|
422
|
+
# @param objects an array of objectIDs
|
402
423
|
# @param request_options contains extra parameters to send with your query
|
403
424
|
#
|
404
|
-
def delete_objects(
|
405
|
-
check_array
|
406
|
-
batch(build_batch('deleteObject',
|
425
|
+
def delete_objects(objects, request_options = {})
|
426
|
+
check_array(objects)
|
427
|
+
batch(build_batch('deleteObject', objects.map { |objectID| { :objectID => objectID } }, false), request_options)
|
407
428
|
end
|
408
429
|
|
409
430
|
#
|
410
431
|
# Delete several objects and wait end of indexing
|
411
432
|
#
|
412
|
-
# @param
|
433
|
+
# @param objects an array of objectIDs
|
413
434
|
# @param request_options contains extra parameters to send with your query
|
414
435
|
#
|
415
|
-
def delete_objects!(
|
416
|
-
res = delete_objects(
|
436
|
+
def delete_objects!(objects, request_options = {})
|
437
|
+
res = delete_objects(objects, request_options)
|
417
438
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
418
439
|
res
|
419
440
|
end
|
@@ -422,6 +443,7 @@ module Algolia
|
|
422
443
|
# Delete all objects matching a query
|
423
444
|
# This method retrieves all objects synchronously but deletes in batch
|
424
445
|
# asynchronously
|
446
|
+
#
|
425
447
|
# @param query the query string
|
426
448
|
# @param params the optional query parameters
|
427
449
|
# @param request_options contains extra parameters to send with your query
|
@@ -445,7 +467,7 @@ module Algolia
|
|
445
467
|
hits = result['hits']
|
446
468
|
break if hits.empty?
|
447
469
|
|
448
|
-
ids += hits.map { |
|
470
|
+
ids += hits.map { |hit| hit['objectID'] }
|
449
471
|
end
|
450
472
|
|
451
473
|
delete_objects(ids, request_options)
|
@@ -516,6 +538,7 @@ module Algolia
|
|
516
538
|
client.put(Protocol.settings_uri(name, options), new_settings.to_json, :write, request_options)
|
517
539
|
end
|
518
540
|
|
541
|
+
#
|
519
542
|
# Set settings for this index and wait end of indexing
|
520
543
|
#
|
521
544
|
def set_settings!(new_settings, options = {}, request_options = {})
|
@@ -524,12 +547,15 @@ module Algolia
|
|
524
547
|
res
|
525
548
|
end
|
526
549
|
|
550
|
+
#
|
527
551
|
# Get settings of this index
|
552
|
+
#
|
528
553
|
def get_settings(options = {}, request_options = {})
|
529
554
|
options['getVersion'] = 2 if !options[:getVersion] && !options['getVersion']
|
530
555
|
client.get(Protocol.settings_uri(name, options).to_s, :read, request_options)
|
531
556
|
end
|
532
557
|
|
558
|
+
#
|
533
559
|
# List all existing user keys with their associated ACLs
|
534
560
|
#
|
535
561
|
# Deprecated: Please us `client.list_api_keys` instead.
|
@@ -537,6 +563,7 @@ module Algolia
|
|
537
563
|
client.get(Protocol.index_keys_uri(name), :read, request_options)
|
538
564
|
end
|
539
565
|
|
566
|
+
#
|
540
567
|
# Get ACL of a user key
|
541
568
|
#
|
542
569
|
# Deprecated: Please us `client.get_api_key` instead.
|
@@ -547,9 +574,9 @@ module Algolia
|
|
547
574
|
#
|
548
575
|
# Create a new user key
|
549
576
|
#
|
550
|
-
# @param
|
551
|
-
# The list of parameters for this key. Defined by a
|
552
|
-
#
|
577
|
+
# @param object can be two different parameters:
|
578
|
+
# The list of parameters for this key. Defined by a Hash that can
|
579
|
+
# contains the following values:
|
553
580
|
# - acl: array of string
|
554
581
|
# - validity: int
|
555
582
|
# - referers: array of string
|
@@ -557,7 +584,7 @@ module Algolia
|
|
557
584
|
# - maxHitsPerQuery: integer
|
558
585
|
# - queryParameters: string
|
559
586
|
# - maxQueriesPerIPPerHour: integer
|
560
|
-
# Or the list of ACL for this key. Defined by an array of
|
587
|
+
# Or the list of ACL for this key. Defined by an array of String that
|
561
588
|
# can contains the following values:
|
562
589
|
# - search: allow to search (https and http)
|
563
590
|
# - addObject: allows to add/update an object in the index (https only)
|
@@ -566,36 +593,29 @@ module Algolia
|
|
566
593
|
# - settings : allows to get index settings (https only)
|
567
594
|
# - editSettings : allows to change index settings (https only)
|
568
595
|
# @param validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
569
|
-
# @param
|
570
|
-
# @param
|
596
|
+
# @param max_queries_per_IP_per_hour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
|
597
|
+
# @param max_hits_per_query the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
571
598
|
# @param request_options contains extra parameters to send with your query
|
572
|
-
#
# Deprecated: Please use `client.add_api_key` instead
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
params = {
|
577
|
-
:acl => obj
|
578
|
-
}
|
599
|
+
#
# Deprecated: Please use `client.add_api_key` instead
|
600
|
+
def add_api_key(object, validity = 0, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, request_options = {})
|
601
|
+
if object.instance_of?(Array)
|
602
|
+
params = { :acl => object }
|
579
603
|
else
|
580
|
-
params =
|
581
|
-
end
|
582
|
-
if validity != 0
|
583
|
-
params["validity"] = validity.to_i
|
584
|
-
end
|
585
|
-
if maxQueriesPerIPPerHour != 0
|
586
|
-
params["maxQueriesPerIPPerHour"] = maxQueriesPerIPPerHour.to_i
|
587
|
-
end
|
588
|
-
if maxHitsPerQuery != 0
|
589
|
-
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
604
|
+
params = object
|
590
605
|
end
|
606
|
+
|
607
|
+
params['validity'] = validity.to_i if validity != 0
|
608
|
+
params['maxHitsPerQuery'] = max_hits_per_query.to_i if max_hits_per_query != 0
|
609
|
+
params['maxQueriesPerIPPerHour'] = max_queries_per_IP_per_hour.to_i if max_queries_per_IP_per_hour != 0
|
610
|
+
|
591
611
|
client.post(Protocol.index_keys_uri(name), params.to_json, :write, request_options)
|
592
612
|
end
|
593
613
|
|
594
614
|
#
|
595
615
|
# Update a user key
|
596
616
|
#
|
597
|
-
# @param
|
598
|
-
# The list of parameters for this key. Defined by a
|
617
|
+
# @param object can be two different parameters:
|
618
|
+
# The list of parameters for this key. Defined by a Hash that
|
599
619
|
# can contains the following values:
|
600
620
|
# - acl: array of string
|
601
621
|
# - validity: int
|
@@ -604,7 +624,7 @@ module Algolia
|
|
604
624
|
# - maxHitsPerQuery: integer
|
605
625
|
# - queryParameters: string
|
606
626
|
# - maxQueriesPerIPPerHour: integer
|
607
|
-
# Or the list of ACL for this key. Defined by an array of
|
627
|
+
# Or the list of ACL for this key. Defined by an array of String that
|
608
628
|
# can contains the following values:
|
609
629
|
# - search: allow to search (https and http)
|
610
630
|
# - addObject: allows to add/update an object in the index (https only)
|
@@ -613,69 +633,70 @@ module Algolia
|
|
613
633
|
# - settings : allows to get index settings (https only)
|
614
634
|
# - editSettings : allows to change index settings (https only)
|
615
635
|
# @param validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
616
|
-
# @param
|
617
|
-
# @param
|
636
|
+
# @param max_queries_per_IP_per_hour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
|
637
|
+
# @param max_hits_per_query the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
618
638
|
# @param request_options contains extra parameters to send with your query
|
619
639
|
#
|
620
|
-
|
621
|
-
def update_api_key(key,
|
622
|
-
if
|
623
|
-
params = {
|
624
|
-
:acl => obj
|
625
|
-
}
|
640
|
+
# Deprecated: Please use `client.update_api_key` instead
|
641
|
+
def update_api_key(key, object, validity = 0, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, request_options = {})
|
642
|
+
if object.instance_of?(Array)
|
643
|
+
params = { :acl => object }
|
626
644
|
else
|
627
|
-
params =
|
628
|
-
end
|
629
|
-
if validity != 0
|
630
|
-
params["validity"] = validity.to_i
|
631
|
-
end
|
632
|
-
if maxQueriesPerIPPerHour != 0
|
633
|
-
params["maxQueriesPerIPPerHour"] = maxQueriesPerIPPerHour.to_i
|
634
|
-
end
|
635
|
-
if maxHitsPerQuery != 0
|
636
|
-
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
645
|
+
params = object
|
637
646
|
end
|
647
|
+
|
648
|
+
params['validity'] = validity.to_i if validity != 0
|
649
|
+
params['maxHitsPerQuery'] = max_hits_per_query.to_i if max_hits_per_query != 0
|
650
|
+
params['maxQueriesPerIPPerHour'] = max_queries_per_IP_per_hour.to_i if max_queries_per_IP_per_hour != 0
|
651
|
+
|
638
652
|
client.put(Protocol.index_key_uri(name, key), params.to_json, :write, request_options)
|
639
653
|
end
|
640
654
|
|
641
|
-
|
655
|
+
#
|
642
656
|
# Delete an existing user key
|
643
657
|
#
|
644
|
-
# Deprecated: Please
|
658
|
+
# Deprecated: Please use `client.delete_api_key` instead
|
645
659
|
def delete_api_key(key, request_options = {})
|
646
660
|
client.delete(Protocol.index_key_uri(name, key), :write, request_options)
|
647
661
|
end
|
648
662
|
|
663
|
+
#
|
649
664
|
# Send a batch request
|
665
|
+
#
|
650
666
|
def batch(request, request_options = {})
|
651
667
|
client.post(Protocol.batch_uri(name), request.to_json, :batch, request_options)
|
652
668
|
end
|
653
669
|
|
670
|
+
#
|
654
671
|
# Send a batch request and wait the end of the indexing
|
672
|
+
#
|
655
673
|
def batch!(request, request_options = {})
|
656
674
|
res = batch(request, request_options)
|
657
675
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
658
676
|
res
|
659
677
|
end
|
660
678
|
|
679
|
+
#
|
661
680
|
# Search for facet values
|
662
681
|
#
|
663
|
-
# @param
|
682
|
+
# @param facet_name Name of the facet to search. It must have been declared in the
|
664
683
|
# index's`attributesForFaceting` setting with the `searchable()` modifier.
|
665
|
-
# @param
|
666
|
-
# @param
|
684
|
+
# @param facet_query Text to search for in the facet's values
|
685
|
+
# @param search_parameters An optional query to take extra search parameters into account.
|
667
686
|
# These parameters apply to index objects like in a regular search query.
|
668
687
|
# Only facet values contained in the matched objects will be returned.
|
669
688
|
# @param request_options contains extra parameters to send with your query
|
670
|
-
|
671
|
-
|
672
|
-
params
|
673
|
-
|
689
|
+
#
|
690
|
+
def search_for_facet_values(facet_name, facet_query, search_parameters = {}, request_options = {})
|
691
|
+
params = search_parameters.clone
|
692
|
+
params['facetQuery'] = facet_query
|
693
|
+
client.post(Protocol.search_facet_uri(name, facet_name), params.to_json, :read, request_options)
|
674
694
|
end
|
675
695
|
|
676
696
|
# deprecated
|
677
697
|
alias_method :search_facet, :search_for_facet_values
|
678
698
|
|
699
|
+
#
|
679
700
|
# Perform a search with disjunctive facets generating as many queries as number of disjunctive facets
|
680
701
|
#
|
681
702
|
# @param query the query
|
@@ -684,6 +705,7 @@ module Algolia
|
|
684
705
|
# @param refinements a hash ("string" -> ["array", "of", "refined", "values"]) representing the current refinements
|
685
706
|
# ex: { "my_facet1" => ["my_value1", ["my_value2"], "my_disjunctive_facet1" => ["my_value1", "my_value2"] }
|
686
707
|
# @param request_options contains extra parameters to send with your query
|
708
|
+
#
|
687
709
|
def search_disjunctive_faceting(query, disjunctive_facets, params = {}, refinements = {}, request_options = {})
|
688
710
|
raise ArgumentError.new('Argument "disjunctive_facets" must be a String or an Array') unless disjunctive_facets.is_a?(String) || disjunctive_facets.is_a?(Array)
|
689
711
|
raise ArgumentError.new('Argument "refinements" must be a Hash of Arrays') if !refinements.is_a?(Hash) || !refinements.select { |k, v| !v.is_a?(Array) }.empty?
|
@@ -771,11 +793,13 @@ module Algolia
|
|
771
793
|
Algolia.list_indexes(request_options)
|
772
794
|
end
|
773
795
|
|
796
|
+
#
|
774
797
|
# Search synonyms
|
775
798
|
#
|
776
799
|
# @param query the query
|
777
800
|
# @param params an optional hash of :type, :page, :hitsPerPage
|
778
801
|
# @param request_options contains extra parameters to send with your query
|
802
|
+
#
|
779
803
|
def search_synonyms(query, params = {}, request_options = {})
|
780
804
|
type = params[:type] || params['type']
|
781
805
|
type = type.join(',') if type.is_a?(Array)
|
@@ -790,6 +814,7 @@ module Algolia
|
|
790
814
|
client.post(Protocol.search_synonyms_uri(name), params.to_json, :read, request_options)
|
791
815
|
end
|
792
816
|
|
817
|
+
#
|
793
818
|
# Get a synonym
|
794
819
|
#
|
795
820
|
# @param objectID the synonym objectID
|
@@ -798,94 +823,112 @@ module Algolia
|
|
798
823
|
client.get(Protocol.synonym_uri(name, objectID), :read, request_options)
|
799
824
|
end
|
800
825
|
|
826
|
+
#
|
801
827
|
# Delete a synonym
|
802
828
|
#
|
803
829
|
# @param objectID the synonym objectID
|
804
830
|
# @param forward_to_replicas should we forward the delete to replica indices
|
805
831
|
# @param request_options contains extra parameters to send with your query
|
832
|
+
#
|
806
833
|
def delete_synonym(objectID, forward_to_replicas = false, request_options = {})
|
807
834
|
client.delete("#{Protocol.synonym_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", :write, request_options)
|
808
835
|
end
|
809
836
|
|
837
|
+
#
|
810
838
|
# Delete a synonym and wait the end of indexing
|
811
839
|
#
|
812
840
|
# @param objectID the synonym objectID
|
813
841
|
# @param forward_to_replicas should we forward the delete to replica indices
|
814
842
|
# @param request_options contains extra parameters to send with your query
|
843
|
+
#
|
815
844
|
def delete_synonym!(objectID, forward_to_replicas = false, request_options = {})
|
816
845
|
res = delete_synonym(objectID, forward_to_replicas, request_options)
|
817
846
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
818
847
|
res
|
819
848
|
end
|
820
849
|
|
850
|
+
#
|
821
851
|
# Save a synonym
|
822
852
|
#
|
823
853
|
# @param objectID the synonym objectID
|
824
854
|
# @param synonym the synonym
|
825
855
|
# @param forward_to_replicas should we forward the delete to replica indices
|
826
856
|
# @param request_options contains extra parameters to send with your query
|
857
|
+
#
|
827
858
|
def save_synonym(objectID, synonym, forward_to_replicas = false, request_options = {})
|
828
859
|
client.put("#{Protocol.synonym_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", synonym.to_json, :write, request_options)
|
829
860
|
end
|
830
861
|
|
862
|
+
#
|
831
863
|
# Save a synonym and wait the end of indexing
|
832
864
|
#
|
833
865
|
# @param objectID the synonym objectID
|
834
866
|
# @param synonym the synonym
|
835
867
|
# @param forward_to_replicas should we forward the delete to replica indices
|
836
868
|
# @param request_options contains extra parameters to send with your query
|
869
|
+
#
|
837
870
|
def save_synonym!(objectID, synonym, forward_to_replicas = false, request_options = {})
|
838
871
|
res = save_synonym(objectID, synonym, forward_to_replicas, request_options)
|
839
872
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
840
873
|
res
|
841
874
|
end
|
842
875
|
|
876
|
+
#
|
843
877
|
# Clear all synonyms
|
844
878
|
#
|
845
879
|
# @param forward_to_replicas should we forward the delete to replica indices
|
846
880
|
# @param request_options contains extra parameters to send with your query
|
881
|
+
#
|
847
882
|
def clear_synonyms(forward_to_replicas = false, request_options = {})
|
848
883
|
client.post("#{Protocol.clear_synonyms_uri(name)}?forwardToReplicas=#{forward_to_replicas}", {}, :write, request_options)
|
849
884
|
end
|
850
885
|
|
886
|
+
#
|
851
887
|
# Clear all synonyms and wait the end of indexing
|
852
888
|
#
|
853
889
|
# @param forward_to_replicas should we forward the delete to replica indices
|
854
890
|
# @param request_options contains extra parameters to send with your query
|
891
|
+
#
|
855
892
|
def clear_synonyms!(forward_to_replicas = false, request_options = {})
|
856
893
|
res = clear_synonyms(forward_to_replicas, request_options)
|
857
894
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
858
895
|
res
|
859
896
|
end
|
860
897
|
|
898
|
+
#
|
861
899
|
# Add/Update an array of synonyms
|
862
900
|
#
|
863
901
|
# @param synonyms the array of synonyms to add/update
|
864
902
|
# @param forward_to_replicas should we forward the delete to replica indices
|
865
903
|
# @param replace_existing_synonyms should we replace the existing synonyms before adding the new ones
|
866
904
|
# @param request_options contains extra parameters to send with your query
|
905
|
+
#
|
867
906
|
def batch_synonyms(synonyms, forward_to_replicas = false, replace_existing_synonyms = false, request_options = {})
|
868
907
|
client.post("#{Protocol.batch_synonyms_uri(name)}?forwardToReplicas=#{forward_to_replicas}&replaceExistingSynonyms=#{replace_existing_synonyms}", synonyms.to_json, :batch, request_options)
|
869
908
|
end
|
870
909
|
|
910
|
+
#
|
871
911
|
# Add/Update an array of synonyms and wait the end of indexing
|
872
912
|
#
|
873
913
|
# @param synonyms the array of synonyms to add/update
|
874
914
|
# @param forward_to_replicas should we forward the delete to replica indices
|
875
915
|
# @param replace_existing_synonyms should we replace the existing synonyms before adding the new ones
|
876
916
|
# @param request_options contains extra parameters to send with your query
|
917
|
+
#
|
877
918
|
def batch_synonyms!(synonyms, forward_to_replicas = false, replace_existing_synonyms = false, request_options = {})
|
878
919
|
res = batch_synonyms(synonyms, forward_to_replicas, replace_existing_synonyms, request_options)
|
879
920
|
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
880
921
|
res
|
881
922
|
end
|
882
923
|
|
924
|
+
#
|
883
925
|
# Export the full list of synonyms
|
884
|
-
#
|
885
|
-
#
|
926
|
+
# Accepts an optional block to which it will pass each synonym
|
927
|
+
# Also returns an array with all the synonyms
|
886
928
|
#
|
887
929
|
# @param hits_per_page Amount of synonyms to retrieve on each internal request - Optional - Default: 100
|
888
930
|
# @param request_options contains extra parameters to send with your query - Optional
|
931
|
+
#
|
889
932
|
def export_synonyms(hits_per_page = 100, request_options = {}, &_block)
|
890
933
|
res = []
|
891
934
|
page = 0
|
@@ -901,11 +944,13 @@ module Algolia
|
|
901
944
|
res
|
902
945
|
end
|
903
946
|
|
947
|
+
#
|
904
948
|
# Search rules
|
905
949
|
#
|
906
950
|
# @param query the query
|
907
951
|
# @param params an optional hash of :anchoring, :context, :page, :hitsPerPage
|
908
952
|
# @param request_options contains extra parameters to send with your query
|
953
|
+
#
|
909
954
|
def search_rules(query, params = {}, request_options = {})
|
910
955
|
anchoring = params[:anchoring]
|
911
956
|
context = params[:context]
|
@@ -921,103 +966,123 @@ module Algolia
|
|
921
966
|
client.post(Protocol.search_rules_uri(name), params.to_json, :read, request_options)
|
922
967
|
end
|
923
968
|
|
969
|
+
#
|
924
970
|
# Get a rule
|
925
971
|
#
|
926
972
|
# @param objectID the rule objectID
|
927
973
|
# @param request_options contains extra parameters to send with your query
|
974
|
+
#
|
928
975
|
def get_rule(objectID, request_options = {})
|
929
976
|
client.get(Protocol.rule_uri(name, objectID), :read, request_options)
|
930
977
|
end
|
931
978
|
|
979
|
+
#
|
932
980
|
# Delete a rule
|
933
981
|
#
|
934
982
|
# @param objectID the rule objectID
|
935
983
|
# @param forward_to_replicas should we forward the delete to replica indices
|
936
984
|
# @param request_options contains extra parameters to send with your query
|
985
|
+
#
|
937
986
|
def delete_rule(objectID, forward_to_replicas = false, request_options = {})
|
938
987
|
client.delete("#{Protocol.rule_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", :write, request_options)
|
939
988
|
end
|
940
989
|
|
990
|
+
#
|
941
991
|
# Delete a rule and wait the end of indexing
|
942
992
|
#
|
943
993
|
# @param objectID the rule objectID
|
944
994
|
# @param forward_to_replicas should we forward the delete to replica indices
|
945
995
|
# @param request_options contains extra parameters to send with your query
|
996
|
+
#
|
946
997
|
def delete_rule!(objectID, forward_to_replicas = false, request_options = {})
|
947
998
|
res = delete_rule(objectID, forward_to_replicas, request_options)
|
948
|
-
wait_task(res[
|
999
|
+
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
949
1000
|
return res
|
950
1001
|
end
|
951
1002
|
|
1003
|
+
#
|
952
1004
|
# Save a rule
|
953
1005
|
#
|
954
1006
|
# @param objectID the rule objectID
|
955
1007
|
# @param rule the rule
|
956
1008
|
# @param forward_to_replicas should we forward the delete to replica indices
|
957
1009
|
# @param request_options contains extra parameters to send with your query
|
1010
|
+
#
|
958
1011
|
def save_rule(objectID, rule, forward_to_replicas = false, request_options = {})
|
959
1012
|
raise ArgumentError.new('objectID must not be blank') if objectID.nil? || objectID == ''
|
960
1013
|
client.put("#{Protocol.rule_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", rule.to_json, :write, request_options)
|
961
1014
|
end
|
962
1015
|
|
1016
|
+
#
|
963
1017
|
# Save a rule and wait the end of indexing
|
964
1018
|
#
|
965
1019
|
# @param objectID the rule objectID
|
966
1020
|
# @param rule the rule
|
967
1021
|
# @param forward_to_replicas should we forward the delete to replica indices
|
968
1022
|
# @param request_options contains extra parameters to send with your query
|
1023
|
+
#
|
969
1024
|
def save_rule!(objectID, rule, forward_to_replicas = false, request_options = {})
|
970
1025
|
res = save_rule(objectID, rule, forward_to_replicas, request_options)
|
971
|
-
wait_task(res[
|
1026
|
+
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
972
1027
|
return res
|
973
1028
|
end
|
974
1029
|
|
1030
|
+
#
|
975
1031
|
# Clear all rules
|
976
1032
|
#
|
977
1033
|
# @param forward_to_replicas should we forward the delete to replica indices
|
978
1034
|
# @param request_options contains extra parameters to send with your query
|
1035
|
+
#
|
979
1036
|
def clear_rules(forward_to_replicas = false, request_options = {})
|
980
1037
|
client.post("#{Protocol.clear_rules_uri(name)}?forwardToReplicas=#{forward_to_replicas}", {}, :write, request_options)
|
981
1038
|
end
|
982
1039
|
|
1040
|
+
#
|
983
1041
|
# Clear all rules and wait the end of indexing
|
984
1042
|
#
|
985
1043
|
# @param forward_to_replicas should we forward the delete to replica indices
|
986
1044
|
# @param request_options contains extra parameters to send with your query
|
1045
|
+
#
|
987
1046
|
def clear_rules!(forward_to_replicas = false, request_options = {})
|
988
1047
|
res = clear_rules(forward_to_replicas, request_options)
|
989
|
-
wait_task(res[
|
1048
|
+
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
990
1049
|
return res
|
991
1050
|
end
|
992
1051
|
|
1052
|
+
#
|
993
1053
|
# Add/Update an array of rules
|
994
1054
|
#
|
995
1055
|
# @param rules the array of rules to add/update
|
996
1056
|
# @param forward_to_replicas should we forward the delete to replica indices
|
997
1057
|
# @param clear_existing_rules should we clear the existing rules before adding the new ones
|
998
1058
|
# @param request_options contains extra parameters to send with your query
|
1059
|
+
#
|
999
1060
|
def batch_rules(rules, forward_to_replicas = false, clear_existing_rules = false, request_options = {})
|
1000
1061
|
client.post("#{Protocol.batch_rules_uri(name)}?forwardToReplicas=#{forward_to_replicas}&clearExistingRules=#{clear_existing_rules}", rules.to_json, :batch, request_options)
|
1001
1062
|
end
|
1002
1063
|
|
1064
|
+
#
|
1003
1065
|
# Add/Update an array of rules and wait the end of indexing
|
1004
1066
|
#
|
1005
1067
|
# @param rules the array of rules to add/update
|
1006
1068
|
# @param forward_to_replicas should we forward the delete to replica indices
|
1007
1069
|
# @param clear_existing_rules should we clear the existing rules before adding the new ones
|
1008
1070
|
# @param request_options contains extra parameters to send with your query
|
1071
|
+
#
|
1009
1072
|
def batch_rules!(rules, forward_to_replicas = false, clear_existing_rules = false, request_options = {})
|
1010
1073
|
res = batch_rules(rules, forward_to_replicas, clear_existing_rules, request_options)
|
1011
|
-
wait_task(res[
|
1074
|
+
wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
|
1012
1075
|
return res
|
1013
1076
|
end
|
1014
1077
|
|
1078
|
+
#
|
1015
1079
|
# Export the full list of rules
|
1016
|
-
#
|
1017
|
-
#
|
1080
|
+
# Accepts an optional block to which it will pass each rule
|
1081
|
+
# Also returns an array with all the rules
|
1018
1082
|
#
|
1019
1083
|
# @param hits_per_page Amount of rules to retrieve on each internal request - Optional - Default: 100
|
1020
1084
|
# @param request_options contains extra parameters to send with your query - Optional
|
1085
|
+
#
|
1021
1086
|
def export_rules(hits_per_page = 100, request_options = {}, &_block)
|
1022
1087
|
res = []
|
1023
1088
|
page = 0
|
@@ -1041,35 +1106,36 @@ module Algolia
|
|
1041
1106
|
alias_method :delete_user_key, :delete_api_key
|
1042
1107
|
|
1043
1108
|
private
|
1044
|
-
|
1045
|
-
|
1109
|
+
|
1110
|
+
def check_array(object)
|
1111
|
+
raise ArgumentError.new('argument must be an array of objects') if !object.is_a?(Array)
|
1046
1112
|
end
|
1047
1113
|
|
1048
|
-
def check_object(
|
1049
|
-
case
|
1114
|
+
def check_object(object, in_array = false)
|
1115
|
+
case object
|
1050
1116
|
when Array
|
1051
|
-
raise ArgumentError.new(in_array ?
|
1117
|
+
raise ArgumentError.new(in_array ? 'argument must be an array of objects' : 'argument must not be an array')
|
1052
1118
|
when String, Integer, Float, TrueClass, FalseClass, NilClass
|
1053
|
-
raise ArgumentError.new("argument must be an #{'array of' if in_array} object, got: #{
|
1119
|
+
raise ArgumentError.new("argument must be an #{'array of' if in_array} object, got: #{object.inspect}")
|
1054
1120
|
else
|
1055
1121
|
# ok
|
1056
1122
|
end
|
1057
1123
|
end
|
1058
1124
|
|
1059
|
-
def get_objectID(
|
1060
|
-
check_object
|
1061
|
-
objectID ||=
|
1125
|
+
def get_objectID(object, objectID = nil)
|
1126
|
+
check_object(object)
|
1127
|
+
objectID ||= object[:objectID] || object['objectID']
|
1062
1128
|
raise ArgumentError.new("Missing 'objectID'") if objectID.nil?
|
1063
1129
|
return objectID
|
1064
1130
|
end
|
1065
1131
|
|
1066
|
-
def build_batch(action,
|
1067
|
-
check_array
|
1132
|
+
def build_batch(action, objects, with_object_id = false)
|
1133
|
+
check_array(objects)
|
1068
1134
|
{
|
1069
|
-
:requests =>
|
1070
|
-
check_object
|
1071
|
-
h = { :action => action, :body =>
|
1072
|
-
h[:objectID] = get_objectID(
|
1135
|
+
:requests => objects.map { |object|
|
1136
|
+
check_object(object, true)
|
1137
|
+
h = { :action => action, :body => object }
|
1138
|
+
h[:objectID] = get_objectID(object).to_s if with_object_id
|
1073
1139
|
h
|
1074
1140
|
}
|
1075
1141
|
}
|