module Algolia

Constants

VERSION
WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY

Public Class Methods

add_api_key(object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil) click to toggle source

Create a new user key

Deprecated call was add_api_key(acl, validity, max_queries_per_IP_per_hour, max_hits_per_query, indexes)

ACL can contain an array with those strings:

- search: allow to search (https and http)
- addObject: allows to add/update an object in the index (https only)
- deleteObject : allows to delete an existing object (https only)
- deleteIndex : allows to delete index content (https only)
- settings : allows to get index settings (https only)
- editSettings : allows to change index settings (https only)

@param object can be two different parameters:

The list of parameters for this key. Defined by a NSDictionary that
can contains the following values:
  - acl: array of string
  - indexes: array of string
  - validity: int
  - referers: array of string
  - description: string
  - max_hits_per_query: integer
  - queryParameters: string
  - max_queries_per_IP_per_hour: integer

@param request_options contains extra parameters to send with your query - Default = {}

# File lib/algolia/client.rb, line 1022
def Algolia.add_api_key(object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil)
  Algolia.client.add_api_key(object, request_options, max_queries_per_IP_per_hour, max_hits_per_query, indexes)
end
add_user_key(object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil) click to toggle source

Deprecated

# File lib/algolia/client.rb, line 1029
def Algolia.add_user_key(object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil)
  Algolia.client.add_api_key(object, request_options, max_queries_per_IP_per_hour, max_hits_per_query, indexes)
end
batch(requests, request_options = {}) click to toggle source

Send a batch request targeting multiple indices

# File lib/algolia/client.rb, line 1094
def Algolia.batch(requests, request_options = {})
  Algolia.client.batch(requests, request_options)
end
batch!(requests, request_options = {}) click to toggle source

Send a batch request targeting multiple indices and wait the end of the indexing

# File lib/algolia/client.rb, line 1101
def Algolia.batch!(requests, request_options = {})
  Algolia.client.batch!(requests, request_options)
end
client() click to toggle source
# File lib/algolia/client.rb, line 1124
def Algolia.client
  if !@@client
    raise AlgoliaError, 'API not initialized'
  end
  @@client
end
copy_index(src_index, dst_index, scope = nil, request_options = {}) click to toggle source

Copy an existing index.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name (destination will be overriten if it already exist). @param scope the optional list of scopes to copy (all if not specified). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 856
def Algolia.copy_index(src_index, dst_index, scope = nil, request_options = {})
  Algolia.client.copy_index(src_index, dst_index, scope, request_options)
end
copy_index!(src_index, dst_index, scope = nil, request_options = {}) click to toggle source

Copy an existing index and wait until the copy has been processed.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name (destination will be overriten if it already exist). @param scope the optional list of scopes to copy (all if not specified). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 868
def Algolia.copy_index!(src_index, dst_index, scope = nil, request_options = {})
  Algolia.client.copy_index!(src_index, dst_index, scope, request_options)
end
copy_rules(src_index, dst_index, request_options = {}) click to toggle source

Copy an existing index rules.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name rules (destination rules will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 923
def Algolia.copy_rules(src_index, dst_index, request_options = {})
  Algolia.client.copy_rules(src_index, dst_index, request_options)
end
copy_rules!(src_index, dst_index, request_options = {}) click to toggle source

Copy an existing index rules and wait until the copy has been processed.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name rules (destination rules will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 934
def Algolia.copy_rules!(src_index, dst_index, request_options = {})
  Algolia.client.copy_rules!(src_index, dst_index, request_options)
end
copy_settings(src_index, dst_index, request_options = {}) click to toggle source

Copy an existing index settings.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name settings (destination settings will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 879
def Algolia.copy_settings(src_index, dst_index, request_options = {})
  Algolia.client.copy_settings(src_index, dst_index, request_options)
end
copy_settings!(src_index, dst_index, request_options = {}) click to toggle source

Copy an existing index settings and wait until the copy has been processed.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name settings (destination settings will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 890
def Algolia.copy_settings!(src_index, dst_index, request_options = {})
  Algolia.client.copy_settings!(src_index, dst_index, request_options)
end
copy_synonyms(src_index, dst_index, request_options = {}) click to toggle source

Copy an existing index synonyms.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name synonyms (destination synonyms will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 901
def Algolia.copy_synonyms(src_index, dst_index, request_options = {})
  Algolia.client.copy_synonyms(src_index, dst_index, request_options)
end
copy_synonyms!(src_index, dst_index, request_options = {}) click to toggle source

Copy an existing index synonyms and wait until the copy has been processed.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name synonyms (destination synonyms will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 912
def Algolia.copy_synonyms!(src_index, dst_index, request_options = {})
  Algolia.client.copy_synonyms!(src_index, dst_index, request_options)
end
delete_api_key(key, request_options = {}) click to toggle source

Delete an existing user key

# File lib/algolia/client.rb, line 1073
def Algolia.delete_api_key(key, request_options = {})
  Algolia.client.delete_api_key(key, request_options)
end
delete_index(name, request_options = {}) click to toggle source

Delete an index

# File lib/algolia/client.rb, line 941
def Algolia.delete_index(name, request_options = {})
  Algolia.client.delete_index(name, request_options)
end
delete_index!(name, request_options = {}) click to toggle source

Delete an index and wait until the deletion has been processed.

# File lib/algolia/client.rb, line 948
def Algolia.delete_index!(name, request_options = {})
  Algolia.client.delete_index!(name, request_options)
end
delete_user_key(key, request_options = {}) click to toggle source

Deprecated

# File lib/algolia/client.rb, line 1087
def Algolia.delete_user_key(key, request_options = {})
  Algolia.client.delete_api_key(key, request_options)
end
destroy() click to toggle source

Used mostly for testing. Lets you delete the api key global vars.

# File lib/algolia/client.rb, line 1118
def Algolia.destroy
  @@client.destroy unless @@client.nil?
  @@client = nil
  self
end
disable_rate_limit_forward() click to toggle source

Disable IP rate limit enabled with enableRateLimitForward() function

# File lib/algolia/client.rb, line 741
def Algolia.disable_rate_limit_forward
  Algolia.client.disable_rate_limit_forward
end
enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key) click to toggle source

Allow to use IP rate limit when you have a proxy between end-user and Algolia. This option will set the X-Forwarded-For HTTP header with the client IP and the X-Forwarded-API-Key with the API Key having rate limits.

@param admin_api_key the admin API Key you can find in your dashboard @param end_user_ip the end user IP (you can use both IPV4 or IPV6 syntax) @param rate_limit_api_key the API key on which you have a rate limit

# File lib/algolia/client.rb, line 734
def Algolia.enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key)
  Algolia.client.enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key)
end
generate_secured_api_key(private_api_key, tag_filters_or_params, user_token = nil) click to toggle source

Generate a secured and public API Key from a list of tagFilters and an optional user token identifying the current user

@param private_api_key your private API Key @param tag_filters the list of tags applied to the query (used as security) @param user_token an optional token identifying the current user

# File lib/algolia/client.rb, line 760
def Algolia.generate_secured_api_key(private_api_key, tag_filters_or_params, user_token = nil)
  if tag_filters_or_params.is_a?(Hash) && user_token.nil?
    encoded_params = Hash[tag_filters_or_params.map { |k, v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
    query_str = Protocol.to_query(encoded_params)
    hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), private_api_key, query_str)
    Base64.encode64("#{hmac}#{query_str}").gsub("\n", '')
  else
    tag_filters = if tag_filters_or_params.is_a?(Array)
      tag_filters = tag_filters_or_params.map { |t| t.is_a?(Array) ? "(#{t.join(',')})" : t }.join(',')
    else
      tag_filters_or_params
    end
    raise ArgumentError.new('Attribute "tag_filters" must be a list of tags') if !tag_filters.is_a?(String)
    OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), private_api_key, "#{tag_filters}#{user_token.to_s}")
  end
end
get_api_key(key, request_options = {}) click to toggle source

Get ACL of a user key

@param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 985
def Algolia.get_api_key(key, request_options = {})
  Algolia.client.get_api_key(key, request_options)
end
get_logs(options = nil, length = nil, type = nil) click to toggle source

Return last logs entries.

@param offset Specify the first entry to retrieve (0-based, 0 is the most recent log entry). @param length Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000. @param type Specify the type of entries you want to retrieve - default: “all” @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 960
def Algolia.get_logs(options = nil, length = nil, type = nil)
  Algolia.client.get_logs(options, length, type)
end
get_secured_api_key_remaining_validity(secured_api_key) click to toggle source

Returns the remaining validity time for the given API key in seconds

@param [String] secured_api_key the secured API key to check

@return [Integer] remaining validity in seconds

# File lib/algolia/client.rb, line 784
def Algolia.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 ValidUntilNotFoundError.new('The SecuredAPIKey doesn\'t have a validUntil parameter.')
  end

  valid_until = matches[1].to_i

  valid_until - now
end
get_task_status(index_name, taskID, request_options = {}) click to toggle source
# File lib/algolia/client.rb, line 1112
def Algolia.get_task_status(index_name, taskID, request_options = {})
  Algolia.client.get_task_status(index_name, taskID, request_options = {})
end
get_user_key(key, request_options = {}) click to toggle source

Deprecated

# File lib/algolia/client.rb, line 992
def Algolia.get_user_key(key, request_options = {})
  Algolia.client.get_user_key(key, request_options)
end
init(options = {}) click to toggle source

Initialize the singleton instance of Client which is used by all API methods

# File lib/algolia/client.rb, line 708
def Algolia.init(options = {})
  application_id = ENV['ALGOLIA_APP_ID'] || ENV['ALGOLIA_API_ID'] || ENV['ALGOLIA_APPLICATION_ID']
  api_key = ENV['ALGOLIA_REST_API_KEY'] || ENV['ALGOLIA_API_KEY']

  defaulted = { :application_id => application_id, :api_key => api_key }
  defaulted.merge!(options)

  @@client = Client.new(defaulted)
end
list_api_keys(request_options = {}) click to toggle source

List all existing user keys with their associated ACLs

@param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 969
def Algolia.list_api_keys(request_options = {})
  Algolia.client.list_api_keys(request_options)
end
list_indexes(request_options = {}) click to toggle source

List all existing indexes return an Answer object with answer in the form

{"items": [{ "name": "contacts", "createdAt": "2013-01-18T15:33:13.556Z"},
           {"name": "notes", "createdAt": "2013-01-18T15:33:13.556Z"}]}

@param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 822
def Algolia.list_indexes(request_options = {})
  Algolia.client.list_indexes(request_options)
end
list_user_keys(request_options = {}) click to toggle source

Deprecated

# File lib/algolia/client.rb, line 976
def Algolia.list_user_keys(request_options = {})
  Algolia.client.list_api_keys(request_options)
end
move_index(src_index, dst_index, request_options = {}) click to toggle source

Move an existing index.

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name (destination will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 833
def Algolia.move_index(src_index, dst_index, request_options = {})
  Algolia.client.move_index(src_index, dst_index, request_options)
end
move_index!(src_index, dst_index, request_options = {}) click to toggle source

Move an existing index and wait until the move has been processed

@param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of src_index_name (destination will be overriten if it already exist). @param request_options contains extra parameters to send with your query

# File lib/algolia/client.rb, line 844
def Algolia.move_index!(src_index, dst_index, request_options = {})
  Algolia.client.move_index!(src_index, dst_index, request_options)
end
multiple_get_objects(requests, request_options = {}) click to toggle source

This method allows to get objects (records) via objectID across multiple indexes with one API call

# File lib/algolia/client.rb, line 810
def Algolia.multiple_get_objects(requests, request_options = {})
  Algolia.client.multiple_get_objects(requests, request_options)
end
multiple_queries(queries, options = nil, strategy = nil) click to toggle source

This method allows to query multiple indexes with one API call

# File lib/algolia/client.rb, line 802
def Algolia.multiple_queries(queries, options = nil, strategy = nil)
  Algolia.client.multiple_queries(queries, options, strategy)
end
restore_api_key(key, request_options = {}) click to toggle source

Restore an existing api key

# File lib/algolia/client.rb, line 1080
def Algolia.restore_api_key(key, request_options = {})
  Algolia.client.restore_api_key(key, request_options)
end
set_extra_header(key, value) click to toggle source

Allow to set custom headers

# File lib/algolia/client.rb, line 721
def Algolia.set_extra_header(key, value)
  Algolia.client.set_extra_header(key, value)
end
update_api_key(key, object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil) click to toggle source

Update a user key

Deprecated call was update_api_key(key, acl, validity, maxQueriesPerIPPerHour, max_hits_per_query, indexes)

ACL can contain an array with those strings:

- search: allow to search (https and http)
- addObject: allows to add/update an object in the index (https only)
- deleteObject : allows to delete an existing object (https only)
- deleteIndex : allows to delete index content (https only)
- settings : allows to get index settings (https only)
- editSettings : allows to change index settings (https only)

@param key API Key to update @param object The list of parameters for this key.

Defined by a Hash that can contain the following values:
 - acl: array of string
 - indexes: array of string
 - validity: int
 - referers: array of string
 - description: string
 - max_hits_per_query: integer
 - queryParameters: string
 - max_queries_per_IP_per_hour: integer

@param request_options contains extra parameters to send with your query - Default = {}

# File lib/algolia/client.rb, line 1059
def Algolia.update_api_key(key, object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil)
  Algolia.client.update_api_key(key, object, request_options, max_queries_per_IP_per_hour, max_hits_per_query, indexes)
end
update_user_key(key, object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil) click to toggle source

Deprecated

# File lib/algolia/client.rb, line 1066
def Algolia.update_user_key(key, object, request_options = {}, max_queries_per_IP_per_hour = 0, max_hits_per_query = 0, indexes = nil)
  Algolia.client.update_api_key(key, object, request_options, max_queries_per_IP_per_hour, max_hits_per_query, indexes)
end
wait_task(index_name, taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {}) click to toggle source

Wait until task is completed by the engine

# File lib/algolia/client.rb, line 1108
def Algolia.wait_task(index_name, taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {})
  Algolia.client.wait_task(index_name, taskID, time_before_retry, request_options)
end
with_rate_limits(end_user_ip, rate_limit_api_key, &block) click to toggle source

Convenience method thats wraps enable_rate_limit_forward/disable_rate_limit_forward

# File lib/algolia/client.rb, line 748
def Algolia.with_rate_limits(end_user_ip, rate_limit_api_key, &block)
  Algolia.client.with_rate_limits(end_user_ip, rate_limit_api_key, &block)
end