|
| 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 |
0 commit comments