Class: Algolia::Search::Client
- Inherits:
-
Object
- Object
- Algolia::Search::Client
- Defined in:
- lib/algolia/search_client.rb
Overview
Class Client
Constant Summary
Constants included from CallType
CallType::READ, CallType::WRITE
Class Method Summary collapse
-
.create(app_id, api_key) ⇒ Object
Create a new client providing only app ID and API key.
-
.create_with_config(config) ⇒ Object
Create a new client providing only the search config.
-
.generate_secured_api_key(parent_key, restrictions) ⇒ String
Generate a secured API key from the given parent key with the given restrictions.
-
.get_secured_api_key_remaining_validity(secured_api_key) ⇒ Integer
Returns the time the given securedAPIKey remains valid in seconds.
Instance Method Summary collapse
-
#add_api_key(acl, opts = {}) ⇒ AddApiKeyResponse
Add an API key with the given ACL.
-
#add_api_key!(acl, opts = {}) ⇒ AddApiKeyResponse
Add an API key with the given ACL and wait for the task to complete.
-
#assign_user_id(user_id, cluster_name, opts = {}) ⇒ Hash
Assign or Move a userID to a cluster.
-
#assign_user_ids(user_ids, cluster_name, opts = {}) ⇒ Hash
Assign multiple userIDs to a cluster.
-
#clear_dictionary_entries(dictionary, opts = {}) ⇒ Object
Clear all entries for a given dictionary.
-
#clear_dictionary_entries!(dictionary, opts = {}) ⇒ Object
Clear all entries for a given dictionary and wait for the task to finish.
-
#copy_index(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the source index to the destination index.
-
#copy_index!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the source index to the destination index and wait for the task to complete.
-
#copy_rules(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the rules from source index to destination index.
-
#copy_rules!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the rules from source index to destination index and wait for the task to complete.
-
#copy_settings(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the settings from source index to destination index.
-
#copy_settings!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the settings from source index to destination index and wait for the task to complete.
-
#copy_synonyms(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the synonyms from source index to destination index.
-
#copy_synonyms!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the synonyms from source index to destination index and wait for the task to complete.
-
#custom_request(data, uri, method, call_type, opts = {}) ⇒ Object
Method available to make custom requests to the API.
-
#delete_api_key(key, opts = {}) ⇒ DeleteApiKeyResponse
Delete the given API key.
-
#delete_api_key!(key, opts = {}) ⇒ DeleteApiKeyResponse
Delete the given API key and wait for the task to complete.
-
#delete_dictionary_entries(dictionary, object_ids, opts = {}) ⇒ Object
Delete entries for a given dictionary.
-
#delete_dictionary_entries!(dictionary, object_ids, opts = {}) ⇒ Object
Delete entries for a given dictionary and wait for the task to finish.
-
#get_api_key(key_id, opts = {}) ⇒ Hash
Get the designated API key.
-
#get_dictionary_settings(opts = {}) ⇒ Object
Retrieve settings for all the dictionaries.
-
#get_logs(opts = {}) ⇒ Hash
Retrieve the client logs.
-
#get_task_status(index_name, task_id, opts = {}) ⇒ String
Check the status of a task on the server.
-
#get_top_user_ids(opts = {}) ⇒ Hash
Get the top 10 userIDs with the highest number of records per cluster.
-
#get_user_id(user_id, opts = {}) ⇒ Hash
Returns the userID data stored in the mapping.
-
#init_index(index_name) ⇒ Index
Initialize an index with a given name.
-
#initialize(search_config, opts = {}) ⇒ Client
constructor
Initialize a client to connect to Algolia.
-
#list_api_keys(opts = {}) ⇒ Hash
List all keys associated with the current client.
-
#list_clusters(opts = {}) ⇒ Hash
List the clusters available in a multi-clusters setup for a single appID.
-
#list_indexes(opts = {}) ⇒ Hash
List all indexes of the client.
-
#list_user_ids(opts = {}) ⇒ Hash
List the userIDs assigned to a multi-clusters appID.
-
#move_index(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Move the source index to the destination index.
-
#move_index!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Move the source index to the destination index and wait for the task to complete.
-
#multiple_batch(operations, opts = {}) ⇒ MultipleIndexBatchIndexingResponse
Batch multiple operations.
-
#multiple_batch!(operations, opts = {}) ⇒ MultipleIndexBatchIndexingResponse
Batch multiple operations and wait for the task to complete.
-
#multiple_get_objects(requests, opts = {}) ⇒ Hash
Retrieve multiple objects in one batch request.
-
#multiple_queries(queries, opts = {}) ⇒ Hash
(also: #search)
Search multiple indices.
-
#pending_mappings?(opts = {}) ⇒ Hash
(also: #has_pending_mappings)
Get the status of your clusters’ migrations or user creations.
-
#remove_user_id(user_id, opts = {}) ⇒ Hash
Remove a userID and its associated data from the multi-clusters.
-
#replace_dictionary_entries(dictionary, dictionary_entries, opts = {}) ⇒ Object
Replace entries for a given dictionary.
-
#replace_dictionary_entries!(dictionary, dictionary_entries, opts = {}) ⇒ Object
Replace entries for a given dictionary and wait for the task to finish.
-
#restore_api_key(key, opts = {}) ⇒ RestoreApiKeyResponse
Restore the given API key.
-
#restore_api_key!(key, opts = {}) ⇒ RestoreApiKeyResponse
Restore the given API key and wait for the task to complete.
-
#save_dictionary_entries(dictionary, dictionary_entries, opts = {}) ⇒ Object
Save entries for a given dictionary.
-
#save_dictionary_entries!(dictionary, dictionary_entries, opts = {}) ⇒ Object
Save entries for a given dictionary and wait for the task to finish.
-
#search_dictionary_entries(dictionary, query, opts = {}) ⇒ Object
Search entries for a given dictionary.
-
#search_user_ids(query, opts = {}) ⇒ Hash
Search for userIDs.
-
#set_dictionary_settings(dictionary_settings, opts = {}) ⇒ Object
Set settings for all the dictionaries.
-
#set_dictionary_settings!(dictionary_settings, opts = {}) ⇒ Object
Set settings for all the dictionaries and wait for the task to finish.
-
#update_api_key(key, opts = {}) ⇒ UpdateApiKeyResponse
Update an API key with the optional parameters.
-
#update_api_key!(key, opts = {}) ⇒ UpdateApiKeyResponse
Update an API key with the optional parameters and wait for the task to complete.
-
#wait_task(index_name, task_id, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, opts = {}) ⇒ Object
Fetch the task status until it returns as “published”, meaning the operation is done.
Methods included from Helpers
#check_array, #check_object, #chunk, #deserialize_settings, #get_object_id, #get_option, #handle_params, #hash_includes_subset?, included, #json_to_hash, #path_encode, #symbolize_hash, #to_json, #to_query_string
Constructor Details
#initialize(search_config, opts = {}) ⇒ Client
Initialize a client to connect to Algolia
19 20 21 22 23 24 25 |
# File 'lib/algolia/search_client.rb', line 19 def initialize(search_config, opts = {}) @config = search_config adapter = opts[:adapter] || Defaults::ADAPTER @logger = opts[:logger] || LoggerHelper.create requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, @logger) @transporter = Transport::Transport.new(@config, requester) end |
Class Method Details
.create(app_id, api_key) ⇒ Object
Create a new client providing only app ID and API key
34 35 36 37 |
# File 'lib/algolia/search_client.rb', line 34 def self.create(app_id, api_key) config = Search::Config.new(application_id: app_id, api_key: api_key) create_with_config(config) end |
.create_with_config(config) ⇒ Object
Create a new client providing only the search config
45 46 47 |
# File 'lib/algolia/search_client.rb', line 45 def self.create_with_config(config) new(config) end |
.generate_secured_api_key(parent_key, restrictions) ⇒ String
Generate a secured API key from the given parent key with the given restrictions
405 406 407 408 409 |
# File 'lib/algolia/search_client.rb', line 405 def self.generate_secured_api_key(parent_key, restrictions) url_encoded_restrictions = to_query_string(symbolize_hash(restrictions)) hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), parent_key, url_encoded_restrictions) Base64.encode64("#{hmac}#{url_encoded_restrictions}").gsub("\n", '') end |
.get_secured_api_key_remaining_validity(secured_api_key) ⇒ Integer
Returns the time the given securedAPIKey remains valid in seconds
417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/algolia/search_client.rb', line 417 def self.get_secured_api_key_remaining_validity(secured_api_key) now = Time.now.to_i decoded_key = Base64.decode64(secured_api_key) regex = 'validUntil=(\d+)' matches = decoded_key.match(regex) if matches.nil? raise AlgoliaError, 'The SecuredAPIKey doesn\'t have a validUntil parameter.' end valid_until = matches[1].to_i valid_until - now end |
Instance Method Details
#add_api_key(acl, opts = {}) ⇒ AddApiKeyResponse
Add an API key with the given ACL
289 290 291 292 293 |
# File 'lib/algolia/search_client.rb', line 289 def add_api_key(acl, opts = {}) response = @transporter.write(:POST, '/1/keys', { acl: acl }, opts) AddApiKeyResponse.new(self, response) end |
#add_api_key!(acl, opts = {}) ⇒ AddApiKeyResponse
Add an API key with the given ACL and wait for the task to complete
302 303 304 305 306 |
# File 'lib/algolia/search_client.rb', line 302 def add_api_key!(acl, opts = {}) response = add_api_key(acl, opts) response.wait(opts) end |
#assign_user_id(user_id, cluster_name, opts = {}) ⇒ Hash
Assign or Move a userID to a cluster.
499 500 501 502 503 504 |
# File 'lib/algolia/search_client.rb', line 499 def assign_user_id(user_id, cluster_name, opts = {}) = symbolize_hash(opts) [:headers] = { 'X-Algolia-User-ID': user_id } @transporter.write(:POST, '/1/clusters/mapping', { cluster: cluster_name }, ) end |
#assign_user_ids(user_ids, cluster_name, opts = {}) ⇒ Hash
Assign multiple userIDs to a cluster.
513 514 515 |
# File 'lib/algolia/search_client.rb', line 513 def assign_user_ids(user_ids, cluster_name, opts = {}) @transporter.write(:POST, '/1/clusters/mapping/batch', { cluster: cluster_name, users: user_ids }, opts) end |
#clear_dictionary_entries(dictionary, opts = {}) ⇒ Object
Clear all entries for a given dictionary
712 713 714 |
# File 'lib/algolia/search_client.rb', line 712 def clear_dictionary_entries(dictionary, opts = {}) replace_dictionary_entries(dictionary, [], opts) end |
#clear_dictionary_entries!(dictionary, opts = {}) ⇒ Object
Clear all entries for a given dictionary and wait for the task to finish
721 722 723 724 725 |
# File 'lib/algolia/search_client.rb', line 721 def clear_dictionary_entries!(dictionary, opts = {}) response = replace_dictionary_entries(dictionary, [], opts) response.wait(opts) end |
#copy_index(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the source index to the destination index
216 217 218 219 220 |
# File 'lib/algolia/search_client.rb', line 216 def copy_index(src_index_name, dest_index_name, opts = {}) response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', src_index_name), { operation: 'copy', destination: dest_index_name }, opts) IndexingResponse.new(init_index(src_index_name), response) end |
#copy_index!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the source index to the destination index and wait for the task to complete
230 231 232 233 234 |
# File 'lib/algolia/search_client.rb', line 230 def copy_index!(src_index_name, dest_index_name, opts = {}) response = copy_index(src_index_name, dest_index_name, opts) response.wait(opts) end |
#copy_rules(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the rules from source index to destination index
132 133 134 135 136 |
# File 'lib/algolia/search_client.rb', line 132 def copy_rules(src_index_name, dest_index_name, opts = {}) = symbolize_hash(opts) [:scope] = ['rules'] copy_index(src_index_name, dest_index_name, ) end |
#copy_rules!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the rules from source index to destination index and wait for the task to complete
146 147 148 149 150 |
# File 'lib/algolia/search_client.rb', line 146 def copy_rules!(src_index_name, dest_index_name, opts = {}) = symbolize_hash(opts) [:scope] = ['rules'] copy_index!(src_index_name, dest_index_name, ) end |
#copy_settings(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the settings from source index to destination index
160 161 162 163 164 |
# File 'lib/algolia/search_client.rb', line 160 def copy_settings(src_index_name, dest_index_name, opts = {}) = symbolize_hash(opts) [:scope] = ['settings'] copy_index(src_index_name, dest_index_name, ) end |
#copy_settings!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the settings from source index to destination index and wait for the task to complete
174 175 176 177 178 |
# File 'lib/algolia/search_client.rb', line 174 def copy_settings!(src_index_name, dest_index_name, opts = {}) = symbolize_hash(opts) [:scope] = ['settings'] copy_index!(src_index_name, dest_index_name, ) end |
#copy_synonyms(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the synonyms from source index to destination index
188 189 190 191 192 |
# File 'lib/algolia/search_client.rb', line 188 def copy_synonyms(src_index_name, dest_index_name, opts = {}) = symbolize_hash(opts) [:scope] = ['synonyms'] copy_index(src_index_name, dest_index_name, ) end |
#copy_synonyms!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Copy the synonyms from source index to destination index and wait for the task to complete
202 203 204 205 206 |
# File 'lib/algolia/search_client.rb', line 202 def copy_synonyms!(src_index_name, dest_index_name, opts = {}) = symbolize_hash(opts) [:scope] = ['synonyms'] copy_index!(src_index_name, dest_index_name, ) end |
#custom_request(data, uri, method, call_type, opts = {}) ⇒ Object
Method available to make custom requests to the API
782 783 784 785 786 787 788 |
# File 'lib/algolia/search_client.rb', line 782 def custom_request(data, uri, method, call_type, opts = {}) if call_type == WRITE @transporter.write(method.to_sym, uri, data, opts) elsif call_type == READ @transporter.read(method.to_sym, uri, data, opts) end end |
#delete_api_key(key, opts = {}) ⇒ DeleteApiKeyResponse
Delete the given API key
343 344 345 346 347 |
# File 'lib/algolia/search_client.rb', line 343 def delete_api_key(key, opts = {}) response = @transporter.write(:DELETE, path_encode('/1/keys/%s', key), {}, opts) DeleteApiKeyResponse.new(self, response, key) end |
#delete_api_key!(key, opts = {}) ⇒ DeleteApiKeyResponse
Delete the given API key and wait for the task to complete
356 357 358 359 360 |
# File 'lib/algolia/search_client.rb', line 356 def delete_api_key!(key, opts = {}) response = delete_api_key(key, opts) response.wait(opts) end |
#delete_dictionary_entries(dictionary, object_ids, opts = {}) ⇒ Object
Delete entries for a given dictionary
679 680 681 682 683 684 685 686 687 688 689 690 691 |
# File 'lib/algolia/search_client.rb', line 679 def delete_dictionary_entries(dictionary, object_ids, opts = {}) request = object_ids.map do |object_id| { objectID: object_id } end response = @transporter.write( :POST, path_encode('/1/dictionaries/%s/batch', dictionary), { clearExistingDictionaryEntries: false, requests: chunk('deleteEntry', request) }, opts ) DictionaryResponse.new(self, response) end |
#delete_dictionary_entries!(dictionary, object_ids, opts = {}) ⇒ Object
Delete entries for a given dictionary and wait for the task to finish
699 700 701 702 703 |
# File 'lib/algolia/search_client.rb', line 699 def delete_dictionary_entries!(dictionary, object_ids, opts = {}) response = delete_dictionary_entries(dictionary, object_ids, opts) response.wait(opts) end |
#get_api_key(key_id, opts = {}) ⇒ Hash
Get the designated API key
278 279 280 |
# File 'lib/algolia/search_client.rb', line 278 def get_api_key(key_id, opts = {}) @transporter.read(:GET, path_encode('/1/keys/%s', key_id), {}, opts) end |
#get_dictionary_settings(opts = {}) ⇒ Object
Retrieve settings for all the dictionaries
772 773 774 |
# File 'lib/algolia/search_client.rb', line 772 def get_dictionary_settings(opts = {}) @transporter.read(:GET, '/1/dictionaries/*/settings', {}, opts) end |
#get_logs(opts = {}) ⇒ Hash
Retrieve the client logs
116 117 118 |
# File 'lib/algolia/search_client.rb', line 116 def get_logs(opts = {}) @transporter.read(:GET, '/1/logs', {}, opts) end |
#get_task_status(index_name, task_id, opts = {}) ⇒ String
Check the status of a task on the server. All server task are asynchronous and you can check the status of a task with this method.
77 78 79 80 |
# File 'lib/algolia/search_client.rb', line 77 def get_task_status(index_name, task_id, opts = {}) res = @transporter.read(:GET, path_encode('/1/indexes/%s/task/%s', index_name, task_id), {}, opts) get_option(res, 'status') end |
#get_top_user_ids(opts = {}) ⇒ Hash
Get the top 10 userIDs with the highest number of records per cluster.
523 524 525 |
# File 'lib/algolia/search_client.rb', line 523 def get_top_user_ids(opts = {}) @transporter.read(:GET, '/1/clusters/mapping/top', {}, opts) end |
#get_user_id(user_id, opts = {}) ⇒ Hash
Returns the userID data stored in the mapping.
534 535 536 |
# File 'lib/algolia/search_client.rb', line 534 def get_user_id(user_id, opts = {}) @transporter.read(:GET, path_encode('/1/clusters/mapping/%s', user_id), {}, opts) end |
#init_index(index_name) ⇒ Index
Initialize an index with a given name
92 93 94 95 96 97 98 |
# File 'lib/algolia/search_client.rb', line 92 def init_index(index_name) stripped_index_name = index_name.strip if stripped_index_name.empty? raise AlgoliaError, 'Please provide a valid index name' end Index.new(stripped_index_name, @transporter, @config, @logger) end |
#list_api_keys(opts = {}) ⇒ Hash
List all keys associated with the current client
394 395 396 |
# File 'lib/algolia/search_client.rb', line 394 def list_api_keys(opts = {}) @transporter.read(:GET, '/1/keys', {}, opts) end |
#list_clusters(opts = {}) ⇒ Hash
List the clusters available in a multi-clusters setup for a single appID
544 545 546 |
# File 'lib/algolia/search_client.rb', line 544 def list_clusters(opts = {}) @transporter.read(:GET, '/1/clusters', {}, opts) end |
#list_indexes(opts = {}) ⇒ Hash
List all indexes of the client
106 107 108 |
# File 'lib/algolia/search_client.rb', line 106 def list_indexes(opts = {}) @transporter.read(:GET, '/1/indexes', {}, opts) end |
#list_user_ids(opts = {}) ⇒ Hash
List the userIDs assigned to a multi-clusters appID
554 555 556 |
# File 'lib/algolia/search_client.rb', line 554 def list_user_ids(opts = {}) @transporter.read(:GET, '/1/clusters/mapping', {}, opts) end |
#move_index(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Move the source index to the destination index
248 249 250 251 252 |
# File 'lib/algolia/search_client.rb', line 248 def move_index(src_index_name, dest_index_name, opts = {}) response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', src_index_name), { operation: 'move', destination: dest_index_name }, opts) IndexingResponse.new(init_index(src_index_name), response) end |
#move_index!(src_index_name, dest_index_name, opts = {}) ⇒ IndexingResponse
Move the source index to the destination index and wait for the task to complete
262 263 264 265 266 |
# File 'lib/algolia/search_client.rb', line 262 def move_index!(src_index_name, dest_index_name, opts = {}) response = move_index(src_index_name, dest_index_name, opts) response.wait(opts) end |
#multiple_batch(operations, opts = {}) ⇒ MultipleIndexBatchIndexingResponse
Batch multiple operations
443 444 445 446 447 |
# File 'lib/algolia/search_client.rb', line 443 def multiple_batch(operations, opts = {}) response = @transporter.write(:POST, '/1/indexes/*/batch', { requests: operations }, opts) MultipleIndexBatchIndexingResponse.new(self, response) end |
#multiple_batch!(operations, opts = {}) ⇒ MultipleIndexBatchIndexingResponse
Batch multiple operations and wait for the task to complete
456 457 458 459 460 |
# File 'lib/algolia/search_client.rb', line 456 def multiple_batch!(operations, opts = {}) response = multiple_batch(operations, opts) response.wait(opts) end |
#multiple_get_objects(requests, opts = {}) ⇒ Hash
Retrieve multiple objects in one batch request
469 470 471 |
# File 'lib/algolia/search_client.rb', line 469 def multiple_get_objects(requests, opts = {}) @transporter.read(:POST, '/1/indexes/*/objects', { requests: requests }, opts) end |
#multiple_queries(queries, opts = {}) ⇒ Hash Also known as: search
Search multiple indices
480 481 482 483 484 485 |
# File 'lib/algolia/search_client.rb', line 480 def multiple_queries(queries, opts = {}) queries.each do |q| q[:params] = to_query_string(q[:params]) unless q[:params].nil? || q[:params].is_a?(String) end @transporter.read(:POST, '/1/indexes/*/queries', { requests: queries }, opts) end |
#pending_mappings?(opts = {}) ⇒ Hash Also known as: has_pending_mappings
Get the status of your clusters’ migrations or user creations
589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/algolia/search_client.rb', line 589 def pending_mappings?(opts = {}) retrieve_mappings = false = symbolize_hash(opts) if .has_key?(:retrieveMappings) retrieve_mappings = [:retrieveMappings] .delete(:retrieveMappings) end @transporter.read(:GET, '/1/clusters/mapping/pending' + handle_params({ getClusters: retrieve_mappings }), {}, ) end |
#remove_user_id(user_id, opts = {}) ⇒ Hash
Remove a userID and its associated data from the multi-clusters
565 566 567 568 569 570 |
# File 'lib/algolia/search_client.rb', line 565 def remove_user_id(user_id, opts = {}) = symbolize_hash(opts) [:headers] = { 'X-Algolia-User-ID': user_id } @transporter.write(:DELETE, '/1/clusters/mapping', {}, ) end |
#replace_dictionary_entries(dictionary, dictionary_entries, opts = {}) ⇒ Object
Replace entries for a given dictionary
648 649 650 651 652 653 654 655 656 657 |
# File 'lib/algolia/search_client.rb', line 648 def replace_dictionary_entries(dictionary, dictionary_entries, opts = {}) response = @transporter.write( :POST, path_encode('/1/dictionaries/%s/batch', dictionary), { clearExistingDictionaryEntries: true, requests: chunk('addEntry', dictionary_entries) }, opts ) DictionaryResponse.new(self, response) end |
#replace_dictionary_entries!(dictionary, dictionary_entries, opts = {}) ⇒ Object
Replace entries for a given dictionary and wait for the task to finish
665 666 667 668 669 |
# File 'lib/algolia/search_client.rb', line 665 def replace_dictionary_entries!(dictionary, dictionary_entries, opts = {}) response = replace_dictionary_entries(dictionary, dictionary_entries, opts) response.wait(opts) end |
#restore_api_key(key, opts = {}) ⇒ RestoreApiKeyResponse
Restore the given API key
369 370 371 372 373 |
# File 'lib/algolia/search_client.rb', line 369 def restore_api_key(key, opts = {}) @transporter.write(:POST, path_encode('/1/keys/%s/restore', key), {}, opts) RestoreApiKeyResponse.new(self, key) end |
#restore_api_key!(key, opts = {}) ⇒ RestoreApiKeyResponse
Restore the given API key and wait for the task to complete
382 383 384 385 386 |
# File 'lib/algolia/search_client.rb', line 382 def restore_api_key!(key, opts = {}) response = restore_api_key(key, opts) response.wait(opts) end |
#save_dictionary_entries(dictionary, dictionary_entries, opts = {}) ⇒ Object
Save entries for a given dictionary
617 618 619 620 621 622 623 624 625 626 |
# File 'lib/algolia/search_client.rb', line 617 def save_dictionary_entries(dictionary, dictionary_entries, opts = {}) response = @transporter.write( :POST, path_encode('/1/dictionaries/%s/batch', dictionary), { clearExistingDictionaryEntries: false, requests: chunk('addEntry', dictionary_entries) }, opts ) DictionaryResponse.new(self, response) end |
#save_dictionary_entries!(dictionary, dictionary_entries, opts = {}) ⇒ Object
Save entries for a given dictionary and wait for the task to finish
634 635 636 637 638 |
# File 'lib/algolia/search_client.rb', line 634 def save_dictionary_entries!(dictionary, dictionary_entries, opts = {}) response = save_dictionary_entries(dictionary, dictionary_entries, opts) response.wait(opts) end |
#search_dictionary_entries(dictionary, query, opts = {}) ⇒ Object
Search entries for a given dictionary
733 734 735 736 737 738 739 740 |
# File 'lib/algolia/search_client.rb', line 733 def search_dictionary_entries(dictionary, query, opts = {}) @transporter.read( :POST, path_encode('/1/dictionaries/%s/search', dictionary), { query: query }, opts ) end |
#search_user_ids(query, opts = {}) ⇒ Hash
Search for userIDs
579 580 581 |
# File 'lib/algolia/search_client.rb', line 579 def search_user_ids(query, opts = {}) @transporter.read(:POST, '/1/clusters/mapping/search', { query: query }, opts) end |
#set_dictionary_settings(dictionary_settings, opts = {}) ⇒ Object
Set settings for all the dictionaries
749 750 751 752 753 |
# File 'lib/algolia/search_client.rb', line 749 def set_dictionary_settings(dictionary_settings, opts = {}) response = @transporter.write(:PUT, '/1/dictionaries/*/settings', dictionary_settings, opts) DictionaryResponse.new(self, response) end |
#set_dictionary_settings!(dictionary_settings, opts = {}) ⇒ Object
Set settings for all the dictionaries and wait for the task to finish
762 763 764 765 766 |
# File 'lib/algolia/search_client.rb', line 762 def set_dictionary_settings!(dictionary_settings, opts = {}) response = set_dictionary_settings(dictionary_settings, opts) response.wait(opts) end |
#update_api_key(key, opts = {}) ⇒ UpdateApiKeyResponse
Update an API key with the optional parameters
315 316 317 318 319 320 321 |
# File 'lib/algolia/search_client.rb', line 315 def update_api_key(key, opts = {}) = symbolize_hash(opts) response = @transporter.write(:PUT, path_encode('/1/keys/%s', key), {}, ) UpdateApiKeyResponse.new(self, response, ) end |
#update_api_key!(key, opts = {}) ⇒ UpdateApiKeyResponse
Update an API key with the optional parameters and wait for the task to complete
330 331 332 333 334 |
# File 'lib/algolia/search_client.rb', line 330 def update_api_key!(key, opts = {}) response = update_api_key(key, opts) response.wait(opts) end |
#wait_task(index_name, task_id, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, opts = {}) ⇒ Object
Fetch the task status until it returns as “published”, meaning the operation is done
58 59 60 61 62 63 64 65 66 |
# File 'lib/algolia/search_client.rb', line 58 def wait_task(index_name, task_id, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, opts = {}) loop do status = get_task_status(index_name, task_id, opts) if status == 'published' return end sleep(time_before_retry.to_f / 1000) end end |