diff --git a/lib/algolia/api/abtesting_client.rb b/lib/algolia/api/abtesting_client.rb index 45bdc9b3..84bac171 100644 --- a/lib/algolia/api/abtesting_client.rb +++ b/lib/algolia/api/abtesting_client.rb @@ -39,6 +39,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # Creates a new A/B test. # # Required API Key ACLs: diff --git a/lib/algolia/api/analytics_client.rb b/lib/algolia/api/analytics_client.rb index 3cfba8cc..00ecf4bf 100644 --- a/lib/algolia/api/analytics_client.rb +++ b/lib/algolia/api/analytics_client.rb @@ -39,6 +39,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # This method allow you to send requests to the Algolia REST API. # @param path [String] Path of the endpoint, anything after \"/1\" must be specified. (required) diff --git a/lib/algolia/api/ingestion_client.rb b/lib/algolia/api/ingestion_client.rb index b23c2110..97e72910 100644 --- a/lib/algolia/api/ingestion_client.rb +++ b/lib/algolia/api/ingestion_client.rb @@ -39,6 +39,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # Creates a new authentication resource. # # Required API Key ACLs: diff --git a/lib/algolia/api/insights_client.rb b/lib/algolia/api/insights_client.rb index 31692a70..7369f2bc 100644 --- a/lib/algolia/api/insights_client.rb +++ b/lib/algolia/api/insights_client.rb @@ -39,6 +39,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # This method allow you to send requests to the Algolia REST API. # @param path [String] Path of the endpoint, anything after \"/1\" must be specified. (required) diff --git a/lib/algolia/api/monitoring_client.rb b/lib/algolia/api/monitoring_client.rb index 5cd63b1f..53699951 100644 --- a/lib/algolia/api/monitoring_client.rb +++ b/lib/algolia/api/monitoring_client.rb @@ -24,6 +24,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # This method allow you to send requests to the Algolia REST API. # @param path [String] Path of the endpoint, anything after \"/1\" must be specified. (required) diff --git a/lib/algolia/api/personalization_client.rb b/lib/algolia/api/personalization_client.rb index bc8f0a6a..b8e4edb3 100644 --- a/lib/algolia/api/personalization_client.rb +++ b/lib/algolia/api/personalization_client.rb @@ -39,6 +39,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # This method allow you to send requests to the Algolia REST API. # @param path [String] Path of the endpoint, anything after \"/1\" must be specified. (required) diff --git a/lib/algolia/api/query_suggestions_client.rb b/lib/algolia/api/query_suggestions_client.rb index adda7fa3..c779edc0 100644 --- a/lib/algolia/api/query_suggestions_client.rb +++ b/lib/algolia/api/query_suggestions_client.rb @@ -39,6 +39,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # Creates a new Query Suggestions configuration. You can have up to 100 configurations per Algolia application. # # Required API Key ACLs: diff --git a/lib/algolia/api/recommend_client.rb b/lib/algolia/api/recommend_client.rb index 732b35f2..6f7dfb0f 100644 --- a/lib/algolia/api/recommend_client.rb +++ b/lib/algolia/api/recommend_client.rb @@ -32,6 +32,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # This method allow you to send requests to the Algolia REST API. # @param path [String] Path of the endpoint, anything after \"/1\" must be specified. (required) diff --git a/lib/algolia/api/search_client.rb b/lib/algolia/api/search_client.rb index a718a390..ab544b62 100644 --- a/lib/algolia/api/search_client.rb +++ b/lib/algolia/api/search_client.rb @@ -35,6 +35,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # Creates a new API key with specific permissions and restrictions. # # Required API Key ACLs: diff --git a/lib/algolia/api/usage_client.rb b/lib/algolia/api/usage_client.rb index 402644c0..45b0430f 100644 --- a/lib/algolia/api/usage_client.rb +++ b/lib/algolia/api/usage_client.rb @@ -24,6 +24,14 @@ def self.create_with_config(config) new(config) end + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + end + # This method allow you to send requests to the Algolia REST API. # @param path [String] Path of the endpoint, anything after \"/1\" must be specified. (required) diff --git a/lib/algolia/api_client.rb b/lib/algolia/api_client.rb index 44387622..25ebf835 100644 --- a/lib/algolia/api_client.rb +++ b/lib/algolia/api_client.rb @@ -20,6 +20,10 @@ def self.default @@default ||= ApiClient.new end + def set_client_api_key(api_key) + @config.set_client_api_key(api_key) + end + # Call an API with given options. # # @return [Http::Response] the response. diff --git a/lib/algolia/configuration.rb b/lib/algolia/configuration.rb index f60a629f..03dc9bd5 100644 --- a/lib/algolia/configuration.rb +++ b/lib/algolia/configuration.rb @@ -44,6 +44,11 @@ def initialize(app_id, api_key, hosts, client_name, opts = {}) yield(self) if block_given? end + def set_client_api_key(api_key) + @api_key = api_key + @header_params["X-Algolia-API-Key"] = api_key + end + # The default Configuration object. def self.default @@default ||= Configuration.new