algolia 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/algolia/api/analytics_client.rb +144 -32
- data/lib/algolia/api/search_client.rb +16 -16
- data/lib/algolia/models/recommend/banner.rb +218 -0
- data/lib/algolia/models/recommend/banner_image.rb +221 -0
- data/lib/algolia/models/recommend/banner_image_url.rb +212 -0
- data/lib/algolia/models/recommend/banner_link.rb +212 -0
- data/lib/algolia/models/recommend/banners.rb +209 -0
- data/lib/algolia/models/recommend/fallback_params.rb +8 -8
- data/lib/algolia/models/recommend/numeric_filters.rb +1 -1
- data/lib/algolia/models/recommend/recommend_search_params.rb +8 -8
- data/lib/algolia/models/recommend/rendering_content.rb +14 -5
- data/lib/algolia/models/recommend/typo_tolerance.rb +1 -1
- data/lib/algolia/models/recommend/widgets.rb +209 -0
- data/lib/algolia/models/search/api_key.rb +1 -1
- data/lib/algolia/models/search/banner.rb +218 -0
- data/lib/algolia/models/search/banner_image.rb +221 -0
- data/lib/algolia/models/search/banner_image_url.rb +212 -0
- data/lib/algolia/models/search/banner_link.rb +212 -0
- data/lib/algolia/models/search/banners.rb +209 -0
- data/lib/algolia/models/search/browse_params_object.rb +4 -4
- data/lib/algolia/models/search/consequence_params.rb +4 -4
- data/lib/algolia/models/search/delete_by_params.rb +1 -1
- data/lib/algolia/models/search/get_api_key_response.rb +1 -1
- data/lib/algolia/models/search/index_settings.rb +7 -7
- data/lib/algolia/models/search/numeric_filters.rb +1 -1
- data/lib/algolia/models/search/rendering_content.rb +14 -5
- data/lib/algolia/models/search/search_for_facets.rb +4 -4
- data/lib/algolia/models/search/search_for_hits.rb +4 -4
- data/lib/algolia/models/search/search_params_object.rb +4 -4
- data/lib/algolia/models/search/settings_response.rb +7 -7
- data/lib/algolia/models/search/typo_tolerance.rb +1 -1
- data/lib/algolia/models/search/widgets.rb +209 -0
- data/lib/algolia/version.rb +1 -1
- metadata +14 -2
@@ -0,0 +1,209 @@
|
|
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 Recommend
|
8
|
+
# widgets returned from any rules that are applied to the current search.
|
9
|
+
class Widgets
|
10
|
+
attr_accessor :banners
|
11
|
+
|
12
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
13
|
+
def self.attribute_map
|
14
|
+
{
|
15
|
+
:banners => :banners
|
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
|
+
:banners => :"Banners"
|
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 ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Widgets` initialize method"
|
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::Widgets`. 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?(:banners)
|
59
|
+
self.banners = attributes[:banners]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Checks equality by comparing each attribute.
|
64
|
+
# @param [Object] Object to be compared
|
65
|
+
def ==(other)
|
66
|
+
return true if self.equal?(other)
|
67
|
+
self.class == other.class &&
|
68
|
+
banners == other.banners
|
69
|
+
end
|
70
|
+
|
71
|
+
# @see the `==` method
|
72
|
+
# @param [Object] Object to be compared
|
73
|
+
def eql?(other)
|
74
|
+
self == other
|
75
|
+
end
|
76
|
+
|
77
|
+
# Calculates hash code according to all attributes.
|
78
|
+
# @return [Integer] Hash code
|
79
|
+
def hash
|
80
|
+
[banners].hash
|
81
|
+
end
|
82
|
+
|
83
|
+
# Builds the object from hash
|
84
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
85
|
+
# @return [Object] Returns the model itself
|
86
|
+
def self.build_from_hash(attributes)
|
87
|
+
return nil unless attributes.is_a?(Hash)
|
88
|
+
attributes = attributes.transform_keys(&:to_sym)
|
89
|
+
transformed_hash = {}
|
90
|
+
types_mapping.each_pair do |key, type|
|
91
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
92
|
+
transformed_hash[key.to_sym] = nil
|
93
|
+
elsif type =~ /\AArray<(.*)>/i
|
94
|
+
# check to ensure the input is an array given that the attribute
|
95
|
+
# is documented as an array but the input is not
|
96
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
97
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
98
|
+
_deserialize(::Regexp.last_match(1), v)
|
99
|
+
}
|
100
|
+
end
|
101
|
+
elsif !attributes[attribute_map[key]].nil?
|
102
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
new(transformed_hash)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Deserializes the data based on type
|
110
|
+
# @param string type Data type
|
111
|
+
# @param string value Value to be deserialized
|
112
|
+
# @return [Object] Deserialized data
|
113
|
+
def self._deserialize(type, value)
|
114
|
+
case type.to_sym
|
115
|
+
when :Time
|
116
|
+
Time.parse(value)
|
117
|
+
when :Date
|
118
|
+
Date.parse(value)
|
119
|
+
when :String
|
120
|
+
value.to_s
|
121
|
+
when :Integer
|
122
|
+
value.to_i
|
123
|
+
when :Float
|
124
|
+
value.to_f
|
125
|
+
when :Boolean
|
126
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
127
|
+
true
|
128
|
+
else
|
129
|
+
false
|
130
|
+
end
|
131
|
+
|
132
|
+
when :Object
|
133
|
+
# generic object (usually a Hash), return directly
|
134
|
+
value
|
135
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
136
|
+
inner_type = Regexp.last_match[:inner_type]
|
137
|
+
value.map { |v| _deserialize(inner_type, v) }
|
138
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
139
|
+
k_type = Regexp.last_match[:k_type]
|
140
|
+
v_type = Regexp.last_match[:v_type]
|
141
|
+
{}.tap do |hash|
|
142
|
+
value.each do |k, v|
|
143
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
# model
|
147
|
+
else
|
148
|
+
# models (e.g. Pet) or oneOf
|
149
|
+
klass = Algolia::Recommend.const_get(type)
|
150
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
151
|
+
.build_from_hash(value)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns the string representation of the object
|
156
|
+
# @return [String] String presentation of the object
|
157
|
+
def to_s
|
158
|
+
to_hash.to_s
|
159
|
+
end
|
160
|
+
|
161
|
+
# to_body is an alias to to_hash (backward compatibility)
|
162
|
+
# @return [Hash] Returns the object in the form of hash
|
163
|
+
def to_body
|
164
|
+
to_hash
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_json(*_args)
|
168
|
+
to_hash.to_json
|
169
|
+
end
|
170
|
+
|
171
|
+
# Returns the object in the form of hash
|
172
|
+
# @return [Hash] Returns the object in the form of hash
|
173
|
+
def to_hash
|
174
|
+
hash = {}
|
175
|
+
self.class.attribute_map.each_pair do |attr, param|
|
176
|
+
value = send(attr)
|
177
|
+
if value.nil?
|
178
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
179
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
180
|
+
end
|
181
|
+
|
182
|
+
hash[param] = _to_hash(value)
|
183
|
+
end
|
184
|
+
|
185
|
+
hash
|
186
|
+
end
|
187
|
+
|
188
|
+
# Outputs non-array value in the form of hash
|
189
|
+
# For object, use to_hash. Otherwise, just return the value
|
190
|
+
# @param [Object] value Any valid value
|
191
|
+
# @return [Hash] Returns the value in the form of hash
|
192
|
+
def _to_hash(value)
|
193
|
+
if value.is_a?(Array)
|
194
|
+
value.compact.map { |v| _to_hash(v) }
|
195
|
+
elsif value.is_a?(Hash)
|
196
|
+
{}.tap do |hash|
|
197
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
198
|
+
end
|
199
|
+
elsif value.respond_to?(:to_hash)
|
200
|
+
value.to_hash
|
201
|
+
else
|
202
|
+
value
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
end
|
@@ -22,7 +22,7 @@ module Algolia
|
|
22
22
|
# Maximum number of API requests allowed per IP address or [user token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken/) per hour. If this limit is reached, the API returns an error with status code `429`. By default, there's no limit.
|
23
23
|
attr_accessor :max_queries_per_ip_per_hour
|
24
24
|
|
25
|
-
# Query parameters to add when making API requests with this API key. To restrict this API key to specific IP addresses, add the `restrictSources` parameter. You can only add a single source, but you can provide a range of IP addresses. Creating an API key fails if the request is made from an IP address
|
25
|
+
# Query parameters to add when making API requests with this API key. To restrict this API key to specific IP addresses, add the `restrictSources` parameter. You can only add a single source, but you can provide a range of IP addresses. Creating an API key fails if the request is made from an IP address outside the restricted range.
|
26
26
|
attr_accessor :query_parameters
|
27
27
|
|
28
28
|
# Allowed HTTP referrers for this API key. By default, all referrers are allowed. You can use leading and trailing wildcard characters (`*`): - `https://algolia.com/*` allows all referrers starting with \"https://algolia.com/\" - `*.algolia.com` allows all referrers ending with \".algolia.com\" - `*algolia.com*` allows all referrers in the domain \"algolia.com\". Like all HTTP headers, referrers can be spoofed. Don't rely on them to secure your data. For more information, see [HTTP referrer restrictions](https://www.algolia.com/doc/guides/security/security-best-practices/#http-referrers-restrictions).
|
@@ -0,0 +1,218 @@
|
|
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 Search
|
8
|
+
# a search banner with image and url.
|
9
|
+
class Banner
|
10
|
+
attr_accessor :image
|
11
|
+
|
12
|
+
attr_accessor :link
|
13
|
+
|
14
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
15
|
+
def self.attribute_map
|
16
|
+
{
|
17
|
+
:image => :image,
|
18
|
+
:link => :link
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns all the JSON keys this model knows about
|
23
|
+
def self.acceptable_attributes
|
24
|
+
attribute_map.values
|
25
|
+
end
|
26
|
+
|
27
|
+
# Attribute type mapping.
|
28
|
+
def self.types_mapping
|
29
|
+
{
|
30
|
+
:image => :"BannerImage",
|
31
|
+
:link => :"BannerLink"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# List of attributes with nullable: true
|
36
|
+
def self.openapi_nullable
|
37
|
+
Set.new(
|
38
|
+
[]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Initializes the object
|
43
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
44
|
+
def initialize(attributes = {})
|
45
|
+
if (!attributes.is_a?(Hash))
|
46
|
+
raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Banner` initialize method"
|
47
|
+
end
|
48
|
+
|
49
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
50
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
51
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
52
|
+
raise(
|
53
|
+
ArgumentError,
|
54
|
+
"`#{k}` is not a valid attribute in `Algolia::Banner`. Please check the name to make sure it's valid. List of attributes: " +
|
55
|
+
self.class.attribute_map.keys.inspect
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
h[k.to_sym] = v
|
60
|
+
}
|
61
|
+
|
62
|
+
if attributes.key?(:image)
|
63
|
+
self.image = attributes[:image]
|
64
|
+
end
|
65
|
+
|
66
|
+
if attributes.key?(:link)
|
67
|
+
self.link = attributes[:link]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Checks equality by comparing each attribute.
|
72
|
+
# @param [Object] Object to be compared
|
73
|
+
def ==(other)
|
74
|
+
return true if self.equal?(other)
|
75
|
+
self.class == other.class &&
|
76
|
+
image == other.image &&
|
77
|
+
link == other.link
|
78
|
+
end
|
79
|
+
|
80
|
+
# @see the `==` method
|
81
|
+
# @param [Object] Object to be compared
|
82
|
+
def eql?(other)
|
83
|
+
self == other
|
84
|
+
end
|
85
|
+
|
86
|
+
# Calculates hash code according to all attributes.
|
87
|
+
# @return [Integer] Hash code
|
88
|
+
def hash
|
89
|
+
[image, link].hash
|
90
|
+
end
|
91
|
+
|
92
|
+
# Builds the object from hash
|
93
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
94
|
+
# @return [Object] Returns the model itself
|
95
|
+
def self.build_from_hash(attributes)
|
96
|
+
return nil unless attributes.is_a?(Hash)
|
97
|
+
attributes = attributes.transform_keys(&:to_sym)
|
98
|
+
transformed_hash = {}
|
99
|
+
types_mapping.each_pair do |key, type|
|
100
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
101
|
+
transformed_hash[key.to_sym] = nil
|
102
|
+
elsif type =~ /\AArray<(.*)>/i
|
103
|
+
# check to ensure the input is an array given that the attribute
|
104
|
+
# is documented as an array but the input is not
|
105
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
106
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
107
|
+
_deserialize(::Regexp.last_match(1), v)
|
108
|
+
}
|
109
|
+
end
|
110
|
+
elsif !attributes[attribute_map[key]].nil?
|
111
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
new(transformed_hash)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Deserializes the data based on type
|
119
|
+
# @param string type Data type
|
120
|
+
# @param string value Value to be deserialized
|
121
|
+
# @return [Object] Deserialized data
|
122
|
+
def self._deserialize(type, value)
|
123
|
+
case type.to_sym
|
124
|
+
when :Time
|
125
|
+
Time.parse(value)
|
126
|
+
when :Date
|
127
|
+
Date.parse(value)
|
128
|
+
when :String
|
129
|
+
value.to_s
|
130
|
+
when :Integer
|
131
|
+
value.to_i
|
132
|
+
when :Float
|
133
|
+
value.to_f
|
134
|
+
when :Boolean
|
135
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
136
|
+
true
|
137
|
+
else
|
138
|
+
false
|
139
|
+
end
|
140
|
+
|
141
|
+
when :Object
|
142
|
+
# generic object (usually a Hash), return directly
|
143
|
+
value
|
144
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
145
|
+
inner_type = Regexp.last_match[:inner_type]
|
146
|
+
value.map { |v| _deserialize(inner_type, v) }
|
147
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
148
|
+
k_type = Regexp.last_match[:k_type]
|
149
|
+
v_type = Regexp.last_match[:v_type]
|
150
|
+
{}.tap do |hash|
|
151
|
+
value.each do |k, v|
|
152
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
# model
|
156
|
+
else
|
157
|
+
# models (e.g. Pet) or oneOf
|
158
|
+
klass = Algolia::Search.const_get(type)
|
159
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
160
|
+
.build_from_hash(value)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# Returns the string representation of the object
|
165
|
+
# @return [String] String presentation of the object
|
166
|
+
def to_s
|
167
|
+
to_hash.to_s
|
168
|
+
end
|
169
|
+
|
170
|
+
# to_body is an alias to to_hash (backward compatibility)
|
171
|
+
# @return [Hash] Returns the object in the form of hash
|
172
|
+
def to_body
|
173
|
+
to_hash
|
174
|
+
end
|
175
|
+
|
176
|
+
def to_json(*_args)
|
177
|
+
to_hash.to_json
|
178
|
+
end
|
179
|
+
|
180
|
+
# Returns the object in the form of hash
|
181
|
+
# @return [Hash] Returns the object in the form of hash
|
182
|
+
def to_hash
|
183
|
+
hash = {}
|
184
|
+
self.class.attribute_map.each_pair do |attr, param|
|
185
|
+
value = send(attr)
|
186
|
+
if value.nil?
|
187
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
188
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
189
|
+
end
|
190
|
+
|
191
|
+
hash[param] = _to_hash(value)
|
192
|
+
end
|
193
|
+
|
194
|
+
hash
|
195
|
+
end
|
196
|
+
|
197
|
+
# Outputs non-array value in the form of hash
|
198
|
+
# For object, use to_hash. Otherwise, just return the value
|
199
|
+
# @param [Object] value Any valid value
|
200
|
+
# @return [Hash] Returns the value in the form of hash
|
201
|
+
def _to_hash(value)
|
202
|
+
if value.is_a?(Array)
|
203
|
+
value.compact.map { |v| _to_hash(v) }
|
204
|
+
elsif value.is_a?(Hash)
|
205
|
+
{}.tap do |hash|
|
206
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
207
|
+
end
|
208
|
+
elsif value.respond_to?(:to_hash)
|
209
|
+
value.to_hash
|
210
|
+
else
|
211
|
+
value
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,221 @@
|
|
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 Search
|
8
|
+
# image of a search banner.
|
9
|
+
class BannerImage
|
10
|
+
attr_accessor :urls
|
11
|
+
|
12
|
+
attr_accessor :title
|
13
|
+
|
14
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
15
|
+
def self.attribute_map
|
16
|
+
{
|
17
|
+
:urls => :urls,
|
18
|
+
:title => :title
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns all the JSON keys this model knows about
|
23
|
+
def self.acceptable_attributes
|
24
|
+
attribute_map.values
|
25
|
+
end
|
26
|
+
|
27
|
+
# Attribute type mapping.
|
28
|
+
def self.types_mapping
|
29
|
+
{
|
30
|
+
:urls => :"BannerImageUrl",
|
31
|
+
:title => :"String"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# List of attributes with nullable: true
|
36
|
+
def self.openapi_nullable
|
37
|
+
Set.new(
|
38
|
+
[]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Initializes the object
|
43
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
44
|
+
def initialize(attributes = {})
|
45
|
+
if (!attributes.is_a?(Hash))
|
46
|
+
raise(
|
47
|
+
ArgumentError,
|
48
|
+
"The input argument (attributes) must be a hash in `Algolia::BannerImage` initialize method"
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
53
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
54
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
55
|
+
raise(
|
56
|
+
ArgumentError,
|
57
|
+
"`#{k}` is not a valid attribute in `Algolia::BannerImage`. Please check the name to make sure it's valid. List of attributes: " +
|
58
|
+
self.class.attribute_map.keys.inspect
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
h[k.to_sym] = v
|
63
|
+
}
|
64
|
+
|
65
|
+
if attributes.key?(:urls)
|
66
|
+
self.urls = attributes[:urls]
|
67
|
+
end
|
68
|
+
|
69
|
+
if attributes.key?(:title)
|
70
|
+
self.title = attributes[:title]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Checks equality by comparing each attribute.
|
75
|
+
# @param [Object] Object to be compared
|
76
|
+
def ==(other)
|
77
|
+
return true if self.equal?(other)
|
78
|
+
self.class == other.class &&
|
79
|
+
urls == other.urls &&
|
80
|
+
title == other.title
|
81
|
+
end
|
82
|
+
|
83
|
+
# @see the `==` method
|
84
|
+
# @param [Object] Object to be compared
|
85
|
+
def eql?(other)
|
86
|
+
self == other
|
87
|
+
end
|
88
|
+
|
89
|
+
# Calculates hash code according to all attributes.
|
90
|
+
# @return [Integer] Hash code
|
91
|
+
def hash
|
92
|
+
[urls, title].hash
|
93
|
+
end
|
94
|
+
|
95
|
+
# Builds the object from hash
|
96
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
97
|
+
# @return [Object] Returns the model itself
|
98
|
+
def self.build_from_hash(attributes)
|
99
|
+
return nil unless attributes.is_a?(Hash)
|
100
|
+
attributes = attributes.transform_keys(&:to_sym)
|
101
|
+
transformed_hash = {}
|
102
|
+
types_mapping.each_pair do |key, type|
|
103
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
104
|
+
transformed_hash[key.to_sym] = nil
|
105
|
+
elsif type =~ /\AArray<(.*)>/i
|
106
|
+
# check to ensure the input is an array given that the attribute
|
107
|
+
# is documented as an array but the input is not
|
108
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
109
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
|
110
|
+
_deserialize(::Regexp.last_match(1), v)
|
111
|
+
}
|
112
|
+
end
|
113
|
+
elsif !attributes[attribute_map[key]].nil?
|
114
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
new(transformed_hash)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Deserializes the data based on type
|
122
|
+
# @param string type Data type
|
123
|
+
# @param string value Value to be deserialized
|
124
|
+
# @return [Object] Deserialized data
|
125
|
+
def self._deserialize(type, value)
|
126
|
+
case type.to_sym
|
127
|
+
when :Time
|
128
|
+
Time.parse(value)
|
129
|
+
when :Date
|
130
|
+
Date.parse(value)
|
131
|
+
when :String
|
132
|
+
value.to_s
|
133
|
+
when :Integer
|
134
|
+
value.to_i
|
135
|
+
when :Float
|
136
|
+
value.to_f
|
137
|
+
when :Boolean
|
138
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
139
|
+
true
|
140
|
+
else
|
141
|
+
false
|
142
|
+
end
|
143
|
+
|
144
|
+
when :Object
|
145
|
+
# generic object (usually a Hash), return directly
|
146
|
+
value
|
147
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
148
|
+
inner_type = Regexp.last_match[:inner_type]
|
149
|
+
value.map { |v| _deserialize(inner_type, v) }
|
150
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
151
|
+
k_type = Regexp.last_match[:k_type]
|
152
|
+
v_type = Regexp.last_match[:v_type]
|
153
|
+
{}.tap do |hash|
|
154
|
+
value.each do |k, v|
|
155
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
# model
|
159
|
+
else
|
160
|
+
# models (e.g. Pet) or oneOf
|
161
|
+
klass = Algolia::Search.const_get(type)
|
162
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
|
163
|
+
.build_from_hash(value)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Returns the string representation of the object
|
168
|
+
# @return [String] String presentation of the object
|
169
|
+
def to_s
|
170
|
+
to_hash.to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
# to_body is an alias to to_hash (backward compatibility)
|
174
|
+
# @return [Hash] Returns the object in the form of hash
|
175
|
+
def to_body
|
176
|
+
to_hash
|
177
|
+
end
|
178
|
+
|
179
|
+
def to_json(*_args)
|
180
|
+
to_hash.to_json
|
181
|
+
end
|
182
|
+
|
183
|
+
# Returns the object in the form of hash
|
184
|
+
# @return [Hash] Returns the object in the form of hash
|
185
|
+
def to_hash
|
186
|
+
hash = {}
|
187
|
+
self.class.attribute_map.each_pair do |attr, param|
|
188
|
+
value = send(attr)
|
189
|
+
if value.nil?
|
190
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
191
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
192
|
+
end
|
193
|
+
|
194
|
+
hash[param] = _to_hash(value)
|
195
|
+
end
|
196
|
+
|
197
|
+
hash
|
198
|
+
end
|
199
|
+
|
200
|
+
# Outputs non-array value in the form of hash
|
201
|
+
# For object, use to_hash. Otherwise, just return the value
|
202
|
+
# @param [Object] value Any valid value
|
203
|
+
# @return [Hash] Returns the value in the form of hash
|
204
|
+
def _to_hash(value)
|
205
|
+
if value.is_a?(Array)
|
206
|
+
value.compact.map { |v| _to_hash(v) }
|
207
|
+
elsif value.is_a?(Hash)
|
208
|
+
{}.tap do |hash|
|
209
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
210
|
+
end
|
211
|
+
elsif value.respond_to?(:to_hash)
|
212
|
+
value.to_hash
|
213
|
+
else
|
214
|
+
value
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
end
|