algolia 3.42.3 → 3.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/do-not-edit-this-repository.yml +1 -1
  3. data/.github/workflows/issue.yml +7 -5
  4. data/.github/workflows/release.yml +4 -4
  5. data/CHANGELOG.md +29 -0
  6. data/Gemfile.lock +2 -2
  7. data/lib/algolia/api/abtesting_client.rb +20 -13
  8. data/lib/algolia/api/abtesting_v3_client.rb +2 -1
  9. data/lib/algolia/api/agent_studio_client.rb +2 -1
  10. data/lib/algolia/api/analytics_client.rb +223 -1
  11. data/lib/algolia/api/composition_client.rb +2 -1
  12. data/lib/algolia/api/ingestion_client.rb +2 -1
  13. data/lib/algolia/api/insights_client.rb +2 -1
  14. data/lib/algolia/api/monitoring_client.rb +2 -1
  15. data/lib/algolia/api/personalization_client.rb +2 -1
  16. data/lib/algolia/api/query_suggestions_client.rb +2 -1
  17. data/lib/algolia/api/recommend_client.rb +2 -1
  18. data/lib/algolia/api/search_client.rb +124 -20
  19. data/lib/algolia/api_client.rb +10 -2
  20. data/lib/algolia/chunked_helper_options.rb +1 -0
  21. data/lib/algolia/configuration.rb +10 -2
  22. data/lib/algolia/error.rb +20 -3
  23. data/lib/algolia/models/abtesting-v3/ab_test.rb +7 -19
  24. data/lib/algolia/models/abtesting-v3/decision.rb +219 -0
  25. data/lib/algolia/models/analytics/bin_edge.rb +109 -0
  26. data/lib/algolia/models/analytics/catalog.rb +208 -0
  27. data/lib/algolia/models/analytics/catalog_entry.rb +249 -0
  28. data/lib/algolia/models/analytics/distribution_definition.rb +243 -0
  29. data/lib/algolia/models/analytics/distribution_payload.rb +247 -0
  30. data/lib/algolia/models/analytics/domain_catalog.rb +253 -0
  31. data/lib/algolia/models/analytics/field_reference.rb +219 -0
  32. data/lib/algolia/models/analytics/filter_definition.rb +238 -0
  33. data/lib/algolia/models/analytics/order_definition.rb +230 -0
  34. data/lib/algolia/models/analytics/order_direction.rb +34 -0
  35. data/lib/algolia/models/analytics/parameter_definition.rb +230 -0
  36. data/lib/algolia/models/analytics/parameter_reference.rb +219 -0
  37. data/lib/algolia/models/analytics/parameter_value.rb +111 -0
  38. data/lib/algolia/models/analytics/scalar_payload.rb +247 -0
  39. data/lib/algolia/models/analytics/series.rb +234 -0
  40. data/lib/algolia/models/analytics/series_date.rb +223 -0
  41. data/lib/algolia/models/analytics/table_payload.rb +292 -0
  42. data/lib/algolia/models/analytics/table_response.rb +211 -0
  43. data/lib/algolia/models/analytics/timeseries_payload.rb +279 -0
  44. data/lib/algolia/models/analytics/timeseries_response.rb +213 -0
  45. data/lib/algolia/models/insights/added_to_cart_object_ids_after_search.rb +1 -1
  46. data/lib/algolia/models/insights/clicked_object_ids_after_search.rb +1 -1
  47. data/lib/algolia/models/insights/converted_object_ids_after_search.rb +1 -1
  48. data/lib/algolia/models/insights/events_items.rb +1 -0
  49. data/lib/algolia/models/insights/instantsearch.rb +269 -0
  50. data/lib/algolia/models/insights/instantsearch_event.rb +33 -0
  51. data/lib/algolia/models/search/log.rb +11 -0
  52. data/lib/algolia/transport/http/http_requester.rb +2 -2
  53. data/lib/algolia/transport/request_id.rb +49 -0
  54. data/lib/algolia/transport/transport.rb +79 -8
  55. data/lib/algolia/version.rb +1 -1
  56. data/lib/algolia.rb +1 -0
  57. metadata +26 -2
@@ -0,0 +1,269 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 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.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Insights
10
+ class Instantsearch
11
+ # Event name, up to 64 ASCII characters. Consider naming events consistently—for example, by adopting Segment's [object-action](https://segment.com/academy/collecting-data/naming-conventions-for-clean-data/#the-object-action-framework) framework.
12
+ attr_accessor :event_name
13
+
14
+ attr_accessor :event_type
15
+
16
+ # Anonymous or pseudonymous user identifier. Don't use personally identifiable information in user tokens. For more information, see [User token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken).
17
+ attr_accessor :user_token
18
+
19
+ # Identifier for authenticated users. When the user signs in, you can get an identifier from your system and send it as `authenticatedUserToken`. This lets you keep using the `userToken` from before the user signed in, while providing a reliable way to identify users across sessions. Don't use personally identifiable information in user tokens. For more information, see [User token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken).
20
+ attr_accessor :authenticated_user_token
21
+
22
+ # Timestamp of the event, measured in milliseconds since the Unix epoch. Must be no older than 30 days. If not provided, we use the time at which the request was received.
23
+ attr_accessor :timestamp
24
+
25
+ # Unique identifier for an agent session. Used to correlate instantsearch events with a specific agent interaction.
26
+ attr_accessor :agent_id
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :event_name => :eventName,
32
+ :event_type => :eventType,
33
+ :user_token => :userToken,
34
+ :authenticated_user_token => :authenticatedUserToken,
35
+ :timestamp => :timestamp,
36
+ :agent_id => :agentID
37
+ }
38
+ end
39
+
40
+ # Returns the keys that uniquely identify this oneOf variant when present
41
+ def self.discriminator_attributes
42
+ [
43
+ :eventType
44
+ ]
45
+ end
46
+
47
+ # Attribute type mapping.
48
+ def self.types_mapping
49
+ {
50
+ :event_name => :"String",
51
+ :event_type => :"InstantsearchEvent",
52
+ :user_token => :"String",
53
+ :authenticated_user_token => :"String",
54
+ :timestamp => :"Integer",
55
+ :agent_id => :"String"
56
+ }
57
+ end
58
+
59
+ # List of attributes with nullable: true
60
+ def self.openapi_nullable
61
+ Set.new(
62
+ []
63
+ )
64
+ end
65
+
66
+ # Initializes the object
67
+ # @param [Hash] attributes Model attributes in the form of hash
68
+ def initialize(attributes = {})
69
+ if (!attributes.is_a?(Hash))
70
+ raise(
71
+ ArgumentError,
72
+ "The input argument (attributes) must be a hash in `Algolia::Instantsearch` initialize method"
73
+ )
74
+ end
75
+
76
+ # check to see if the attribute exists and convert string to symbol for hash key
77
+ attributes = attributes.each_with_object({}) { |(k, v), h|
78
+ if (!self.class.attribute_map.key?(k.to_sym))
79
+ raise(
80
+ ArgumentError,
81
+ "`#{k}` is not a valid attribute in `Algolia::Instantsearch`. Please check the name to make sure it's valid. List of attributes: " +
82
+ self.class.attribute_map.keys.inspect
83
+ )
84
+ end
85
+
86
+ h[k.to_sym] = v
87
+ }
88
+
89
+ if attributes.key?(:event_name)
90
+ self.event_name = attributes[:event_name]
91
+ else
92
+ self.event_name = nil
93
+ end
94
+
95
+ if attributes.key?(:event_type)
96
+ self.event_type = attributes[:event_type]
97
+ else
98
+ self.event_type = nil
99
+ end
100
+
101
+ if attributes.key?(:user_token)
102
+ self.user_token = attributes[:user_token]
103
+ else
104
+ self.user_token = nil
105
+ end
106
+
107
+ if attributes.key?(:authenticated_user_token)
108
+ self.authenticated_user_token = attributes[:authenticated_user_token]
109
+ end
110
+
111
+ if attributes.key?(:timestamp)
112
+ self.timestamp = attributes[:timestamp]
113
+ end
114
+
115
+ if attributes.key?(:agent_id)
116
+ self.agent_id = attributes[:agent_id]
117
+ end
118
+ end
119
+
120
+ # Checks equality by comparing each attribute.
121
+ # @param [Object] Object to be compared
122
+ def ==(other)
123
+ return true if self.equal?(other)
124
+ self.class == other.class &&
125
+ event_name == other.event_name &&
126
+ event_type == other.event_type &&
127
+ user_token == other.user_token &&
128
+ authenticated_user_token == other.authenticated_user_token &&
129
+ timestamp == other.timestamp &&
130
+ agent_id == other.agent_id
131
+ end
132
+
133
+ # @see the `==` method
134
+ # @param [Object] Object to be compared
135
+ def eql?(other)
136
+ self == other
137
+ end
138
+
139
+ # Calculates hash code according to all attributes.
140
+ # @return [Integer] Hash code
141
+ def hash
142
+ [event_name, event_type, user_token, authenticated_user_token, timestamp, agent_id].hash
143
+ end
144
+
145
+ # Builds the object from hash
146
+ # @param [Hash] attributes Model attributes in the form of hash
147
+ # @return [Object] Returns the model itself
148
+ def self.build_from_hash(attributes)
149
+ return nil unless attributes.is_a?(Hash)
150
+ attributes = attributes.transform_keys(&:to_sym)
151
+ transformed_hash = {}
152
+ types_mapping.each_pair do |key, type|
153
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
154
+ transformed_hash[key.to_sym] = nil
155
+ elsif type =~ /\AArray<(.*)>/i
156
+ # check to ensure the input is an array given that the attribute
157
+ # is documented as an array but the input is not
158
+ if attributes[attribute_map[key]].is_a?(Array)
159
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
160
+ _deserialize(::Regexp.last_match(1), v)
161
+ }
162
+ end
163
+ elsif !attributes[attribute_map[key]].nil?
164
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
165
+ end
166
+ end
167
+
168
+ new(transformed_hash)
169
+ end
170
+
171
+ # Deserializes the data based on type
172
+ # @param string type Data type
173
+ # @param string value Value to be deserialized
174
+ # @return [Object] Deserialized data
175
+ def self._deserialize(type, value)
176
+ case type.to_sym
177
+ when :Time
178
+ Time.parse(value)
179
+ when :Date
180
+ Date.parse(value)
181
+ when :String
182
+ value.to_s
183
+ when :Integer
184
+ value.to_i
185
+ when :Float
186
+ value.to_f
187
+ when :Boolean
188
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
189
+ true
190
+ else
191
+ false
192
+ end
193
+
194
+ when :Object
195
+ # generic object (usually a Hash), return directly
196
+ value
197
+ when /\AArray<(?<inner_type>.+)>\z/
198
+ inner_type = Regexp.last_match[:inner_type]
199
+ value.map { |v| _deserialize(inner_type, v) }
200
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
201
+ k_type = Regexp.last_match[:k_type]
202
+ v_type = Regexp.last_match[:v_type]
203
+ {}.tap do |hash|
204
+ value.each do |k, v|
205
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
206
+ end
207
+ end
208
+ # model
209
+ else
210
+ # models (e.g. Pet) or oneOf
211
+ klass = Algolia::Insights.const_get(type)
212
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
213
+ .build_from_hash(value)
214
+ end
215
+ end
216
+
217
+ # Returns the string representation of the object
218
+ # @return [String] String presentation of the object
219
+ def to_s
220
+ to_hash.to_s
221
+ end
222
+
223
+ # to_body is an alias to to_hash (backward compatibility)
224
+ # @return [Hash] Returns the object in the form of hash
225
+ def to_body
226
+ to_hash
227
+ end
228
+
229
+ def to_json(*_args)
230
+ to_hash.to_json
231
+ end
232
+
233
+ # Returns the object in the form of hash
234
+ # @return [Hash] Returns the object in the form of hash
235
+ def to_hash
236
+ hash = {}
237
+ self.class.attribute_map.each_pair do |attr, param|
238
+ value = send(attr)
239
+ if value.nil?
240
+ is_nullable = self.class.openapi_nullable.include?(attr)
241
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
242
+ end
243
+
244
+ hash[param] = _to_hash(value)
245
+ end
246
+
247
+ hash
248
+ end
249
+
250
+ # Outputs non-array value in the form of hash
251
+ # For object, use to_hash. Otherwise, just return the value
252
+ # @param [Object] value Any valid value
253
+ # @return [Hash] Returns the value in the form of hash
254
+ def _to_hash(value)
255
+ if value.is_a?(Array)
256
+ value.map { |v| _to_hash(v) }
257
+ elsif value.is_a?(Hash)
258
+ {}.tap do |hash|
259
+ value.each { |k, v| hash[k] = _to_hash(v) }
260
+ end
261
+ elsif value.respond_to?(:to_hash)
262
+ value.to_hash
263
+ else
264
+ value
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 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.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Insights
10
+ class InstantsearchEvent
11
+ INSTANTSEARCH = "instantsearch".freeze
12
+
13
+ def self.all_vars
14
+ @all_vars ||= [INSTANTSEARCH].freeze
15
+ end
16
+
17
+ # Builds the enum from string
18
+ # @param [String] The enum value in the form of the string
19
+ # @return [String] The enum value
20
+ def self.build_from_hash(value)
21
+ new.build_from_hash(value)
22
+ end
23
+
24
+ # Builds the enum from string
25
+ # @param [String] The enum value in the form of the string
26
+ # @return [String] The enum value
27
+ def build_from_hash(value)
28
+ return value if InstantsearchEvent.all_vars.include?(value)
29
+ raise "Invalid ENUM value #{value} for class #InstantsearchEvent"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -8,6 +8,9 @@ require "time"
8
8
  module Algolia
9
9
  module Search
10
10
  class Log
11
+ # Correlation ID of the logged API request, also returned in that request's `Correlation-ID` response header.
12
+ attr_accessor :cid
13
+
11
14
  # Date and time of the API request, in RFC 3339 format.
12
15
  attr_accessor :timestamp
13
16
 
@@ -56,6 +59,7 @@ module Algolia
56
59
  # Attribute mapping from ruby-style variable name to JSON key.
57
60
  def self.attribute_map
58
61
  {
62
+ :cid => :cid,
59
63
  :timestamp => :timestamp,
60
64
  :method => :method,
61
65
  :answer_code => :answer_code,
@@ -77,6 +81,7 @@ module Algolia
77
81
  # Attribute type mapping.
78
82
  def self.types_mapping
79
83
  {
84
+ :cid => :"String",
80
85
  :timestamp => :"String",
81
86
  :method => :"String",
82
87
  :answer_code => :"String",
@@ -122,6 +127,10 @@ module Algolia
122
127
  h[k.to_sym] = v
123
128
  }
124
129
 
130
+ if attributes.key?(:cid)
131
+ self.cid = attributes[:cid]
132
+ end
133
+
125
134
  if attributes.key?(:timestamp)
126
135
  self.timestamp = attributes[:timestamp]
127
136
  else
@@ -210,6 +219,7 @@ module Algolia
210
219
  def ==(other)
211
220
  return true if self.equal?(other)
212
221
  self.class == other.class &&
222
+ cid == other.cid &&
213
223
  timestamp == other.timestamp &&
214
224
  method == other.method &&
215
225
  answer_code == other.answer_code &&
@@ -237,6 +247,7 @@ module Algolia
237
247
  # @return [Integer] Hash code
238
248
  def hash
239
249
  [
250
+ cid,
240
251
  timestamp,
241
252
  method,
242
253
  answer_code,
@@ -26,8 +26,8 @@ module Algolia
26
26
  #
27
27
  def send_request(host, method, path, body, query_params, headers, timeout, connect_timeout)
28
28
  connection = connection(host)
29
- connection.options.timeout = timeout / 1000
30
- connection.options.open_timeout = connect_timeout / 1000
29
+ connection.options.timeout = timeout / 1000.0
30
+ connection.options.open_timeout = connect_timeout / 1000.0
31
31
  path += handle_query_params(query_params)
32
32
 
33
33
  @logger.info("Sending #{method.to_s.upcase} request to #{path} with body #{body}") if ENV["ALGOLIA_DEBUG"]
@@ -0,0 +1,49 @@
1
+ require "securerandom"
2
+
3
+ module Algolia
4
+ module Transport
5
+ # Mints the Request-ID tracing header sent by the clients that support it.
6
+ module RequestId
7
+ HEADER = "request-id".freeze
8
+ CORRELATION_HEADER = "Correlation-ID".freeze
9
+ QUERY_PARAM = "x-algolia-request-id".freeze
10
+
11
+ # Returns a fresh 11-character base62 identifier suitable for the Request-ID header.
12
+ #
13
+ # @return [String]
14
+ #
15
+ def self.generate
16
+ SecureRandom.alphanumeric(11)
17
+ end
18
+
19
+ # Whether the given headers already carry a Request-ID entry, whatever its casing
20
+ # and key type. Header hashes keep the caller's literal casing and may use symbol
21
+ # keys, so the lookup must not assume a canonical form.
22
+ #
23
+ # @param headers [Hash, nil]
24
+ #
25
+ # @return [true, false]
26
+ #
27
+ def self.request_id?(headers)
28
+ return false unless headers.respond_to?(:each_pair)
29
+
30
+ headers.any? { |k, _| k.to_s.casecmp?(HEADER) }
31
+ end
32
+
33
+ # Whether the given query parameters already carry an x-algolia-request-id
34
+ # entry, whatever its casing and key type. The server consults the query
35
+ # parameter only when the header is absent, so minting a header would
36
+ # override a caller-supplied value sent on that channel.
37
+ #
38
+ # @param query_params [Hash, nil]
39
+ #
40
+ # @return [true, false]
41
+ #
42
+ def self.request_id_query_param?(query_params)
43
+ return false unless query_params.respond_to?(:each_pair)
44
+
45
+ query_params.any? { |k, _| k.to_s.casecmp?(QUERY_PARAM) }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -23,13 +23,25 @@ module Algolia
23
23
 
24
24
  # @param config [Configuration]
25
25
  # @param requester [Object] requester used for sending requests. Uses Algolia::Http::HttpRequester by default
26
+ # @param request_id_support [true, false] the generated per-client Request-ID capability
26
27
  #
27
- def initialize(config, requester)
28
+ def initialize(config, requester, request_id_support: false)
28
29
  @config = config
29
30
  @requester = requester
31
+ @request_id_support = request_id_support
30
32
  @retry_strategy = RetryStrategy.new(config.hosts)
31
33
  end
32
34
 
35
+ # Whether the transport mints Request-ID headers. Resolved per request so a
36
+ # caller can flip config.request_id_enabled at any time, like every other
37
+ # Configuration setting; nil falls back to the per-client capability.
38
+ #
39
+ # @return [true, false]
40
+ #
41
+ def request_id_enabled?
42
+ @config.request_id_enabled.nil? ? @request_id_support : @config.request_id_enabled
43
+ end
44
+
33
45
  # @param call_type [Binary] READ or WRITE operation
34
46
  # @param method [Symbol] method used for request
35
47
  # @param path [String] path of the request
@@ -41,7 +53,23 @@ module Algolia
41
53
  def request(call_type, method, path, body, opts = {})
42
54
  retry_errors = []
43
55
 
56
+ # The Request-ID is minted once per execution, before the host loop, so that
57
+ # every retry attempt shares the same value and each subsequent call gets a
58
+ # fresh one.
59
+ request_id = mint_request_id(opts)
60
+
61
+ # create consumes these two channels from opts on every attempt: snapshot them
62
+ # so retries keep them. Timeout keys stay consumable, recomputed per host below.
63
+ header_params = opts[:header_params]
64
+ query_params = opts[:query_params]
65
+
66
+ # The Correlation-ID of the last retried attempt whose response carried a
67
+ # non-empty one, surfaced on the exhaustion error for support tickets.
68
+ last_correlation_id = nil
69
+
44
70
  @retry_strategy.get_tryable_hosts(call_type).each do |host|
71
+ opts[:header_params] ||= header_params
72
+ opts[:query_params] ||= query_params
45
73
  opts[:timeout] ||= get_timeout(call_type)
46
74
  opts[:connect_timeout] ||= (@config.connect_timeout || Defaults::CONNECT_TIMEOUT) * (host.retry_count + 1)
47
75
 
@@ -50,7 +78,7 @@ module Algolia
50
78
  # TODO: what is this merge for ?
51
79
  # request_options.query_params.merge!(request_options.data) if method == :GET
52
80
 
53
- request = build_request(method, path, body, request_options)
81
+ request = build_request(method, path, body, request_options, request_id)
54
82
  response = @requester.send_request(
55
83
  host,
56
84
  request[:method],
@@ -69,16 +97,20 @@ module Algolia
69
97
  network_failure: response.network_failure
70
98
  )
71
99
  if outcome == FAILURE
100
+ correlation_id = correlation_id_from(response.headers)
101
+
72
102
  # handle HTML error
73
103
  if response.headers["content-type"]&.include?("text/html")
74
- raise Algolia::AlgoliaHttpError.new(response.status, response.reason_phrase)
104
+ raise Algolia::AlgoliaHttpError.new(response.status, response.reason_phrase, correlation_id)
75
105
  end
76
106
 
77
107
  decoded_error = JSON.parse(response.error, :symbolize_names => true)
78
- raise Algolia::AlgoliaHttpError.new(response.status, decoded_error[:message])
108
+ raise Algolia::AlgoliaHttpError.new(response.status, decoded_error[:message], correlation_id)
79
109
  end
80
110
 
81
111
  if outcome == RETRY
112
+ correlation_id = correlation_id_from(response.headers)
113
+ last_correlation_id = correlation_id unless correlation_id.nil? || correlation_id.empty?
82
114
  retry_errors << {host: host.url, error: response.error}
83
115
  else
84
116
  return response
@@ -88,29 +120,65 @@ module Algolia
88
120
  raise(
89
121
  Algolia::AlgoliaUnreachableHostError.new(
90
122
  "Unreachable hosts. If the error persists, please visit our help center https://alg.li/support-unreachable-hosts or reach out to the Algolia Support team: https://alg.li/support",
91
- retry_errors
123
+ retry_errors,
124
+ last_correlation_id
92
125
  )
93
126
  )
94
127
  end
95
128
 
96
129
  private
97
130
 
131
+ # Returns a fresh Request-ID, or nil when the feature is off for this client
132
+ # or the caller already supplied one through the request options, the config
133
+ # default headers, or the x-algolia-request-id query parameter. Caller-supplied
134
+ # values ride their own channel on every attempt.
135
+ #
136
+ # @param opts [Hash]
137
+ #
138
+ # @return [String, nil]
139
+ #
140
+ def mint_request_id(opts)
141
+ return nil unless request_id_enabled?
142
+ return nil if RequestId.request_id?(opts[:header_params])
143
+ return nil if RequestId.request_id?(@config.header_params)
144
+ return nil if RequestId.request_id_query_param?(opts[:query_params])
145
+
146
+ RequestId.generate
147
+ end
148
+
149
+ # Reads the Correlation-ID header of a failed response case-insensitively: the
150
+ # headers hash keeps the server's casing and defaults to an empty string on
151
+ # timeout and network failures. The unrelated X-Algolia-RequestID edge header
152
+ # must never be read instead.
153
+ #
154
+ # @param headers [Hash, String]
155
+ #
156
+ # @return [String, nil]
157
+ #
158
+ def correlation_id_from(headers)
159
+ return nil unless headers.respond_to?(:each_pair)
160
+
161
+ headers.find { |k, _| k.to_s.casecmp?(RequestId::CORRELATION_HEADER) }&.last
162
+ end
163
+
98
164
  # Parse the different information and build the request
99
165
  #
100
166
  # @param [Symbol] method
101
167
  # @param [String] path
102
168
  # @param [Hash] body
103
169
  # @param [RequestOptions] request_options
170
+ # @param [String, nil] request_id
104
171
  #
105
172
  # @return [Hash]
106
173
  #
107
- def build_request(method, path, body, request_options)
174
+ def build_request(method, path, body, request_options, request_id = nil)
108
175
  request = {}
109
176
  request[:method] = method.downcase
110
177
  request[:path] = path
111
178
  request[:body] = build_body(body, request_options)
112
179
  request[:query_params] = Algolia::Transport.stringify_query_params(request_options.query_params)
113
- request[:header_params] = generate_header_params(body, request_options)
180
+
181
+ request[:header_params] = generate_header_params(body, request_options, request_id)
114
182
  request[:timeout] = request_options.timeout
115
183
  request[:connect_timeout] = request_options.connect_timeout
116
184
  request
@@ -129,13 +197,16 @@ module Algolia
129
197
 
130
198
  # Generates headers from config headers and optional parameters
131
199
  #
200
+ # @param body [String, nil]
132
201
  # @param request_options [RequestOptions]
202
+ # @param request_id [String, nil]
133
203
  #
134
204
  # @return [Hash] merged headers
135
205
  #
136
- def generate_header_params(body, request_options)
206
+ def generate_header_params(body, request_options, request_id = nil)
137
207
  header_params = request_options.header_params.transform_keys(&:downcase)
138
208
  header_params = @config.header_params.merge(header_params)
209
+ header_params[RequestId::HEADER] = request_id if request_id
139
210
  if request_options.compression_type == "gzip" && body.is_a?(String) && !body.to_s.strip.empty?
140
211
  header_params["content-encoding"] = "gzip"
141
212
  end
@@ -3,5 +3,5 @@
3
3
  # 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.
4
4
 
5
5
  module Algolia
6
- VERSION = "3.42.3"
6
+ VERSION = "3.45.0"
7
7
  end
data/lib/algolia.rb CHANGED
@@ -17,6 +17,7 @@ require "algolia/transport/call_type"
17
17
  require "algolia/transport/retry_outcome_type"
18
18
  require "algolia/transport/stateful_host"
19
19
  require "algolia/transport/retry_strategy"
20
+ require "algolia/transport/request_id"
20
21
  require "algolia/transport/request_options"
21
22
  require "algolia/transport/transport"
22
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algolia
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.42.3
4
+ version: 3.45.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://alg.li/support
@@ -157,6 +157,7 @@ files:
157
157
  - lib/algolia/models/abtesting-v3/add_ab_tests_request.rb
158
158
  - lib/algolia/models/abtesting-v3/add_ab_tests_variant.rb
159
159
  - lib/algolia/models/abtesting-v3/create_metric.rb
160
+ - lib/algolia/models/abtesting-v3/decision.rb
160
161
  - lib/algolia/models/abtesting-v3/direction.rb
161
162
  - lib/algolia/models/abtesting-v3/effect_metric.rb
162
163
  - lib/algolia/models/abtesting-v3/empty_search_filter.rb
@@ -325,6 +326,9 @@ files:
325
326
  - lib/algolia/models/agent-studio/user_message_v5.rb
326
327
  - lib/algolia/models/agent-studio/validation_error.rb
327
328
  - lib/algolia/models/agent-studio/vote_enum.rb
329
+ - lib/algolia/models/analytics/bin_edge.rb
330
+ - lib/algolia/models/analytics/catalog.rb
331
+ - lib/algolia/models/analytics/catalog_entry.rb
328
332
  - lib/algolia/models/analytics/click_position.rb
329
333
  - lib/algolia/models/analytics/currency_code.rb
330
334
  - lib/algolia/models/analytics/daily_add_to_cart_rates.rb
@@ -340,7 +344,12 @@ files:
340
344
  - lib/algolia/models/analytics/daily_searches_no_results.rb
341
345
  - lib/algolia/models/analytics/daily_users.rb
342
346
  - lib/algolia/models/analytics/direction.rb
347
+ - lib/algolia/models/analytics/distribution_definition.rb
348
+ - lib/algolia/models/analytics/distribution_payload.rb
349
+ - lib/algolia/models/analytics/domain_catalog.rb
343
350
  - lib/algolia/models/analytics/error_base.rb
351
+ - lib/algolia/models/analytics/field_reference.rb
352
+ - lib/algolia/models/analytics/filter_definition.rb
344
353
  - lib/algolia/models/analytics/get_add_to_cart_rate_response.rb
345
354
  - lib/algolia/models/analytics/get_average_click_position_response.rb
346
355
  - lib/algolia/models/analytics/get_click_positions_response.rb
@@ -367,6 +376,18 @@ files:
367
376
  - lib/algolia/models/analytics/get_users_count_response.rb
368
377
  - lib/algolia/models/analytics/operator.rb
369
378
  - lib/algolia/models/analytics/order_by.rb
379
+ - lib/algolia/models/analytics/order_definition.rb
380
+ - lib/algolia/models/analytics/order_direction.rb
381
+ - lib/algolia/models/analytics/parameter_definition.rb
382
+ - lib/algolia/models/analytics/parameter_reference.rb
383
+ - lib/algolia/models/analytics/parameter_value.rb
384
+ - lib/algolia/models/analytics/scalar_payload.rb
385
+ - lib/algolia/models/analytics/series.rb
386
+ - lib/algolia/models/analytics/series_date.rb
387
+ - lib/algolia/models/analytics/table_payload.rb
388
+ - lib/algolia/models/analytics/table_response.rb
389
+ - lib/algolia/models/analytics/timeseries_payload.rb
390
+ - lib/algolia/models/analytics/timeseries_response.rb
370
391
  - lib/algolia/models/analytics/top_country.rb
371
392
  - lib/algolia/models/analytics/top_hit.rb
372
393
  - lib/algolia/models/analytics/top_hit_with_analytics.rb
@@ -665,6 +686,8 @@ files:
665
686
  - lib/algolia/models/insights/events_items.rb
666
687
  - lib/algolia/models/insights/events_response.rb
667
688
  - lib/algolia/models/insights/insights_events.rb
689
+ - lib/algolia/models/insights/instantsearch.rb
690
+ - lib/algolia/models/insights/instantsearch_event.rb
668
691
  - lib/algolia/models/insights/object_data.rb
669
692
  - lib/algolia/models/insights/object_data_after_search.rb
670
693
  - lib/algolia/models/insights/price.rb
@@ -987,6 +1010,7 @@ files:
987
1010
  - lib/algolia/transport/echo_requester.rb
988
1011
  - lib/algolia/transport/http/http_requester.rb
989
1012
  - lib/algolia/transport/http/response.rb
1013
+ - lib/algolia/transport/request_id.rb
990
1014
  - lib/algolia/transport/request_options.rb
991
1015
  - lib/algolia/transport/retry_outcome_type.rb
992
1016
  - lib/algolia/transport/retry_strategy.rb
@@ -1015,7 +1039,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1015
1039
  - !ruby/object:Gem::Version
1016
1040
  version: '0'
1017
1041
  requirements: []
1018
- rubygems_version: 4.0.10
1042
+ rubygems_version: 4.0.16
1019
1043
  specification_version: 4
1020
1044
  summary: A simple Ruby client for the algolia.com REST API
1021
1045
  test_files: []