169
169
#
170
170
# @return [String]
171
171
#
172
- def generate_secured_api_key(parent_api_key, restrictions = { } )
172
+ def self. generate_secured_api_key(parent_api_key, restrictions = { } )
173
173
restrictions = restrictions.to_hash
174
174
if restrictions.key?(:searchParams)
175
175
# merge searchParams with the root of the restrictions
@@ -186,13 +186,25 @@ def generate_secured_api_key(parent_api_key, restrictions = {})
186
186
Base64.encode64("#{ hmac} #{ url_encoded_restrictions} ").gsub("\n", '')
187
187
end
188
188
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
+
189
201
# Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `validUntil` parameter must have been provided.
190
202
#
191
203
# @param secured_api_key [String]
192
204
#
193
205
# @return [Integer]
194
206
#
195
- def get_secured_api_key_remaining_validity(secured_api_key)
207
+ def self. get_secured_api_key_remaining_validity(secured_api_key)
196
208
now = Time.now.to_i
197
209
decoded_key = Base64.decode64(secured_api_key)
198
210
regex = 'validUntil=(\d+)'
@@ -207,6 +219,16 @@ def get_secured_api_key_remaining_validity(secured_api_key)
207
219
valid_until - now
208
220
end
209
221
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
+
210
232
# 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.
211
233
#
212
234
# @param index_name [String]: The `index_name` to save `objects` in.
0 commit comments