Skip to content

Commit ca15e69

Browse files
authored
Merge branch 'main' into chore-add-homepage-to-package.json
2 parents 4c7437b + 066dd87 commit ca15e69

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,7 +3288,7 @@ def browse_synonyms(
32883288
#
32893289
# @return [String]
32903290
#
3291-
def generate_secured_api_key(parent_api_key, restrictions = {})
3291+
def self.generate_secured_api_key(parent_api_key, restrictions = {})
32923292
restrictions = restrictions.to_hash
32933293
if restrictions.key?(:searchParams)
32943294
# merge searchParams with the root of the restrictions
@@ -3310,13 +3310,24 @@ def generate_secured_api_key(parent_api_key, restrictions = {})
33103310
Base64.encode64("#{hmac}#{url_encoded_restrictions}").gsub("\n", "")
33113311
end
33123312

3313+
# Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
3314+
#
3315+
# @param parent_api_key [String] Parent API key used the generate the secured key
3316+
# @param restrictions [SecuredApiKeyRestrictions] Restrictions to apply on the secured key
3317+
#
3318+
# @return [String]
3319+
#
3320+
def generate_secured_api_key(parent_api_key, restrictions = {})
3321+
self.class.generate_secured_api_key(parent_api_key, restrictions)
3322+
end
3323+
33133324
# Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `validUntil` parameter must have been provided.
33143325
#
33153326
# @param secured_api_key [String]
33163327
#
33173328
# @return [Integer]
33183329
#
3319-
def get_secured_api_key_remaining_validity(secured_api_key)
3330+
def self.get_secured_api_key_remaining_validity(secured_api_key)
33203331
now = Time.now.to_i
33213332
decoded_key = Base64.decode64(secured_api_key)
33223333
regex = "validUntil=(\\d+)"
@@ -3331,6 +3342,16 @@ def get_secured_api_key_remaining_validity(secured_api_key)
33313342
valid_until - now
33323343
end
33333344

3345+
# Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `validUntil` parameter must have been provided.
3346+
#
3347+
# @param secured_api_key [String]
3348+
#
3349+
# @return [Integer]
3350+
#
3351+
def get_secured_api_key_remaining_validity(secured_api_key)
3352+
self.class.get_secured_api_key_remaining_validity(secured_api_key)
3353+
end
3354+
33343355
# Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
33353356
#
33363357
# @param index_name [String]: The `index_name` to save `objects` in.

templates/ruby/search_helpers.mustache

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ end
169169
#
170170
# @return [String]
171171
#
172-
def generate_secured_api_key(parent_api_key, restrictions = {})
172+
def self.generate_secured_api_key(parent_api_key, restrictions = {})
173173
restrictions = restrictions.to_hash
174174
if restrictions.key?(:searchParams)
175175
# merge searchParams with the root of the restrictions
@@ -186,13 +186,25 @@ def generate_secured_api_key(parent_api_key, restrictions = {})
186186
Base64.encode64("#{hmac}#{url_encoded_restrictions}").gsub("\n", '')
187187
end
188188

189+
# Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
190+
#
191+
# @param parent_api_key [String] Parent API key used the generate the secured key
192+
# @param restrictions [SecuredApiKeyRestrictions] Restrictions to apply on the secured key
193+
#
194+
# @return [String]
195+
#
196+
def generate_secured_api_key(parent_api_key, restrictions = {})
197+
self.class.generate_secured_api_key(parent_api_key, restrictions)
198+
end
199+
200+
189201
# Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `validUntil` parameter must have been provided.
190202
#
191203
# @param secured_api_key [String]
192204
#
193205
# @return [Integer]
194206
#
195-
def get_secured_api_key_remaining_validity(secured_api_key)
207+
def self.get_secured_api_key_remaining_validity(secured_api_key)
196208
now = Time.now.to_i
197209
decoded_key = Base64.decode64(secured_api_key)
198210
regex = 'validUntil=(\d+)'
@@ -207,6 +219,16 @@ def get_secured_api_key_remaining_validity(secured_api_key)
207219
valid_until - now
208220
end
209221

222+
# Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `validUntil` parameter must have been provided.
223+
#
224+
# @param secured_api_key [String]
225+
#
226+
# @return [Integer]
227+
#
228+
def get_secured_api_key_remaining_validity(secured_api_key)
229+
self.class.get_secured_api_key_remaining_validity(secured_api_key)
230+
end
231+
210232
# Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
211233
#
212234
# @param index_name [String]: The `index_name` to save `objects` in.

0 commit comments

Comments
 (0)