Module: Algolia
- Defined in:
- lib/algolia/error.rb,
lib/algolia/index.rb,
lib/algolia/client.rb,
lib/algolia/version.rb,
lib/algolia/protocol.rb
Defined Under Namespace
Modules: Protocol Classes: AlgoliaError, AlgoliaProtocolError, Client, Index
Constant Summary collapse
- VERSION =
"1.6.1"
- @@client =
A singleton client Always use Algolia.client to retrieve the client object.
nil
Class Method Summary collapse
-
.add_user_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil) ⇒ Object
Create a new user key.
-
.batch(requests) ⇒ Object
Send a batch request targeting multiple indices.
-
.batch!(requests) ⇒ Object
Send a batch request targeting multiple indices and wait the end of the indexing.
- .client ⇒ Object
-
.copy_index(src_index, dst_index) ⇒ Object
Copy an existing index.
-
.copy_index!(src_index, dst_index) ⇒ Object
Copy an existing index and wait until the copy has been processed.
-
.delete_index(name) ⇒ Object
Delete an index.
-
.delete_index!(name) ⇒ Object
Delete an index and wait until the deletion has been processed.
-
.delete_user_key(key) ⇒ Object
Delete an existing user key.
-
.destroy ⇒ Object
Used mostly for testing.
-
.disable_rate_limit_forward ⇒ Object
Disable IP rate limit enabled with enableRateLimitForward() function.
-
.enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key) ⇒ Object
Allow to use IP rate limit when you have a proxy between end-user and Algolia.
-
.generate_secured_api_key(private_api_key, tag_filters, user_token = nil) ⇒ Object
Generate a secured and public API Key from a list of tagFilters and an optional user token identifying the current user.
-
.get_logs(offset = 0, length = 10, type = "all") ⇒ Object
Return last logs entries.
-
.get_user_key(key) ⇒ Object
Get ACL of a user key.
-
.init(options = {}) ⇒ Object
Initialize the singleton instance of Client which is used by all API methods.
-
.list_indexes ⇒ Object
List all existing indexes return an Answer object with answer in the form [{ “name”: “contacts”, “createdAt”: “2013-01-18T15:33:13.556Z”, “notes”, “createdAt”: “2013-01-18T15:33:13.556Z”]}.
-
.list_user_keys ⇒ Object
List all existing user keys with their associated ACLs.
-
.move_index(src_index, dst_index) ⇒ Object
Move an existing index.
-
.move_index!(src_index, dst_index) ⇒ Object
Move an existing index and wait until the move has been processed.
-
.multiple_queries(queries, index_name_key = :index_name, strategy = "none") ⇒ Object
This method allows to query multiple indexes with one API call.
-
.set_extra_header(key, value) ⇒ Object
Allow to set custom headers.
-
.update_user_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil) ⇒ Object
Update a user key.
-
.with_rate_limits(end_user_ip, rate_limit_api_key, &block) ⇒ Object
Convenience method thats wraps enable_rate_limit_forward/disable_rate_limit_forward.
Class Method Details
.add_user_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil) ⇒ Object
Create a new user key
@param obj 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
- indices: array of string
- validity: int
- referers: array of string
- description: string
- maxHitsPerQuery: integer
- queryParameters: string
- maxQueriesPerIPPerHour: integer
Or the list of ACL for this key. Defined by an array of NSString that
can contains the following values:
- 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 validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
@param maxQueriesPerIPPerHour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
@param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
@param indexes the optional list of targeted indexes
596 597 598 |
# File 'lib/algolia/client.rb', line 596 def Algolia.add_user_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil) Algolia.client.add_user_key(obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes) end |
.batch(requests) ⇒ Object
Send a batch request targeting multiple indices
637 638 639 |
# File 'lib/algolia/client.rb', line 637 def Algolia.batch(requests) Algolia.client.batch(requests) end |
.batch!(requests) ⇒ Object
Send a batch request targeting multiple indices and wait the end of the indexing
642 643 644 |
# File 'lib/algolia/client.rb', line 642 def Algolia.batch!(requests) Algolia.client.batch!(requests) end |
.client ⇒ Object
652 653 654 655 656 657 |
# File 'lib/algolia/client.rb', line 652 def Algolia.client if !@@client raise AlgoliaError, "API not initialized" end @@client end |
.copy_index(src_index, dst_index) ⇒ Object
Copy an existing index.
524 525 526 |
# File 'lib/algolia/client.rb', line 524 def Algolia.copy_index(src_index, dst_index) Algolia.client.copy_index(src_index, dst_index) end |
.copy_index!(src_index, dst_index) ⇒ Object
Copy an existing index and wait until the copy has been processed.
533 534 535 |
# File 'lib/algolia/client.rb', line 533 def Algolia.copy_index!(src_index, dst_index) Algolia.client.copy_index!(src_index, dst_index) end |
.delete_index(name) ⇒ Object
Delete an index
539 540 541 |
# File 'lib/algolia/client.rb', line 539 def Algolia.delete_index(name) Algolia.client.delete_index(name) end |
.delete_index!(name) ⇒ Object
Delete an index and wait until the deletion has been processed.
545 546 547 |
# File 'lib/algolia/client.rb', line 545 def Algolia.delete_index!(name) Algolia.client.delete_index!(name) end |
.delete_user_key(key) ⇒ Object
Delete an existing user key
632 633 634 |
# File 'lib/algolia/client.rb', line 632 def Algolia.delete_user_key(key) Algolia.client.delete_user_key(key) end |
.destroy ⇒ Object
Used mostly for testing. Lets you delete the api key global vars.
647 648 649 650 |
# File 'lib/algolia/client.rb', line 647 def Algolia.destroy @@client = Thread.current[:algolia_hosts] = Thread.current[:algolia_search_hosts] = nil self end |
.disable_rate_limit_forward ⇒ Object
Disable IP rate limit enabled with enableRateLimitForward() function
453 454 455 |
# File 'lib/algolia/client.rb', line 453 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) ⇒ Object
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.
446 447 448 |
# File 'lib/algolia/client.rb', line 446 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, user_token = nil) ⇒ Object
Generate a secured and public API Key from a list of tagFilters and an optional user token identifying the current user
472 473 474 475 476 477 478 |
# File 'lib/algolia/client.rb', line 472 def Algolia.generate_secured_api_key(private_api_key, tag_filters, user_token = nil) if tag_filters.is_a?(Array) tag_filters = tag_filters.map { |t| t.is_a?(Array) ? "(#{t.join(',')})" : t }.join(',') 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 |
.get_logs(offset = 0, length = 10, type = "all") ⇒ Object
Return last logs entries.
555 556 557 |
# File 'lib/algolia/client.rb', line 555 def Algolia.get_logs(offset = 0, length = 10, type = "all") Algolia.client.get_logs(offset, length, type) end |
.get_user_key(key) ⇒ Object
Get ACL of a user key
565 566 567 |
# File 'lib/algolia/client.rb', line 565 def Algolia.get_user_key(key) Algolia.client.get_user_key(key) end |
.init(options = {}) ⇒ Object
Initialize the singleton instance of Client which is used by all API methods.
422 423 424 425 426 427 428 429 430 |
# File 'lib/algolia/client.rb', line 422 def Algolia.init( = {}) application_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!() @@client = Client.new(defaulted) end |
.list_indexes ⇒ Object
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"}]}
497 498 499 |
# File 'lib/algolia/client.rb', line 497 def Algolia.list_indexes Algolia.client.list_indexes end |
.list_user_keys ⇒ Object
List all existing user keys with their associated ACLs
560 561 562 |
# File 'lib/algolia/client.rb', line 560 def Algolia.list_user_keys Algolia.client.list_user_keys end |
.move_index(src_index, dst_index) ⇒ Object
Move an existing index.
506 507 508 |
# File 'lib/algolia/client.rb', line 506 def Algolia.move_index(src_index, dst_index) Algolia.client.move_index(src_index, dst_index) end |
.move_index!(src_index, dst_index) ⇒ Object
Move an existing index and wait until the move has been processed
515 516 517 |
# File 'lib/algolia/client.rb', line 515 def Algolia.move_index!(src_index, dst_index) Algolia.client.move_index!(src_index, dst_index) end |
.multiple_queries(queries, index_name_key = :index_name, strategy = "none") ⇒ Object
This method allows to query multiple indexes with one API call
487 488 489 |
# File 'lib/algolia/client.rb', line 487 def Algolia.multiple_queries(queries, index_name_key = :index_name, strategy = "none") Algolia.client.multiple_queries(queries, index_name_key, strategy) end |
.set_extra_header(key, value) ⇒ Object
Allow to set custom headers
435 436 437 |
# File 'lib/algolia/client.rb', line 435 def Algolia.set_extra_header(key, value) Algolia.client.set_extra_header(key, value) end |
.update_user_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil) ⇒ Object
Update a user key
@param obj 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
- indices: array of string
- validity: int
- referers: array of string
- description: string
- maxHitsPerQuery: integer
- queryParameters: string
- maxQueriesPerIPPerHour: integer
Or the list of ACL for this key. Defined by an array of NSString that
can contains the following values:
- 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 validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
@param maxQueriesPerIPPerHour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
@param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
@param indexes the optional list of targeted indexes
627 628 629 |
# File 'lib/algolia/client.rb', line 627 def Algolia.update_user_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil) Algolia.client.update_user_key(key, obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes) end |
.with_rate_limits(end_user_ip, rate_limit_api_key, &block) ⇒ Object
Convenience method thats wraps enable_rate_limit_forward/disable_rate_limit_forward
460 461 462 |
# File 'lib/algolia/client.rb', line 460 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 |