Skip to content

Commit 2ad9232

Browse files
committed
feat(ruby): switch api key helper
1 parent b7dacec commit 2ad9232

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

clients/algoliasearch-client-ruby/lib/algolia/api_client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def self.default
2020
@@default ||= ApiClient.new
2121
end
2222

23+
def set_api_key(api_key)
24+
@config.set_api_key(api_key)
25+
end
26+
2327
# Call an API with given options.
2428
#
2529
# @return [Http::Response] the response.

clients/algoliasearch-client-ruby/lib/algolia/configuration.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def initialize(app_id, api_key, hosts, client_name, opts = {})
4444
yield(self) if block_given?
4545
end
4646

47+
def set_api_key(api_key)
48+
@api_key = api_key
49+
@header_params["X-Algolia-API-Key"] = api_key
50+
end
51+
4752
# The default Configuration object.
4853
def self.default
4954
@@default ||= Configuration.new

templates/ruby/api.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ module {{moduleName}}
5858
def self.create_with_config(config)
5959
new(config)
6060
end
61+
62+
# Helper method to switch the API key used to authenticate the requests.
63+
#
64+
# @param api_key [String] the new API key to use.
65+
# @return [void]
66+
def self.set_api_key(api_key)
67+
@api_client.set_api_key(api_key)
68+
end
6169

6270
{{#operation}}
6371
{{#notes}}

0 commit comments

Comments
 (0)