algolia 3.0.0.beta.9 → 3.0.0.beta.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +4 -2
- data/lib/algolia/api/ingestion_client.rb +912 -359
- data/lib/algolia/api/search_client.rb +17 -17
- data/lib/algolia/error.rb +10 -0
- data/lib/algolia/logger_helper.rb +11 -2
- data/lib/algolia/models/ingestion/action.rb +45 -0
- data/lib/algolia/models/ingestion/batch_request.rb +247 -0
- data/lib/algolia/models/ingestion/batch_write_params.rb +216 -0
- data/lib/algolia/models/ingestion/list_tasks_response_v1.rb +227 -0
- data/lib/algolia/models/ingestion/source_shopify.rb +10 -77
- data/lib/algolia/models/ingestion/source_update_shopify.rb +10 -76
- data/lib/algolia/models/ingestion/task.rb +30 -9
- data/lib/algolia/models/ingestion/task_create.rb +11 -12
- data/lib/algolia/models/ingestion/task_create_v1.rb +328 -0
- data/lib/algolia/models/ingestion/task_update.rb +8 -7
- data/lib/algolia/models/ingestion/task_update_v1.rb +269 -0
- data/lib/algolia/models/ingestion/task_v1.rb +373 -0
- data/lib/algolia/models/recommend/get_recommendations_response.rb +2 -0
- data/lib/algolia/models/recommend/trending_items.rb +0 -4
- data/lib/algolia/models/recommend/trending_items_query.rb +0 -4
- data/lib/algolia/models/search/settings_response.rb +1028 -0
- data/lib/algolia/models/search/with_primary.rb +212 -0
- data/lib/algolia/transport/transport.rb +9 -3
- data/lib/algolia/version.rb +1 -1
- metadata +11 -2
@@ -1529,10 +1529,10 @@ module Algolia
|
|
1529
1529
|
# - search
|
1530
1530
|
# @param index_name [String] Name of the index on which to perform the operation. (required)
|
1531
1531
|
# @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)
|
1532
|
-
# @return [
|
1532
|
+
# @return [SettingsResponse]
|
1533
1533
|
def get_settings(index_name, request_options = {})
|
1534
1534
|
response = get_settings_with_http_info(index_name, request_options)
|
1535
|
-
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Search::
|
1535
|
+
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Search::SettingsResponse")
|
1536
1536
|
end
|
1537
1537
|
|
1538
1538
|
# Retrieves all allowed IP addresses with access to your application.
|
@@ -3179,16 +3179,16 @@ module Algolia
|
|
3179
3179
|
|
3180
3180
|
# Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
|
3181
3181
|
#
|
3182
|
-
# @param operation [String] the `operation` that was done on a `key`.
|
3183
3182
|
# @param key [String] the `key` that has been added, deleted or updated.
|
3183
|
+
# @param operation [String] the `operation` that was done on a `key`.
|
3184
3184
|
# @param api_key [Hash] necessary to know if an `update` operation has been processed, compare fields of the response with it.
|
3185
3185
|
# @param max_retries [Integer] the maximum number of retries.
|
3186
3186
|
# @param timeout [Proc] the function to decide how long to wait between retries.
|
3187
3187
|
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
|
3188
3188
|
# @return [Http::Response] the last get_api_key response
|
3189
3189
|
def wait_for_api_key(
|
3190
|
-
operation,
|
3191
3190
|
key,
|
3191
|
+
operation,
|
3192
3192
|
api_key = {},
|
3193
3193
|
max_retries = 50,
|
3194
3194
|
timeout = -> (retry_count) { [retry_count * 200, 5000].min },
|
@@ -3198,19 +3198,15 @@ module Algolia
|
|
3198
3198
|
if operation == "update"
|
3199
3199
|
raise ArgumentError, "`api_key` is required when waiting for an `update` operation." if api_key.nil?
|
3200
3200
|
while retries < max_retries
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3204
|
-
|
3205
|
-
|
3206
|
-
equals &&= updated_key_hash[k] == v
|
3207
|
-
end
|
3208
|
-
|
3209
|
-
return updatad_key if equals
|
3210
|
-
rescue AlgoliaError => e
|
3211
|
-
raise e unless e.code == 404
|
3201
|
+
updated_key = get_api_key(key, request_options)
|
3202
|
+
updated_key_hash = updated_key.to_hash
|
3203
|
+
equals = true
|
3204
|
+
api_key.to_hash.each do |k, v|
|
3205
|
+
equals &&= updated_key_hash[k] == v
|
3212
3206
|
end
|
3213
3207
|
|
3208
|
+
return updated_key if equals
|
3209
|
+
|
3214
3210
|
retries += 1
|
3215
3211
|
sleep(timeout.call(retries) / 1000.0)
|
3216
3212
|
end
|
@@ -3222,8 +3218,12 @@ module Algolia
|
|
3222
3218
|
begin
|
3223
3219
|
res = get_api_key(key, request_options)
|
3224
3220
|
return res if operation == "add"
|
3225
|
-
rescue
|
3226
|
-
|
3221
|
+
rescue AlgoliaHttpError => e
|
3222
|
+
if e.code == 404
|
3223
|
+
return nil if operation == "delete"
|
3224
|
+
else
|
3225
|
+
raise e
|
3226
|
+
end
|
3227
3227
|
end
|
3228
3228
|
|
3229
3229
|
retries += 1
|
data/lib/algolia/error.rb
CHANGED
@@ -10,6 +10,16 @@ module Algolia
|
|
10
10
|
# Used when hosts are unreachable
|
11
11
|
#
|
12
12
|
class AlgoliaUnreachableHostError < AlgoliaError
|
13
|
+
attr_reader :errors
|
14
|
+
|
15
|
+
def initialize(message, errors = [])
|
16
|
+
errors.last&.tap do |last_error|
|
17
|
+
message += " Last error for #{last_error[:host]}: #{last_error[:error]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
super(message)
|
21
|
+
@errors = errors
|
22
|
+
end
|
13
23
|
end
|
14
24
|
|
15
25
|
# An exception class raised when the REST API returns an error.
|
@@ -5,8 +5,17 @@ module Algolia
|
|
5
5
|
# @param debug_file [nil|String] file used to output the logs
|
6
6
|
#
|
7
7
|
def self.create(debug_file = nil)
|
8
|
-
file = debug_file
|
9
|
-
|
8
|
+
file = debug_file
|
9
|
+
|
10
|
+
if file.nil? && ENV["ALGOLIA_DEBUG"]
|
11
|
+
begin
|
12
|
+
file = File.new("debug.log", "a+")
|
13
|
+
rescue Errno::EACCES, Errno::ENOENT => e
|
14
|
+
puts("Failed to open debug.log: #{e.message}. Falling back to $stderr.")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
instance = ::Logger.new(file || $stderr)
|
10
19
|
instance.progname = "algolia"
|
11
20
|
instance
|
12
21
|
end
|
@@ -0,0 +1,45 @@
|
|
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 Ingestion
|
8
|
+
class Action
|
9
|
+
ADD_OBJECT = "addObject".freeze
|
10
|
+
UPDATE_OBJECT = "updateObject".freeze
|
11
|
+
PARTIAL_UPDATE_OBJECT = "partialUpdateObject".freeze
|
12
|
+
PARTIAL_UPDATE_OBJECT_NO_CREATE = "partialUpdateObjectNoCreate".freeze
|
13
|
+
DELETE_OBJECT = "deleteObject".freeze
|
14
|
+
DELETE = "delete".freeze
|
15
|
+
CLEAR = "clear".freeze
|
16
|
+
|
17
|
+
def self.all_vars
|
18
|
+
@all_vars ||= [
|
19
|
+
ADD_OBJECT,
|
20
|
+
UPDATE_OBJECT,
|
21
|
+
PARTIAL_UPDATE_OBJECT,
|
22
|
+
PARTIAL_UPDATE_OBJECT_NO_CREATE,
|
23
|
+
DELETE_OBJECT,
|
24
|
+
DELETE,
|
25
|
+
CLEAR
|
26
|
+
].freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
# Builds the enum from string
|
30
|
+
# @param [String] The enum value in the form of the string
|
31
|
+
# @return [String] The enum value
|
32
|
+
def self.build_from_hash(value)
|
33
|
+
new.build_from_hash(value)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Builds the enum from string
|
37
|
+
# @param [String] The enum value in the form of the string
|
38
|
+
# @return [String] The enum value
|
39
|
+
def build_from_hash(value)
|
40
|
+
return value if Action.all_vars.include?(value)
|
41
|
+
raise "Invalid ENUM value #{value} for class #Action"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,247 @@
|
|
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 Ingestion
|
8
|
+
class BatchRequest
|
9
|
+
attr_accessor :action
|
10
|
+
|
11
|
+
# Operation arguments (varies with specified `action`).
|
12
|
+
attr_accessor :body
|
13
|
+
|
14
|
+
class EnumAttributeValidator
|
15
|
+
attr_reader :datatype
|
16
|
+
attr_reader :allowable_values
|
17
|
+
|
18
|
+
def initialize(datatype, allowable_values)
|
19
|
+
@allowable_values = allowable_values.map do |value|
|
20
|
+
case datatype.to_s
|
21
|
+
when /Integer/i
|
22
|
+
value.to_i
|
23
|
+
when /Float/i
|
24
|
+
value.to_f
|
25
|
+
else
|
26
|
+
value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid?(value)
|
32
|
+
!value || allowable_values.include?(value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
37
|
+
def self.attribute_map
|
38
|
+
{
|
39
|
+
:action => :action,
|
40
|
+
:body => :body
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns all the JSON keys this model knows about
|
45
|
+
def self.acceptable_attributes
|
46
|
+
attribute_map.values
|
47
|
+
end
|
48
|
+
|
49
|
+
# Attribute type mapping.
|
50
|
+
def self.types_mapping
|
51
|
+
{
|
52
|
+
:action => :"Action",
|
53
|
+
:body => :"Object"
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
# List of attributes with nullable: true
|
58
|
+
def self.openapi_nullable
|
59
|
+
Set.new(
|
60
|
+
[]
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Initializes the object
|
65
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
66
|
+
def initialize(attributes = {})
|
67
|
+
if (!attributes.is_a?(Hash))
|
68
|
+
raise(
|
69
|
+
ArgumentError,
|
70
|
+
"The input argument (attributes) must be a hash in `Algolia::BatchRequest` initialize method"
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
75
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
76
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
77
|
+
raise(
|
78
|
+
ArgumentError,
|
79
|
+
"`#{k}` is not a valid attribute in `Algolia::BatchRequest`. Please check the name to make sure it's valid. List of attributes: " +
|
80
|
+
self.class.attribute_map.keys.inspect
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
h[k.to_sym] = v
|
85
|
+
}
|
86
|
+
|
87
|
+
if attributes.key?(:action)
|
88
|
+
self.action = attributes[:action]
|
89
|
+
else
|
90
|
+
self.action = nil
|
91
|
+
end
|
92
|
+
|
93
|
+
if attributes.key?(:body)
|
94
|
+
self.body = attributes[:body]
|
95
|
+
else
|
96
|
+
self.body = nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Checks equality by comparing each attribute.
|
101
|
+
# @param [Object] Object to be compared
|
102
|
+
def ==(other)
|
103
|
+
return true if self.equal?(other)
|
104
|
+
self.class == other.class &&
|
105
|
+
action == other.action &&
|
106
|
+
body == other.body
|
107
|
+
end
|
108
|
+
|
109
|
+
# @see the `==` method
|
110
|
+
# @param [Object] Object to be compared
|
111
|
+
def eql?(other)
|
112
|
+
self == other
|
113
|
+
end
|
114
|
+
|
115
|
+
# Calculates hash code according to all attributes.
|
116
|
+
# @return [Integer] Hash code
|
117
|
+
def hash
|
118
|
+
[action, body].hash
|
119
|
+
end
|
120
|
+
|
121
|
+
# Builds the object from hash
|
122
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
123
|
+
# @return [Object] Returns the model itself
|
124
|
+
def self.build_from_hash(attributes)
|
125
|
+
return nil unless attributes.is_a?(Hash)
|
126
|
+
attributes = attributes.transform_keys(&:to_sym)
|
127
|
+
transformed_hash = {}
|
128
|
+
types_mapping.each_pair do |key, type|
|
129
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
130
|
+
transformed_hash[key.to_sym] = nil
|
131
|
+
elsif type =~ /\AArray<(.*)>/i
|
132
|
+
# check to ensure the input is an array given that the attribute
|
133
|
+
# is documented as an array but the input is not
|
134
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
135
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
136
|
+
_deserialize(::Regexp.last_match(1), v)
|
137
|
+
}
|
138
|
+
end
|
139
|
+
elsif !attributes[attribute_map[key]].nil?
|
140
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
new(transformed_hash)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Deserializes the data based on type
|
148
|
+
# @param string type Data type
|
149
|
+
# @param string value Value to be deserialized
|
150
|
+
# @return [Object] Deserialized data
|
151
|
+
def self._deserialize(type, value)
|
152
|
+
case type.to_sym
|
153
|
+
when :Time
|
154
|
+
Time.parse(value)
|
155
|
+
when :Date
|
156
|
+
Date.parse(value)
|
157
|
+
when :String
|
158
|
+
value.to_s
|
159
|
+
when :Integer
|
160
|
+
value.to_i
|
161
|
+
when :Float
|
162
|
+
value.to_f
|
163
|
+
when :Boolean
|
164
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
165
|
+
true
|
166
|
+
else
|
167
|
+
false
|
168
|
+
end
|
169
|
+
|
170
|
+
when :Object
|
171
|
+
# generic object (usually a Hash), return directly
|
172
|
+
value
|
173
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
174
|
+
inner_type = Regexp.last_match[:inner_type]
|
175
|
+
value.map { |v| _deserialize(inner_type, v) }
|
176
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
177
|
+
k_type = Regexp.last_match[:k_type]
|
178
|
+
v_type = Regexp.last_match[:v_type]
|
179
|
+
{}.tap do |hash|
|
180
|
+
value.each do |k, v|
|
181
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
# model
|
185
|
+
else
|
186
|
+
# models (e.g. Pet) or oneOf
|
187
|
+
klass = Algolia::Ingestion.const_get(type)
|
188
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
189
|
+
.build_from_hash(value)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns the string representation of the object
|
194
|
+
# @return [String] String presentation of the object
|
195
|
+
def to_s
|
196
|
+
to_hash.to_s
|
197
|
+
end
|
198
|
+
|
199
|
+
# to_body is an alias to to_hash (backward compatibility)
|
200
|
+
# @return [Hash] Returns the object in the form of hash
|
201
|
+
def to_body
|
202
|
+
to_hash
|
203
|
+
end
|
204
|
+
|
205
|
+
def to_json(*_args)
|
206
|
+
to_hash.to_json
|
207
|
+
end
|
208
|
+
|
209
|
+
# Returns the object in the form of hash
|
210
|
+
# @return [Hash] Returns the object in the form of hash
|
211
|
+
def to_hash
|
212
|
+
hash = {}
|
213
|
+
self.class.attribute_map.each_pair do |attr, param|
|
214
|
+
value = send(attr)
|
215
|
+
if value.nil?
|
216
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
217
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
218
|
+
end
|
219
|
+
|
220
|
+
hash[param] = _to_hash(value)
|
221
|
+
end
|
222
|
+
|
223
|
+
hash
|
224
|
+
end
|
225
|
+
|
226
|
+
# Outputs non-array value in the form of hash
|
227
|
+
# For object, use to_hash. Otherwise, just return the value
|
228
|
+
# @param [Object] value Any valid value
|
229
|
+
# @return [Hash] Returns the value in the form of hash
|
230
|
+
def _to_hash(value)
|
231
|
+
if value.is_a?(Array)
|
232
|
+
value.compact.map { |v| _to_hash(v) }
|
233
|
+
elsif value.is_a?(Hash)
|
234
|
+
{}.tap do |hash|
|
235
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
236
|
+
end
|
237
|
+
elsif value.respond_to?(:to_hash)
|
238
|
+
value.to_hash
|
239
|
+
else
|
240
|
+
value
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,216 @@
|
|
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 Ingestion
|
8
|
+
# Batch parameters.
|
9
|
+
class BatchWriteParams
|
10
|
+
attr_accessor :requests
|
11
|
+
|
12
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
13
|
+
def self.attribute_map
|
14
|
+
{
|
15
|
+
:requests => :requests
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns all the JSON keys this model knows about
|
20
|
+
def self.acceptable_attributes
|
21
|
+
attribute_map.values
|
22
|
+
end
|
23
|
+
|
24
|
+
# Attribute type mapping.
|
25
|
+
def self.types_mapping
|
26
|
+
{
|
27
|
+
:requests => :"Array<BatchRequest>"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# List of attributes with nullable: true
|
32
|
+
def self.openapi_nullable
|
33
|
+
Set.new(
|
34
|
+
[]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Initializes the object
|
39
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
40
|
+
def initialize(attributes = {})
|
41
|
+
if (!attributes.is_a?(Hash))
|
42
|
+
raise(
|
43
|
+
ArgumentError,
|
44
|
+
"The input argument (attributes) must be a hash in `Algolia::BatchWriteParams` initialize method"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
49
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
50
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
51
|
+
raise(
|
52
|
+
ArgumentError,
|
53
|
+
"`#{k}` is not a valid attribute in `Algolia::BatchWriteParams`. Please check the name to make sure it's valid. List of attributes: " +
|
54
|
+
self.class.attribute_map.keys.inspect
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
h[k.to_sym] = v
|
59
|
+
}
|
60
|
+
|
61
|
+
if attributes.key?(:requests)
|
62
|
+
if (value = attributes[:requests]).is_a?(Array)
|
63
|
+
self.requests = value
|
64
|
+
end
|
65
|
+
else
|
66
|
+
self.requests = nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Checks equality by comparing each attribute.
|
71
|
+
# @param [Object] Object to be compared
|
72
|
+
def ==(other)
|
73
|
+
return true if self.equal?(other)
|
74
|
+
self.class == other.class &&
|
75
|
+
requests == other.requests
|
76
|
+
end
|
77
|
+
|
78
|
+
# @see the `==` method
|
79
|
+
# @param [Object] Object to be compared
|
80
|
+
def eql?(other)
|
81
|
+
self == other
|
82
|
+
end
|
83
|
+
|
84
|
+
# Calculates hash code according to all attributes.
|
85
|
+
# @return [Integer] Hash code
|
86
|
+
def hash
|
87
|
+
[requests].hash
|
88
|
+
end
|
89
|
+
|
90
|
+
# Builds the object from hash
|
91
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
92
|
+
# @return [Object] Returns the model itself
|
93
|
+
def self.build_from_hash(attributes)
|
94
|
+
return nil unless attributes.is_a?(Hash)
|
95
|
+
attributes = attributes.transform_keys(&:to_sym)
|
96
|
+
transformed_hash = {}
|
97
|
+
types_mapping.each_pair do |key, type|
|
98
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
99
|
+
transformed_hash[key.to_sym] = nil
|
100
|
+
elsif type =~ /\AArray<(.*)>/i
|
101
|
+
# check to ensure the input is an array given that the attribute
|
102
|
+
# is documented as an array but the input is not
|
103
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
104
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
105
|
+
_deserialize(::Regexp.last_match(1), v)
|
106
|
+
}
|
107
|
+
end
|
108
|
+
elsif !attributes[attribute_map[key]].nil?
|
109
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
new(transformed_hash)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Deserializes the data based on type
|
117
|
+
# @param string type Data type
|
118
|
+
# @param string value Value to be deserialized
|
119
|
+
# @return [Object] Deserialized data
|
120
|
+
def self._deserialize(type, value)
|
121
|
+
case type.to_sym
|
122
|
+
when :Time
|
123
|
+
Time.parse(value)
|
124
|
+
when :Date
|
125
|
+
Date.parse(value)
|
126
|
+
when :String
|
127
|
+
value.to_s
|
128
|
+
when :Integer
|
129
|
+
value.to_i
|
130
|
+
when :Float
|
131
|
+
value.to_f
|
132
|
+
when :Boolean
|
133
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
134
|
+
true
|
135
|
+
else
|
136
|
+
false
|
137
|
+
end
|
138
|
+
|
139
|
+
when :Object
|
140
|
+
# generic object (usually a Hash), return directly
|
141
|
+
value
|
142
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
143
|
+
inner_type = Regexp.last_match[:inner_type]
|
144
|
+
value.map { |v| _deserialize(inner_type, v) }
|
145
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
146
|
+
k_type = Regexp.last_match[:k_type]
|
147
|
+
v_type = Regexp.last_match[:v_type]
|
148
|
+
{}.tap do |hash|
|
149
|
+
value.each do |k, v|
|
150
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
# model
|
154
|
+
else
|
155
|
+
# models (e.g. Pet) or oneOf
|
156
|
+
klass = Algolia::Ingestion.const_get(type)
|
157
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
158
|
+
.build_from_hash(value)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns the string representation of the object
|
163
|
+
# @return [String] String presentation of the object
|
164
|
+
def to_s
|
165
|
+
to_hash.to_s
|
166
|
+
end
|
167
|
+
|
168
|
+
# to_body is an alias to to_hash (backward compatibility)
|
169
|
+
# @return [Hash] Returns the object in the form of hash
|
170
|
+
def to_body
|
171
|
+
to_hash
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_json(*_args)
|
175
|
+
to_hash.to_json
|
176
|
+
end
|
177
|
+
|
178
|
+
# Returns the object in the form of hash
|
179
|
+
# @return [Hash] Returns the object in the form of hash
|
180
|
+
def to_hash
|
181
|
+
hash = {}
|
182
|
+
self.class.attribute_map.each_pair do |attr, param|
|
183
|
+
value = send(attr)
|
184
|
+
if value.nil?
|
185
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
186
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
187
|
+
end
|
188
|
+
|
189
|
+
hash[param] = _to_hash(value)
|
190
|
+
end
|
191
|
+
|
192
|
+
hash
|
193
|
+
end
|
194
|
+
|
195
|
+
# Outputs non-array value in the form of hash
|
196
|
+
# For object, use to_hash. Otherwise, just return the value
|
197
|
+
# @param [Object] value Any valid value
|
198
|
+
# @return [Hash] Returns the value in the form of hash
|
199
|
+
def _to_hash(value)
|
200
|
+
if value.is_a?(Array)
|
201
|
+
value.compact.map { |v| _to_hash(v) }
|
202
|
+
elsif value.is_a?(Hash)
|
203
|
+
{}.tap do |hash|
|
204
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
205
|
+
end
|
206
|
+
elsif value.respond_to?(:to_hash)
|
207
|
+
value.to_hash
|
208
|
+
else
|
209
|
+
value
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
end
|