algolia 3.0.0.beta.3 → 3.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55b1f581a3ca4f6ef59d05989130f89559c010f4e114c749a4b9dc523bf45fa6
4
- data.tar.gz: 8b6e80f68129c52f05c2ce91f05a93c4436831f4c3ea450be2351ad6e5c964a5
3
+ metadata.gz: d8a5616a1aa9d89d365371c04b20236bd153937bc86549a340c90f2f996c467b
4
+ data.tar.gz: f07daa4f630934d9fee7a49d30ec1aaa48ad207799db4e754dad39b0fede65d2
5
5
  SHA512:
6
- metadata.gz: 698e012f76df7596ceec8b4200bc77f4e4b889b535a9f015b1b69ad9d780c1a53cb4750ad4a4670908dc931152bdd869f80d961c4c305364cbf9ee8bac8549c2
7
- data.tar.gz: 98c728722f3b2fdc67162b2b4cd6695dac5c1e22d5f5f6c35114ae5c7e3243d64cd43b7bc3a733b751a9acfe5f59f6fa37f228322184a107b2599df4f9ba2951
6
+ metadata.gz: 45af977700dd17bca72b31970899b2e790a6b51c599177fa254babced3e460ee0d67ca4e7cc6b6f1486a7856b0a275527fe30e44aaf3221c421f4a4b0042cd59
7
+ data.tar.gz: e8e4fc306aea4b38a5b842061530e4c305900d1b64ba54f701e7f32cdd019a9187076520c640010a1bcf04c79b323ff6e122488e0244c3a63a2b92bd885c6c5f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [3.0.0.beta.4](https://github.com/algolia/algoliasearch-client-ruby/compare/3.0.0.beta.3...3.0.0.beta.4)
2
+
3
+ - [b2a464a2b](https://github.com/algolia/api-clients-automation/commit/b2a464a2b) feat(clients): add generate_secured_api_key to ruby ([#3166](https://github.com/algolia/api-clients-automation/pull/3166)) by [@millotp](https://github.com/millotp/)
4
+ - [de4090789](https://github.com/algolia/api-clients-automation/commit/de4090789) fix(clients): safer replaceAllObjects + metis compliant ([#3164](https://github.com/algolia/api-clients-automation/pull/3164)) by [@shortcuts](https://github.com/shortcuts/)
5
+
1
6
  ## [3.0.0.beta.3](https://github.com/algolia/algoliasearch-client-ruby/compare/3.0.0.beta.2...3.0.0.beta.3)
2
7
 
3
8
  - [072c38b9a](https://github.com/algolia/api-clients-automation/commit/072c38b9a) fix(clients): remove unused models from lite clients ([#3159](https://github.com/algolia/api-clients-automation/pull/3159)) by [@shortcuts](https://github.com/shortcuts/)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- algolia (3.0.0.beta.3)
4
+ algolia (3.0.0.beta.4)
5
5
  faraday (>= 1.0.1, < 3.0)
6
6
  faraday-net_http_persistent (>= 0.15, < 3)
7
7
  net-http-persistent
data/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  <a href="http://stackoverflow.com/questions/tagged/algolia" target="_blank">Stack Overflow</a> •
20
20
  <a href="https://github.com/algolia/algoliasearch-client-ruby/issues" target="_blank">Report a bug</a> •
21
21
  <a href="https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/" target="_blank">FAQ</a> •
22
- <a href="https://www.algolia.com/support" target="_blank">Support</a>
22
+ <a href="https://alg.li/support" target="_blank">Support</a>
23
23
  </p>
24
24
 
25
25
  ## ✨ Features
@@ -1,5 +1,8 @@
1
1
  # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
2
2
 
3
+ require 'openssl'
4
+ require 'base64'
5
+
3
6
  module Algolia
4
7
  class SearchClient
5
8
  attr_accessor :api_client
@@ -3129,5 +3132,53 @@ module Algolia
3129
3132
 
3130
3133
  synonyms unless block_given?
3131
3134
  end
3135
+
3136
+ # Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
3137
+ #
3138
+ # @param parent_api_key [String] Parent API key used the generate the secured key
3139
+ # @param restrictions [SecuredApiKeyRestrictions] Restrictions to apply on the secured key
3140
+ #
3141
+ # @return [String]
3142
+ #
3143
+ def generate_secured_api_key(parent_api_key, restrictions = {})
3144
+ restrictions = restrictions.to_hash
3145
+ if restrictions.key?(:searchParams)
3146
+ # merge searchParams with the root of the restrictions
3147
+
3148
+ restrictions.merge!(restrictions[:searchParams])
3149
+ restrictions.delete(:searchParams)
3150
+ end
3151
+
3152
+ url_encoded_restrictions = Algolia::Transport.stringify_query_params(restrictions).sort.to_h.map do |key, value|
3153
+ "#{key}=#{value}"
3154
+ end.join('&')
3155
+
3156
+ hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), parent_api_key, url_encoded_restrictions)
3157
+
3158
+ puts "hmac: #{hmac}"
3159
+ puts "url_encoded_restrictions: #{url_encoded_restrictions}"
3160
+ Base64.encode64("#{hmac}#{url_encoded_restrictions}").gsub("\n", '')
3161
+ end
3162
+
3163
+ # Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `validUntil` parameter must have been provided.
3164
+ #
3165
+ # @param secured_api_key [String]
3166
+ #
3167
+ # @return [Integer]
3168
+ #
3169
+ def get_secured_api_key_remaining_validity(secured_api_key)
3170
+ now = Time.now.to_i
3171
+ decoded_key = Base64.decode64(secured_api_key)
3172
+ regex = 'validUntil=(\d+)'
3173
+ matches = decoded_key.match(regex)
3174
+
3175
+ if matches.nil?
3176
+ raise AlgoliaError, 'The SecuredApiKey doesn\'t have a validUntil parameter.'
3177
+ end
3178
+
3179
+ valid_until = matches[1].to_i
3180
+
3181
+ valid_until - now
3182
+ end
3132
3183
  end
3133
3184
  end
@@ -9,6 +9,13 @@ module Algolia
9
9
  CGI.escape(uri).gsub('+', '%20')
10
10
  end
11
11
 
12
+ def self.stringify_query_params(query_params)
13
+ query_params.to_h do |key, value|
14
+ value = value.join(',') if value.is_a?(Array)
15
+ [encode_uri(key.to_s).to_sym, encode_uri(value.to_s)]
16
+ end
17
+ end
18
+
12
19
  class Transport
13
20
  include RetryOutcomeType
14
21
  include CallType
@@ -79,7 +86,7 @@ module Algolia
79
86
  request[:method] = method.downcase
80
87
  request[:path] = path
81
88
  request[:body] = build_body(body, request_options)
82
- request[:query_params] = stringify_query_params(request_options.query_params)
89
+ request[:query_params] = Algolia::Transport.stringify_query_params(request_options.query_params)
83
90
  request[:header_params] = generate_header_params(body, request_options)
84
91
  request[:timeout] = request_options.timeout
85
92
  request[:connect_timeout] = request_options.connect_timeout
@@ -128,13 +135,6 @@ module Algolia
128
135
  @config.write_timeout
129
136
  end
130
137
  end
131
-
132
- def stringify_query_params(query_params)
133
- query_params.to_h do |key, value|
134
- value = value.join(',') if value.is_a?(Array)
135
- [Algolia::Transport.encode_uri(key.to_s).to_sym, Algolia::Transport.encode_uri(value.to_s)]
136
- end
137
- end
138
138
  end
139
139
  end
140
140
  end
@@ -1,5 +1,5 @@
1
1
  # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
2
2
 
3
3
  module Algolia
4
- VERSION = '3.0.0.beta.3'.freeze
4
+ VERSION = '3.0.0.beta.4'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algolia
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta.3
4
+ version: 3.0.0.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://alg.li/support
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-11 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday