algolia 3.0.0.beta.5 → 3.0.0.beta.7

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: 7841f068eb004a49c57459769fc18f10f98714b3229b63f4223839e9d3e15ea6
4
- data.tar.gz: 6f72cc44d5c858418ae7deed49ad2eaf86458fac3e08b2710e40207dd3f1b5ab
3
+ metadata.gz: 7cc326f3f421493311bb0c56147b9de597c87de115eb3923a0cf649aaba02c38
4
+ data.tar.gz: a7568b187d6b185503521786b2a8e80591b140e2a6109b0ff2a80f7cdbbf3eaa
5
5
  SHA512:
6
- metadata.gz: 91fe14b759af3f8d02e351294d97e447b98c71489820e819f9665fb25ce1d7a640c046ea4657fcc87435c5ed9f9c8688277774b5a6c5ace91804912b5a0d8d2d
7
- data.tar.gz: fa78f348f10ae77b918a52b14768bfd52dedc504710fed6133908015724f27904739552e54403d571f3123f19b8f73722d094eea5e1fe48fd80af615e4931c4f
6
+ metadata.gz: 2f2d6b16d9862a70444bce125e299eb0569c9d33b4b1734269ac47774f8ac67990d6aba65e1e00a9213253463a2fd28c53b0665d68a862f28fb25ab52176d077
7
+ data.tar.gz: 514f78082cd25d98bba2817d30463580f44db2ed616d725fc94c58ed25165b8eb6fd6d811575ec4767668b46fa98975305eddb537c7f814f6a08ffab7275fd43
@@ -24,4 +24,4 @@ jobs:
24
24
  ruby-version: 3.2.2
25
25
  bundler-cache: true
26
26
 
27
- - uses: rubygems/release-gem@v1
27
+ - uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [3.0.0.beta.7](https://github.com/algolia/algoliasearch-client-ruby/compare/3.0.0.beta.6...3.0.0.beta.7)
2
+
3
+ - [95e4c1e17](https://github.com/algolia/api-clients-automation/commit/95e4c1e17) chore(ruby): scope to last commit ([#3266](https://github.com/algolia/api-clients-automation/pull/3266)) by [@shortcuts](https://github.com/shortcuts/)
4
+ - [8e98407c1](https://github.com/algolia/api-clients-automation/commit/8e98407c1) fix(clients): update ingestion transformations description and fix taggroups ([#3265](https://github.com/algolia/api-clients-automation/pull/3265)) by [@shortcuts](https://github.com/shortcuts/)
5
+
6
+ ## [3.0.0.beta.6](https://github.com/algolia/algoliasearch-client-ruby/compare/3.0.0.beta.5...3.0.0.beta.6)
7
+
8
+ - [e5cfcf0c4](https://github.com/algolia/api-clients-automation/commit/e5cfcf0c4) feat(clients): generate common LICENSE ([#3258](https://github.com/algolia/api-clients-automation/pull/3258)) by [@shortcuts](https://github.com/shortcuts/)
9
+ - [47dd4bb5b](https://github.com/algolia/api-clients-automation/commit/47dd4bb5b) fix(clients): update README snippets and contributing guides ([#3257](https://github.com/algolia/api-clients-automation/pull/3257)) by [@shortcuts](https://github.com/shortcuts/)
10
+ - [7a90e4532](https://github.com/algolia/api-clients-automation/commit/7a90e4532) feat(clients): add `saveObjects`, `deleteObjects` and `partialUpdateObjects` helpers ([#3180](https://github.com/algolia/api-clients-automation/pull/3180)) by [@shortcuts](https://github.com/shortcuts/)
11
+ - [5dbdb91e9](https://github.com/algolia/api-clients-automation/commit/5dbdb91e9) fix(specs): virtual is a fetchedIndex props ([#3255](https://github.com/algolia/api-clients-automation/pull/3255)) by [@shortcuts](https://github.com/shortcuts/)
12
+ - [0a6277937](https://github.com/algolia/api-clients-automation/commit/0a6277937) fix(specs): add virtual index settings and update renderingContent ([#3254](https://github.com/algolia/api-clients-automation/pull/3254)) by [@shortcuts](https://github.com/shortcuts/)
13
+ - [536a348f1](https://github.com/algolia/api-clients-automation/commit/536a348f1) fix(clients): chunked batch helper size property consistency ([#3253](https://github.com/algolia/api-clients-automation/pull/3253)) by [@Fluf22](https://github.com/Fluf22/)
14
+
1
15
  ## [3.0.0.beta.5](https://github.com/algolia/algoliasearch-client-ruby/compare/3.0.0.beta.4...3.0.0.beta.5)
2
16
 
3
17
  - [b7ae19f2b](https://github.com/algolia/api-clients-automation/commit/b7ae19f2b) feat(specs): add transformations endpoints to ingestion ([#3215](https://github.com/algolia/api-clients-automation/pull/3215)) 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.5)
4
+ algolia (3.0.0.beta.7)
5
5
  faraday (>= 1.0.1, < 3.0)
6
6
  faraday-net_http_persistent (>= 0.15, < 3)
7
7
  net-http-persistent
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013-Present Algolia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -51,12 +51,12 @@ For full documentation, visit the **[Algolia Ruby API Client](https://www.algoli
51
51
 
52
52
  ## ❓ Troubleshooting
53
53
 
54
- Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/) where you will find answers for the most common issues and gotchas with the client.
54
+ Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/) where you will find answers for the most common issues and gotchas with the client. You can also open [a GitHub issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=&projects=&template=Bug_report.md)
55
55
 
56
- ## Upgrade from V1 to V2
56
+ ## Contributing
57
57
 
58
- If you were using the v1 and wish to update to v2, please follow our [Upgrade Guide](upgrade_guide.md)
58
+ This repository hosts the code of the generated Algolia API client for Ruby, if you'd like to contribute, head over to the [main repository](https://github.com/algolia/api-clients-automation). You can also find contributing guides on [our documentation website](https://api-clients-automation.netlify.app/docs/contributing/introduction).
59
59
 
60
60
  ## 📄 License
61
61
 
62
- Algolia Ruby API Client is an open-sourced software licensed under the [MIT license](LICENSE.md).
62
+ The Algolia Ruby API Client is an open-sourced software licensed under the [MIT license](LICENSE).
@@ -1934,7 +1934,7 @@ module Algolia
1934
1934
  @api_client.deserialize(response.body, request_options[:debug_return_type] || 'Ingestion::SourceWatchResponse')
1935
1935
  end
1936
1936
 
1937
- # Searches for transformations.
1937
+ # Try a transformation.
1938
1938
  #
1939
1939
  # Required API Key ACLs:
1940
1940
  # - addObject
@@ -1968,7 +1968,7 @@ module Algolia
1968
1968
  @api_client.call_api(:POST, path, new_options)
1969
1969
  end
1970
1970
 
1971
- # Searches for transformations.
1971
+ # Try a transformation.
1972
1972
  #
1973
1973
  # Required API Key ACLs:
1974
1974
  # - addObject
@@ -37,13 +37,13 @@ module Algolia
37
37
  #
38
38
  # Required API Key ACLs:
39
39
  # - editSettings
40
- # @param query_suggestions_configuration_with_index [QuerySuggestionsConfigurationWithIndex] (required)
40
+ # @param configuration_with_index [ConfigurationWithIndex] (required)
41
41
  # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
42
42
  # @return [Http::Response] the response
43
- def create_config_with_http_info(query_suggestions_configuration_with_index, request_options = {})
44
- # verify the required parameter 'query_suggestions_configuration_with_index' is set
45
- if @api_client.config.client_side_validation && query_suggestions_configuration_with_index.nil?
46
- raise ArgumentError, "Parameter `query_suggestions_configuration_with_index` is required when calling `create_config`."
43
+ def create_config_with_http_info(configuration_with_index, request_options = {})
44
+ # verify the required parameter 'configuration_with_index' is set
45
+ if @api_client.config.client_side_validation && configuration_with_index.nil?
46
+ raise ArgumentError, "Parameter `configuration_with_index` is required when calling `create_config`."
47
47
  end
48
48
 
49
49
  path = '/1/configs'
@@ -52,7 +52,7 @@ module Algolia
52
52
  header_params = {}
53
53
  header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?
54
54
 
55
- post_body = request_options[:debug_body] || @api_client.object_to_http_body(query_suggestions_configuration_with_index)
55
+ post_body = request_options[:debug_body] || @api_client.object_to_http_body(configuration_with_index)
56
56
 
57
57
  new_options = request_options.merge(
58
58
  :operation => :'QuerySuggestionsClient.create_config',
@@ -69,11 +69,11 @@ module Algolia
69
69
  #
70
70
  # Required API Key ACLs:
71
71
  # - editSettings
72
- # @param query_suggestions_configuration_with_index [QuerySuggestionsConfigurationWithIndex] (required)
72
+ # @param configuration_with_index [ConfigurationWithIndex] (required)
73
73
  # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
74
74
  # @return [BaseResponse]
75
- def create_config(query_suggestions_configuration_with_index, request_options = {})
76
- response = create_config_with_http_info(query_suggestions_configuration_with_index, request_options)
75
+ def create_config(configuration_with_index, request_options = {})
76
+ response = create_config_with_http_info(configuration_with_index, request_options)
77
77
  @api_client.deserialize(response.body, request_options[:debug_return_type] || 'QuerySuggestions::BaseResponse')
78
78
  end
79
79
 
@@ -328,10 +328,10 @@ module Algolia
328
328
  # Required API Key ACLs:
329
329
  # - settings
330
330
  # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
331
- # @return [Array<QuerySuggestionsConfigurationResponse>]
331
+ # @return [Array<ConfigurationResponse>]
332
332
  def get_all_configs(request_options = {})
333
333
  response = get_all_configs_with_http_info(request_options)
334
- @api_client.deserialize(response.body, request_options[:debug_return_type] || 'Array<QuerySuggestions::QuerySuggestionsConfigurationResponse>')
334
+ @api_client.deserialize(response.body, request_options[:debug_return_type] || 'Array<QuerySuggestions::ConfigurationResponse>')
335
335
  end
336
336
 
337
337
  # Retrieves a single Query Suggestions configuration by its index name.
@@ -372,10 +372,10 @@ module Algolia
372
372
  # - settings
373
373
  # @param index_name [String] Query Suggestions index name. (required)
374
374
  # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
375
- # @return [QuerySuggestionsConfigurationResponse]
375
+ # @return [ConfigurationResponse]
376
376
  def get_config(index_name, request_options = {})
377
377
  response = get_config_with_http_info(index_name, request_options)
378
- @api_client.deserialize(response.body, request_options[:debug_return_type] || 'QuerySuggestions::QuerySuggestionsConfigurationResponse')
378
+ @api_client.deserialize(response.body, request_options[:debug_return_type] || 'QuerySuggestions::ConfigurationResponse')
379
379
  end
380
380
 
381
381
  # Reports the status of a Query Suggestions index.
@@ -471,17 +471,17 @@ module Algolia
471
471
  # Required API Key ACLs:
472
472
  # - editSettings
473
473
  # @param index_name [String] Query Suggestions index name. (required)
474
- # @param query_suggestions_configuration [QuerySuggestionsConfiguration] (required)
474
+ # @param configuration [Configuration] (required)
475
475
  # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
476
476
  # @return [Http::Response] the response
477
- def update_config_with_http_info(index_name, query_suggestions_configuration, request_options = {})
477
+ def update_config_with_http_info(index_name, configuration, request_options = {})
478
478
  # verify the required parameter 'index_name' is set
479
479
  if @api_client.config.client_side_validation && index_name.nil?
480
480
  raise ArgumentError, "Parameter `index_name` is required when calling `update_config`."
481
481
  end
482
- # verify the required parameter 'query_suggestions_configuration' is set
483
- if @api_client.config.client_side_validation && query_suggestions_configuration.nil?
484
- raise ArgumentError, "Parameter `query_suggestions_configuration` is required when calling `update_config`."
482
+ # verify the required parameter 'configuration' is set
483
+ if @api_client.config.client_side_validation && configuration.nil?
484
+ raise ArgumentError, "Parameter `configuration` is required when calling `update_config`."
485
485
  end
486
486
 
487
487
  path = '/1/configs/{indexName}'.sub('{' + 'indexName' + '}', Transport.encode_uri(index_name.to_s))
@@ -490,7 +490,7 @@ module Algolia
490
490
  header_params = {}
491
491
  header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?
492
492
 
493
- post_body = request_options[:debug_body] || @api_client.object_to_http_body(query_suggestions_configuration)
493
+ post_body = request_options[:debug_body] || @api_client.object_to_http_body(configuration)
494
494
 
495
495
  new_options = request_options.merge(
496
496
  :operation => :'QuerySuggestionsClient.update_config',
@@ -508,11 +508,11 @@ module Algolia
508
508
  # Required API Key ACLs:
509
509
  # - editSettings
510
510
  # @param index_name [String] Query Suggestions index name. (required)
511
- # @param query_suggestions_configuration [QuerySuggestionsConfiguration] (required)
511
+ # @param configuration [Configuration] (required)
512
512
  # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
513
513
  # @return [BaseResponse]
514
- def update_config(index_name, query_suggestions_configuration, request_options = {})
515
- response = update_config_with_http_info(index_name, query_suggestions_configuration, request_options)
514
+ def update_config(index_name, configuration, request_options = {})
515
+ response = update_config_with_http_info(index_name, configuration, request_options)
516
516
  @api_client.deserialize(response.body, request_options[:debug_return_type] || 'QuerySuggestions::BaseResponse')
517
517
  end
518
518
  end
@@ -3178,6 +3178,64 @@ module Algolia
3178
3178
  valid_until - now
3179
3179
  end
3180
3180
 
3181
+ # 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.
3182
+ #
3183
+ # @param index_name [String]: The `index_name` to save `objects` in.
3184
+ # @param objects [Array]: The array of `objects` to store in the given Algolia `indexName`.
3185
+ # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3186
+ #
3187
+ # @return [BatchResponse]
3188
+ #
3189
+ def save_objects(index_name, objects, request_options = {})
3190
+ chunked_batch(
3191
+ index_name,
3192
+ objects,
3193
+ Search::Action::ADD_OBJECT,
3194
+ false,
3195
+ 1000,
3196
+ request_options
3197
+ )
3198
+ end
3199
+
3200
+ # Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
3201
+ #
3202
+ # @param index_name [String]: The `index_name` to delete `object_ids` from.
3203
+ # @param object_ids [Array]: The object_ids to delete.
3204
+ # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3205
+ #
3206
+ # @return [BatchResponse]
3207
+ #
3208
+ def delete_objects(index_name, object_ids, request_options = {})
3209
+ chunked_batch(
3210
+ index_name,
3211
+ object_ids.map { |id| { "objectID" => id } },
3212
+ Search::Action::DELETE_OBJECT,
3213
+ false,
3214
+ 1000,
3215
+ request_options
3216
+ )
3217
+ end
3218
+
3219
+ # Helper: Replaces object content of all the given objects according to their respective `object_id` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
3220
+ #
3221
+ # @param index_name [String]: The `index_name` to delete `object_ids` from.
3222
+ # @param objects [Array]: The objects to partially update.
3223
+ # @param create_if_not_exists [Boolean]: To be provided if non-existing objects are passed, otherwise, the call will fail.
3224
+ # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3225
+ #
3226
+ # @return [BatchResponse]
3227
+ #
3228
+ def partial_update_objects(index_name, objects, create_if_not_exists, request_options = {})
3229
+ chunked_batch(
3230
+ index_name,
3231
+ objects,
3232
+ create_if_not_exists ? Search::Action::PARTIAL_UPDATE_OBJECT : Search::Action::PARTIAL_UPDATE_OBJECT_NO_CREATE,
3233
+ false,
3234
+ 1000,
3235
+ request_options
3236
+ )
3237
+ end
3238
+
3181
3239
  # Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
3182
3240
  #
3183
3241
  # @param index_name [String] the `index_name` where the operation will be performed.
@@ -0,0 +1,258 @@
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
+
3
+ require 'date'
4
+ require 'time'
5
+
6
+ module Algolia
7
+ module QuerySuggestions
8
+ # Query Suggestions configuration.
9
+ class Configuration
10
+ # Algolia indices from which to get the popular searches for query suggestions.
11
+ attr_accessor :source_indices
12
+
13
+ attr_accessor :languages
14
+
15
+ attr_accessor :exclude
16
+
17
+ # Whether to turn on personalized query suggestions.
18
+ attr_accessor :enable_personalization
19
+
20
+ # Whether to include suggestions with special characters.
21
+ attr_accessor :allow_special_characters
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :source_indices => :sourceIndices,
27
+ :languages => :languages,
28
+ :exclude => :exclude,
29
+ :enable_personalization => :enablePersonalization,
30
+ :allow_special_characters => :allowSpecialCharacters
31
+ }
32
+ end
33
+
34
+ # Returns all the JSON keys this model knows about
35
+ def self.acceptable_attributes
36
+ attribute_map.values
37
+ end
38
+
39
+ # Attribute type mapping.
40
+ def self.types_mapping
41
+ {
42
+ :source_indices => :'Array<SourceIndex>',
43
+ :languages => :Languages,
44
+ :exclude => :'Array<String>',
45
+ :enable_personalization => :Boolean,
46
+ :allow_special_characters => :Boolean
47
+ }
48
+ end
49
+
50
+ # List of attributes with nullable: true
51
+ def self.openapi_nullable
52
+ Set.new([
53
+ :exclude
54
+ ])
55
+ end
56
+
57
+ # Initializes the object
58
+ # @param [Hash] attributes Model attributes in the form of hash
59
+ def initialize(attributes = {})
60
+ unless attributes.is_a?(Hash)
61
+ raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Configuration` initialize method"
62
+ end
63
+
64
+ # check to see if the attribute exists and convert string to symbol for hash key
65
+ attributes = attributes.each_with_object({}) do |(k, v), h|
66
+ unless self.class.attribute_map.key?(k.to_sym)
67
+ raise ArgumentError,
68
+ "`#{k}` is not a valid attribute in `Algolia::Configuration`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
69
+ end
70
+
71
+ h[k.to_sym] = v
72
+ end
73
+
74
+ if attributes.key?(:source_indices)
75
+ if (value = attributes[:source_indices]).is_a?(Array)
76
+ self.source_indices = value
77
+ end
78
+ else
79
+ self.source_indices = nil
80
+ end
81
+
82
+ if attributes.key?(:languages)
83
+ self.languages = attributes[:languages]
84
+ end
85
+
86
+ if attributes.key?(:exclude)
87
+ if (value = attributes[:exclude]).is_a?(Array)
88
+ self.exclude = value
89
+ end
90
+ end
91
+
92
+ if attributes.key?(:enable_personalization)
93
+ self.enable_personalization = attributes[:enable_personalization]
94
+ end
95
+
96
+ if attributes.key?(:allow_special_characters)
97
+ self.allow_special_characters = attributes[:allow_special_characters]
98
+ end
99
+ end
100
+
101
+ # Custom attribute writer method with validation
102
+ # @param [Object] source_indices Value to be assigned
103
+ def source_indices=(source_indices)
104
+ if source_indices.nil?
105
+ raise ArgumentError, 'source_indices cannot be nil'
106
+ end
107
+
108
+ if source_indices.length < 1
109
+ raise ArgumentError, 'invalid value for "source_indices", number of items must be greater than or equal to 1.'
110
+ end
111
+
112
+ @source_indices = source_indices
113
+ end
114
+
115
+ # Checks equality by comparing each attribute.
116
+ # @param [Object] Object to be compared
117
+ def ==(other)
118
+ return true if equal?(other)
119
+
120
+ self.class == other.class &&
121
+ source_indices == other.source_indices &&
122
+ languages == other.languages &&
123
+ exclude == other.exclude &&
124
+ enable_personalization == other.enable_personalization &&
125
+ allow_special_characters == other.allow_special_characters
126
+ end
127
+
128
+ # @see the `==` method
129
+ # @param [Object] Object to be compared
130
+ def eql?(other)
131
+ self == other
132
+ end
133
+
134
+ # Calculates hash code according to all attributes.
135
+ # @return [Integer] Hash code
136
+ def hash
137
+ [source_indices, languages, exclude, enable_personalization, allow_special_characters].hash
138
+ end
139
+
140
+ # Builds the object from hash
141
+ # @param [Hash] attributes Model attributes in the form of hash
142
+ # @return [Object] Returns the model itself
143
+ def self.build_from_hash(attributes)
144
+ return nil unless attributes.is_a?(Hash)
145
+
146
+ attributes = attributes.transform_keys(&:to_sym)
147
+ transformed_hash = {}
148
+ types_mapping.each_pair do |key, type|
149
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
150
+ transformed_hash[key.to_sym] = nil
151
+ elsif type =~ /\AArray<(.*)>/i
152
+ # check to ensure the input is an array given that the attribute
153
+ # is documented as an array but the input is not
154
+ if attributes[attribute_map[key]].is_a?(Array)
155
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
156
+ end
157
+ elsif !attributes[attribute_map[key]].nil?
158
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
159
+ end
160
+ end
161
+ new(transformed_hash)
162
+ end
163
+
164
+ # Deserializes the data based on type
165
+ # @param string type Data type
166
+ # @param string value Value to be deserialized
167
+ # @return [Object] Deserialized data
168
+ def self._deserialize(type, value)
169
+ case type.to_sym
170
+ when :Time
171
+ Time.parse(value)
172
+ when :Date
173
+ Date.parse(value)
174
+ when :String
175
+ value.to_s
176
+ when :Integer
177
+ value.to_i
178
+ when :Float
179
+ value.to_f
180
+ when :Boolean
181
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
182
+ true
183
+ else
184
+ false
185
+ end
186
+ when :Object
187
+ # generic object (usually a Hash), return directly
188
+ value
189
+ when /\AArray<(?<inner_type>.+)>\z/
190
+ inner_type = Regexp.last_match[:inner_type]
191
+ value.map { |v| _deserialize(inner_type, v) }
192
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
193
+ k_type = Regexp.last_match[:k_type]
194
+ v_type = Regexp.last_match[:v_type]
195
+ {}.tap do |hash|
196
+ value.each do |k, v|
197
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
198
+ end
199
+ end
200
+ else # model
201
+ # models (e.g. Pet) or oneOf
202
+ klass = Algolia::QuerySuggestions.const_get(type)
203
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
204
+ end
205
+ end
206
+
207
+ # Returns the string representation of the object
208
+ # @return [String] String presentation of the object
209
+ def to_s
210
+ to_hash.to_s
211
+ end
212
+
213
+ # to_body is an alias to to_hash (backward compatibility)
214
+ # @return [Hash] Returns the object in the form of hash
215
+ def to_body
216
+ to_hash
217
+ end
218
+
219
+ def to_json(*_args)
220
+ to_hash.to_json
221
+ end
222
+
223
+ # Returns the object in the form of hash
224
+ # @return [Hash] Returns the object in the form of hash
225
+ def to_hash
226
+ hash = {}
227
+ self.class.attribute_map.each_pair do |attr, param|
228
+ value = send(attr)
229
+ if value.nil?
230
+ is_nullable = self.class.openapi_nullable.include?(attr)
231
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
232
+ end
233
+
234
+ hash[param] = _to_hash(value)
235
+ end
236
+ hash
237
+ end
238
+
239
+ # Outputs non-array value in the form of hash
240
+ # For object, use to_hash. Otherwise, just return the value
241
+ # @param [Object] value Any valid value
242
+ # @return [Hash] Returns the value in the form of hash
243
+ def _to_hash(value)
244
+ if value.is_a?(Array)
245
+ value.compact.map { |v| _to_hash(v) }
246
+ elsif value.is_a?(Hash)
247
+ {}.tap do |hash|
248
+ value.each { |k, v| hash[k] = _to_hash(v) }
249
+ end
250
+ elsif value.respond_to? :to_hash
251
+ value.to_hash
252
+ else
253
+ value
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end