Skip to content

Commit ebb0647

Browse files
algolia-botmillotp
andcommitted
fix(ruby): expose static helper [skip-bc] (generated)
algolia/api-clients-automation#4191 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 3888281 commit ebb0647

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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.

0 commit comments

Comments
 (0)