This page documents an earlier version of the API client. For the latest version, see Upgrade.
Upgrade from version 1 to version 2
The Ruby client is fully rebuilt while keeping a similar design to make it as smooth as possible to upgrade. It’s compatible with Ruby 2.2 and later.Upgrade the library
In yourGemfile
, replace the algoliasearch
gem with the algolia
gem.
Class names
Most classes have a different name and namespace in the new version. The most used classes are now as follows:Algolia::Client
→Algolia::Search::Client
Algolia::Index
→Algolia::Search::Index
Algolia::AccountClient
→Algolia::Account::Client
Algolia::Analytics
→Algolia::Analytics::Client
Algolia::Insights
→Algolia::Insights::Client
Client instantiation
There’s a slight change in how you instantiate the client. Index initialization remains the same:Ruby
symbolize_keys
configuration option to false
:
Ruby
Instantiating with configuration
You can instantiate all clients using configuration objects. This helps you change their default behavior and settings, such as the default region in the Insights client or custom hosts in the Search client. All setters have been moved from the client to the configuration object. If, for instance, you rely on theset_extra_headers
method or have configured timeouts by passing options to the client during initialization, you need to change your code to use a configuration object.
For example:
Ruby
Optional parameters
To have the most consistent, predictable, and future-proof method signatures, methods follow two rules:- All required parameters have a single argument each
- All optional arguments are part of a hash called
opts
as the last argument
opts
hash.
The same goes for any search_parameters
and request_options
arguments.
For example:
Ruby
New methods
The new client introduces some new methods. Most of these are helper methods: the underlying feature was already available, but required either deeper understanding or custom code.set_personalization_strategy
: set the Personalization strategy for an index.get_personalization_strategy
: get the Personalization strategy for an index.Algolia::Account::Client.copy_index
: copy in an index between Algolia applications.
List of method changes
Client
methods
multiple_queries
The strategy
parameter is no longer a string, but a key in the opts
.
Ruby
generate_secured_api_key
We’ve moved this method to the Algolia::Search::Client
class.
Ruby
add_api_key
acl
is now a single parameter.
The other parameters have been moved to the opts
.
Ruby
update_api_key
This method is now a member of the Algolia::Search::Client
class.
Ruby
get_secured_api_key_remaining_validity
We’ve moved this method to the Algolia::Search::Client
class.
Ruby
list_user_ids
The page
and hitsPerPage
parameters are now part of the opts
hash.
Ruby
search_user_ids
The clusterName
, page
, and hitsPerPage
parameters are now part of the opts
hash.
Ruby
get_logs
The offset
, length
, and type
parameters are now part of the opts
hash.
Ruby
Index
methods
search
searchParameters
and opts
are combined in a single parameter.
Ruby
search_for_facet_values
searchParameters
and opts
are combined in a single parameter.
Ruby
find_object
The method takes a lambda, proc, or block as the first argument (anything that responds to call
),
and the opts
as the second.
Ruby
get_object_position
The class name has changed, but the method remains the same.
Ruby
add_object
and add_objects
These methods are removed in favor of save_object
and save_objects
.
partial_update_object
The createIfNotExists
flag is now part of the opts
parameter.
It defaults to false
in version 2.
(It was true
in version 1.)
You only need to specify the objectID
in the record to be updated,
not as an argument when using the method.
createIfNotExists
is now part of the opts
parameter.
Ruby
partial_update_objects
The createIfNotExists
flag is now part of the opts
parameter.
It defaults to false
in version 2.
(It was true
in version 1.)
Ruby
clear_index
Renamed to clear_objects
.
Ruby
get_object
and get_objects
The attributesToRetrieve
parameter is now part of the opts
.
Ruby
delete_index
Instead of calling the delete_index
method on the client,
you should call the delete
method directly on the index object.
Ruby
browse
Renamed to browse_objects
.
Ruby
save_synonym
You only need to specify the objectID
in the synonym to be saved,
not as an argument when using the method.
Ruby
batch_synonyms
Renamed to save_synonyms
.
The forwardToReplicas
and replaceExistingSynonyms
parameters are now part of the opts
hash.
Ruby
export_synonyms
Renamed to browse_synonyms
.
Ruby
save_rule
You only need to specify the objectID
in the rule to be saved,
not as an argument when using the method.
Ruby
batch_rules
Renamed to save_rules
.
The forwardToReplicas
and clearExistingRules
parameters should now be part of the opts
.
Ruby
delete_rule
The forwardToReplicas
parameter is now part of the opts
.
Ruby
clear_rules
The forwardToReplicas
parameter is now part of the opts
.
Ruby
export_rules
Renamed to browse_rules
.
Ruby