algolia 3.25.0 → 3.26.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.
- checksums.yaml +4 -4
- data/.github/workflows/issue.yml +1 -1
- data/.github/workflows/release.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/lib/algolia/api/composition_client.rb +765 -0
- data/lib/algolia/api/ingestion_client.rb +15 -4
- data/lib/algolia/api/search_client.rb +4 -2
- data/lib/algolia/models/composition/action.rb +34 -0
- data/lib/algolia/models/composition/advanced_syntax_features.rb +34 -0
- data/lib/algolia/models/composition/alternatives_as_exact.rb +36 -0
- data/lib/algolia/models/composition/anchoring.rb +36 -0
- data/lib/algolia/models/composition/base_injection_query_parameters.rb +732 -0
- data/lib/algolia/models/composition/batch_composition_action.rb +109 -0
- data/lib/algolia/models/composition/batch_params.rb +213 -0
- data/lib/algolia/models/composition/boolean_string.rb +34 -0
- data/lib/algolia/models/composition/composition.rb +244 -0
- data/lib/algolia/models/composition/composition_behavior.rb +210 -0
- data/lib/algolia/models/composition/composition_rule.rb +280 -0
- data/lib/algolia/models/composition/composition_rule_consequence.rb +211 -0
- data/lib/algolia/models/composition/composition_rules_batch_params.rb +211 -0
- data/lib/algolia/models/composition/composition_source.rb +210 -0
- data/lib/algolia/models/composition/composition_source_search.rb +220 -0
- data/lib/algolia/models/composition/condition.rb +238 -0
- data/lib/algolia/models/composition/delete_composition_action.rb +212 -0
- data/lib/algolia/models/composition/delete_composition_rule_action.rb +212 -0
- data/lib/algolia/models/composition/distinct.rb +110 -0
- data/lib/algolia/models/composition/exact_on_single_word_query.rb +35 -0
- data/lib/algolia/models/composition/external.rb +226 -0
- data/lib/algolia/models/composition/external_ordering.rb +34 -0
- data/lib/algolia/models/composition/external_source.rb +211 -0
- data/lib/algolia/models/composition/get_task_response.rb +210 -0
- data/lib/algolia/models/composition/ignore_plurals.rb +111 -0
- data/lib/algolia/models/composition/injected_item.rb +253 -0
- data/lib/algolia/models/composition/injected_item_hits_metadata.rb +222 -0
- data/lib/algolia/models/composition/injected_item_metadata.rb +209 -0
- data/lib/algolia/models/composition/injected_item_source.rb +109 -0
- data/lib/algolia/models/composition/injection.rb +222 -0
- data/lib/algolia/models/composition/list_compositions_response.rb +261 -0
- data/lib/algolia/models/composition/main.rb +207 -0
- data/lib/algolia/models/composition/main_injection_query_parameters.rb +807 -0
- data/lib/algolia/models/composition/multiple_batch_request.rb +221 -0
- data/lib/algolia/models/composition/multiple_batch_response.rb +213 -0
- data/lib/algolia/models/composition/optional_words.rb +110 -0
- data/lib/algolia/models/composition/query_type.rb +35 -0
- data/lib/algolia/models/composition/remove_stop_words.rb +110 -0
- data/lib/algolia/models/composition/remove_words_if_no_results.rb +36 -0
- data/lib/algolia/models/composition/rules_batch_composition_action.rb +109 -0
- data/lib/algolia/models/composition/rules_multiple_batch_request.rb +221 -0
- data/lib/algolia/models/composition/rules_multiple_batch_response.rb +211 -0
- data/lib/algolia/models/composition/search.rb +217 -0
- data/lib/algolia/models/composition/search_composition_rules_params.rb +261 -0
- data/lib/algolia/models/composition/search_composition_rules_response.rb +249 -0
- data/lib/algolia/models/composition/search_source.rb +211 -0
- data/lib/algolia/models/composition/task_id_response.rb +211 -0
- data/lib/algolia/models/composition/task_status.rb +34 -0
- data/lib/algolia/models/composition/time_range.rb +219 -0
- data/lib/algolia/models/composition/typo_tolerance.rb +110 -0
- data/lib/algolia/models/composition/typo_tolerance_enum.rb +36 -0
- data/lib/algolia/version.rb +1 -1
- metadata +52 -1
@@ -0,0 +1,110 @@
|
|
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 Composition
|
10
|
+
# Determines how many records of a group are included in the search results. Records with the same value for the `attributeForDistinct` attribute are considered a group. The `distinct` setting controls how many members of the group are returned. This is useful for [deduplication and grouping](https://www.algolia.com/doc/guides/managing-results/refine-results/grouping/#introducing-algolias-distinct-feature). The `distinct` setting is ignored if `attributeForDistinct` is not set.
|
11
|
+
module Distinct
|
12
|
+
class << self
|
13
|
+
# List of class defined in oneOf (OpenAPI v3)
|
14
|
+
def openapi_one_of
|
15
|
+
[
|
16
|
+
:"Boolean",
|
17
|
+
:"Integer"
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Builds the object
|
22
|
+
# @param [Mixed] Data to be matched against the list of oneOf items
|
23
|
+
# @return [Object] Returns the model or the data itself
|
24
|
+
def build(data)
|
25
|
+
# Go through the list of oneOf items and attempt to identify the appropriate one.
|
26
|
+
# Note:
|
27
|
+
# - We do not attempt to check whether exactly one item matches.
|
28
|
+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
|
29
|
+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
|
30
|
+
# - TODO: scalar values are de facto behaving as if they were nullable.
|
31
|
+
# - TODO: logging when debugging is set.
|
32
|
+
openapi_one_of.each do |klass|
|
33
|
+
begin
|
34
|
+
# "nullable: true"
|
35
|
+
next if klass == :AnyType
|
36
|
+
typed_data = find_and_cast_into_type(klass, data)
|
37
|
+
return typed_data if typed_data
|
38
|
+
# rescue all errors so we keep iterating even if the current item lookup raises
|
39
|
+
rescue
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
openapi_one_of.include?(:AnyType) ? data : nil
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
SchemaMismatchError = Class.new(StandardError)
|
49
|
+
|
50
|
+
def find_and_cast_into_type(klass, data)
|
51
|
+
return if data.nil?
|
52
|
+
|
53
|
+
case klass.to_s
|
54
|
+
when "Boolean"
|
55
|
+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
|
56
|
+
when "Float"
|
57
|
+
return data if data.instance_of?(Float)
|
58
|
+
when "Integer"
|
59
|
+
return data if data.instance_of?(Integer)
|
60
|
+
when "Time"
|
61
|
+
return Time.parse(data)
|
62
|
+
when "Date"
|
63
|
+
return Date.parse(data)
|
64
|
+
when "String"
|
65
|
+
return data if data.instance_of?(String)
|
66
|
+
# "type: object"
|
67
|
+
when "Object"
|
68
|
+
return data if data.instance_of?(Hash)
|
69
|
+
# "type: array"
|
70
|
+
when /\AArray<(?<sub_type>.+)>\z/
|
71
|
+
if data.instance_of?(Array)
|
72
|
+
sub_type = Regexp.last_match[:sub_type]
|
73
|
+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
|
74
|
+
end
|
75
|
+
# "type: object" with "additionalProperties: { ... }"
|
76
|
+
when /\AHash<String, (?<sub_type>.+)>\z/
|
77
|
+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
|
78
|
+
sub_type = Regexp.last_match[:sub_type]
|
79
|
+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
|
80
|
+
end
|
81
|
+
# model
|
82
|
+
else
|
83
|
+
const = Algolia::Composition.const_get(klass)
|
84
|
+
if const
|
85
|
+
if const.respond_to?(:openapi_one_of)
|
86
|
+
# nested oneOf model
|
87
|
+
model = const.build(data)
|
88
|
+
elsif const.respond_to?(:discriminator_attributes)
|
89
|
+
if const.discriminator_attributes.all? { |attr| data.key?(attr) }
|
90
|
+
model = const.build_from_hash(data)
|
91
|
+
end
|
92
|
+
else
|
93
|
+
# maybe it's an enum, or doens't have discriminators
|
94
|
+
model = const.build_from_hash(data)
|
95
|
+
end
|
96
|
+
|
97
|
+
return model if model
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# if no match by now, raise
|
102
|
+
raise
|
103
|
+
rescue
|
104
|
+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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 Composition
|
10
|
+
class ExactOnSingleWordQuery
|
11
|
+
ATTRIBUTE = "attribute".freeze
|
12
|
+
NONE = "none".freeze
|
13
|
+
WORD = "word".freeze
|
14
|
+
|
15
|
+
def self.all_vars
|
16
|
+
@all_vars ||= [ATTRIBUTE, NONE, WORD].freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
# Builds the enum from string
|
20
|
+
# @param [String] The enum value in the form of the string
|
21
|
+
# @return [String] The enum value
|
22
|
+
def self.build_from_hash(value)
|
23
|
+
new.build_from_hash(value)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Builds the enum from string
|
27
|
+
# @param [String] The enum value in the form of the string
|
28
|
+
# @return [String] The enum value
|
29
|
+
def build_from_hash(value)
|
30
|
+
return value if ExactOnSingleWordQuery.all_vars.include?(value)
|
31
|
+
raise "Invalid ENUM value #{value} for class #ExactOnSingleWordQuery"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,226 @@
|
|
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 Composition
|
10
|
+
class External
|
11
|
+
# Composition Index name.
|
12
|
+
attr_accessor :index
|
13
|
+
|
14
|
+
attr_accessor :params
|
15
|
+
|
16
|
+
attr_accessor :ordering
|
17
|
+
|
18
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
19
|
+
def self.attribute_map
|
20
|
+
{
|
21
|
+
:index => :index,
|
22
|
+
:params => :params,
|
23
|
+
:ordering => :ordering
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Attribute type mapping.
|
28
|
+
def self.types_mapping
|
29
|
+
{
|
30
|
+
:index => :"String",
|
31
|
+
:params => :"BaseInjectionQueryParameters",
|
32
|
+
:ordering => :"ExternalOrdering"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# List of attributes with nullable: true
|
37
|
+
def self.openapi_nullable
|
38
|
+
Set.new(
|
39
|
+
[]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Initializes the object
|
44
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
45
|
+
def initialize(attributes = {})
|
46
|
+
if (!attributes.is_a?(Hash))
|
47
|
+
raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::External` initialize method"
|
48
|
+
end
|
49
|
+
|
50
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
51
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
52
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
53
|
+
raise(
|
54
|
+
ArgumentError,
|
55
|
+
"`#{k}` is not a valid attribute in `Algolia::External`. Please check the name to make sure it's valid. List of attributes: " +
|
56
|
+
self.class.attribute_map.keys.inspect
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
h[k.to_sym] = v
|
61
|
+
}
|
62
|
+
|
63
|
+
if attributes.key?(:index)
|
64
|
+
self.index = attributes[:index]
|
65
|
+
else
|
66
|
+
self.index = nil
|
67
|
+
end
|
68
|
+
|
69
|
+
if attributes.key?(:params)
|
70
|
+
self.params = attributes[:params]
|
71
|
+
end
|
72
|
+
|
73
|
+
if attributes.key?(:ordering)
|
74
|
+
self.ordering = attributes[:ordering]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Checks equality by comparing each attribute.
|
79
|
+
# @param [Object] Object to be compared
|
80
|
+
def ==(other)
|
81
|
+
return true if self.equal?(other)
|
82
|
+
self.class == other.class &&
|
83
|
+
index == other.index &&
|
84
|
+
params == other.params &&
|
85
|
+
ordering == other.ordering
|
86
|
+
end
|
87
|
+
|
88
|
+
# @see the `==` method
|
89
|
+
# @param [Object] Object to be compared
|
90
|
+
def eql?(other)
|
91
|
+
self == other
|
92
|
+
end
|
93
|
+
|
94
|
+
# Calculates hash code according to all attributes.
|
95
|
+
# @return [Integer] Hash code
|
96
|
+
def hash
|
97
|
+
[index, params, ordering].hash
|
98
|
+
end
|
99
|
+
|
100
|
+
# Builds the object from hash
|
101
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
102
|
+
# @return [Object] Returns the model itself
|
103
|
+
def self.build_from_hash(attributes)
|
104
|
+
return nil unless attributes.is_a?(Hash)
|
105
|
+
attributes = attributes.transform_keys(&:to_sym)
|
106
|
+
transformed_hash = {}
|
107
|
+
types_mapping.each_pair do |key, type|
|
108
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
109
|
+
transformed_hash[key.to_sym] = nil
|
110
|
+
elsif type =~ /\AArray<(.*)>/i
|
111
|
+
# check to ensure the input is an array given that the attribute
|
112
|
+
# is documented as an array but the input is not
|
113
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
114
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
115
|
+
_deserialize(::Regexp.last_match(1), v)
|
116
|
+
}
|
117
|
+
end
|
118
|
+
elsif !attributes[attribute_map[key]].nil?
|
119
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
new(transformed_hash)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Deserializes the data based on type
|
127
|
+
# @param string type Data type
|
128
|
+
# @param string value Value to be deserialized
|
129
|
+
# @return [Object] Deserialized data
|
130
|
+
def self._deserialize(type, value)
|
131
|
+
case type.to_sym
|
132
|
+
when :Time
|
133
|
+
Time.parse(value)
|
134
|
+
when :Date
|
135
|
+
Date.parse(value)
|
136
|
+
when :String
|
137
|
+
value.to_s
|
138
|
+
when :Integer
|
139
|
+
value.to_i
|
140
|
+
when :Float
|
141
|
+
value.to_f
|
142
|
+
when :Boolean
|
143
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
144
|
+
true
|
145
|
+
else
|
146
|
+
false
|
147
|
+
end
|
148
|
+
|
149
|
+
when :Object
|
150
|
+
# generic object (usually a Hash), return directly
|
151
|
+
value
|
152
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
153
|
+
inner_type = Regexp.last_match[:inner_type]
|
154
|
+
value.map { |v| _deserialize(inner_type, v) }
|
155
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
156
|
+
k_type = Regexp.last_match[:k_type]
|
157
|
+
v_type = Regexp.last_match[:v_type]
|
158
|
+
{}.tap do |hash|
|
159
|
+
value.each do |k, v|
|
160
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
# model
|
164
|
+
else
|
165
|
+
# models (e.g. Pet) or oneOf
|
166
|
+
klass = Algolia::Composition.const_get(type)
|
167
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
168
|
+
.build_from_hash(value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns the string representation of the object
|
173
|
+
# @return [String] String presentation of the object
|
174
|
+
def to_s
|
175
|
+
to_hash.to_s
|
176
|
+
end
|
177
|
+
|
178
|
+
# to_body is an alias to to_hash (backward compatibility)
|
179
|
+
# @return [Hash] Returns the object in the form of hash
|
180
|
+
def to_body
|
181
|
+
to_hash
|
182
|
+
end
|
183
|
+
|
184
|
+
def to_json(*_args)
|
185
|
+
to_hash.to_json
|
186
|
+
end
|
187
|
+
|
188
|
+
# Returns the object in the form of hash
|
189
|
+
# @return [Hash] Returns the object in the form of hash
|
190
|
+
def to_hash
|
191
|
+
hash = {}
|
192
|
+
self.class.attribute_map.each_pair do |attr, param|
|
193
|
+
value = send(attr)
|
194
|
+
if value.nil?
|
195
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
196
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
197
|
+
end
|
198
|
+
|
199
|
+
hash[param] = _to_hash(value)
|
200
|
+
end
|
201
|
+
|
202
|
+
hash
|
203
|
+
end
|
204
|
+
|
205
|
+
# Outputs non-array value in the form of hash
|
206
|
+
# For object, use to_hash. Otherwise, just return the value
|
207
|
+
# @param [Object] value Any valid value
|
208
|
+
# @return [Hash] Returns the value in the form of hash
|
209
|
+
def _to_hash(value)
|
210
|
+
if value.is_a?(Array)
|
211
|
+
value.compact.map { |v| _to_hash(v) }
|
212
|
+
elsif value.is_a?(Hash)
|
213
|
+
{}.tap do |hash|
|
214
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
215
|
+
end
|
216
|
+
elsif value.respond_to?(:to_hash)
|
217
|
+
value.to_hash
|
218
|
+
else
|
219
|
+
value
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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 Composition
|
10
|
+
class ExternalOrdering
|
11
|
+
DEFAULT = "default".freeze
|
12
|
+
USER_DEFINED = "userDefined".freeze
|
13
|
+
|
14
|
+
def self.all_vars
|
15
|
+
@all_vars ||= [DEFAULT, USER_DEFINED].freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
# Builds the enum from string
|
19
|
+
# @param [String] The enum value in the form of the string
|
20
|
+
# @return [String] The enum value
|
21
|
+
def self.build_from_hash(value)
|
22
|
+
new.build_from_hash(value)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Builds the enum from string
|
26
|
+
# @param [String] The enum value in the form of the string
|
27
|
+
# @return [String] The enum value
|
28
|
+
def build_from_hash(value)
|
29
|
+
return value if ExternalOrdering.all_vars.include?(value)
|
30
|
+
raise "Invalid ENUM value #{value} for class #ExternalOrdering"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,211 @@
|
|
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 Composition
|
10
|
+
# Injected items will originate from externally provided objectIDs (that must exist in the index) given at runtime in the run request payload.
|
11
|
+
class ExternalSource
|
12
|
+
attr_accessor :external
|
13
|
+
|
14
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
15
|
+
def self.attribute_map
|
16
|
+
{
|
17
|
+
:external => :external
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Attribute type mapping.
|
22
|
+
def self.types_mapping
|
23
|
+
{
|
24
|
+
:external => :"External"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# List of attributes with nullable: true
|
29
|
+
def self.openapi_nullable
|
30
|
+
Set.new(
|
31
|
+
[]
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Initializes the object
|
36
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
37
|
+
def initialize(attributes = {})
|
38
|
+
if (!attributes.is_a?(Hash))
|
39
|
+
raise(
|
40
|
+
ArgumentError,
|
41
|
+
"The input argument (attributes) must be a hash in `Algolia::ExternalSource` initialize method"
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
46
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
47
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
48
|
+
raise(
|
49
|
+
ArgumentError,
|
50
|
+
"`#{k}` is not a valid attribute in `Algolia::ExternalSource`. Please check the name to make sure it's valid. List of attributes: " +
|
51
|
+
self.class.attribute_map.keys.inspect
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
h[k.to_sym] = v
|
56
|
+
}
|
57
|
+
|
58
|
+
if attributes.key?(:external)
|
59
|
+
self.external = attributes[:external]
|
60
|
+
else
|
61
|
+
self.external = nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Checks equality by comparing each attribute.
|
66
|
+
# @param [Object] Object to be compared
|
67
|
+
def ==(other)
|
68
|
+
return true if self.equal?(other)
|
69
|
+
self.class == other.class &&
|
70
|
+
external == other.external
|
71
|
+
end
|
72
|
+
|
73
|
+
# @see the `==` method
|
74
|
+
# @param [Object] Object to be compared
|
75
|
+
def eql?(other)
|
76
|
+
self == other
|
77
|
+
end
|
78
|
+
|
79
|
+
# Calculates hash code according to all attributes.
|
80
|
+
# @return [Integer] Hash code
|
81
|
+
def hash
|
82
|
+
[external].hash
|
83
|
+
end
|
84
|
+
|
85
|
+
# Builds the object from hash
|
86
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
87
|
+
# @return [Object] Returns the model itself
|
88
|
+
def self.build_from_hash(attributes)
|
89
|
+
return nil unless attributes.is_a?(Hash)
|
90
|
+
attributes = attributes.transform_keys(&:to_sym)
|
91
|
+
transformed_hash = {}
|
92
|
+
types_mapping.each_pair do |key, type|
|
93
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
94
|
+
transformed_hash[key.to_sym] = nil
|
95
|
+
elsif type =~ /\AArray<(.*)>/i
|
96
|
+
# check to ensure the input is an array given that the attribute
|
97
|
+
# is documented as an array but the input is not
|
98
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
99
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
100
|
+
_deserialize(::Regexp.last_match(1), v)
|
101
|
+
}
|
102
|
+
end
|
103
|
+
elsif !attributes[attribute_map[key]].nil?
|
104
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
new(transformed_hash)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Deserializes the data based on type
|
112
|
+
# @param string type Data type
|
113
|
+
# @param string value Value to be deserialized
|
114
|
+
# @return [Object] Deserialized data
|
115
|
+
def self._deserialize(type, value)
|
116
|
+
case type.to_sym
|
117
|
+
when :Time
|
118
|
+
Time.parse(value)
|
119
|
+
when :Date
|
120
|
+
Date.parse(value)
|
121
|
+
when :String
|
122
|
+
value.to_s
|
123
|
+
when :Integer
|
124
|
+
value.to_i
|
125
|
+
when :Float
|
126
|
+
value.to_f
|
127
|
+
when :Boolean
|
128
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
129
|
+
true
|
130
|
+
else
|
131
|
+
false
|
132
|
+
end
|
133
|
+
|
134
|
+
when :Object
|
135
|
+
# generic object (usually a Hash), return directly
|
136
|
+
value
|
137
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
138
|
+
inner_type = Regexp.last_match[:inner_type]
|
139
|
+
value.map { |v| _deserialize(inner_type, v) }
|
140
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
141
|
+
k_type = Regexp.last_match[:k_type]
|
142
|
+
v_type = Regexp.last_match[:v_type]
|
143
|
+
{}.tap do |hash|
|
144
|
+
value.each do |k, v|
|
145
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
# model
|
149
|
+
else
|
150
|
+
# models (e.g. Pet) or oneOf
|
151
|
+
klass = Algolia::Composition.const_get(type)
|
152
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
153
|
+
.build_from_hash(value)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Returns the string representation of the object
|
158
|
+
# @return [String] String presentation of the object
|
159
|
+
def to_s
|
160
|
+
to_hash.to_s
|
161
|
+
end
|
162
|
+
|
163
|
+
# to_body is an alias to to_hash (backward compatibility)
|
164
|
+
# @return [Hash] Returns the object in the form of hash
|
165
|
+
def to_body
|
166
|
+
to_hash
|
167
|
+
end
|
168
|
+
|
169
|
+
def to_json(*_args)
|
170
|
+
to_hash.to_json
|
171
|
+
end
|
172
|
+
|
173
|
+
# Returns the object in the form of hash
|
174
|
+
# @return [Hash] Returns the object in the form of hash
|
175
|
+
def to_hash
|
176
|
+
hash = {}
|
177
|
+
self.class.attribute_map.each_pair do |attr, param|
|
178
|
+
value = send(attr)
|
179
|
+
if value.nil?
|
180
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
181
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
182
|
+
end
|
183
|
+
|
184
|
+
hash[param] = _to_hash(value)
|
185
|
+
end
|
186
|
+
|
187
|
+
hash
|
188
|
+
end
|
189
|
+
|
190
|
+
# Outputs non-array value in the form of hash
|
191
|
+
# For object, use to_hash. Otherwise, just return the value
|
192
|
+
# @param [Object] value Any valid value
|
193
|
+
# @return [Hash] Returns the value in the form of hash
|
194
|
+
def _to_hash(value)
|
195
|
+
if value.is_a?(Array)
|
196
|
+
value.compact.map { |v| _to_hash(v) }
|
197
|
+
elsif value.is_a?(Hash)
|
198
|
+
{}.tap do |hash|
|
199
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
200
|
+
end
|
201
|
+
elsif value.respond_to?(:to_hash)
|
202
|
+
value.to_hash
|
203
|
+
else
|
204
|
+
value
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|