|
| 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 AbtestingV3 |
| 10 | + class ABTest |
| 11 | + # Unique A/B test identifier. |
| 12 | + attr_accessor :ab_test_id |
| 13 | + |
| 14 | + # Date and time when the A/B test was last updated, in RFC 3339 format. |
| 15 | + attr_accessor :updated_at |
| 16 | + |
| 17 | + # Date and time when the A/B test was created, in RFC 3339 format. |
| 18 | + attr_accessor :created_at |
| 19 | + |
| 20 | + # End date and time of the A/B test, in RFC 3339 format. |
| 21 | + attr_accessor :end_at |
| 22 | + |
| 23 | + # A/B test name. |
| 24 | + attr_accessor :name |
| 25 | + |
| 26 | + attr_accessor :status |
| 27 | + |
| 28 | + # A/B test variants. The first variant is your _control_ index, typically your production index. All of the additional variants are indexes with changed settings that you want to test against the control. |
| 29 | + attr_accessor :variants |
| 30 | + |
| 31 | + attr_accessor :configuration |
| 32 | + |
| 33 | + # Unique migrated A/B test identifier. |
| 34 | + attr_accessor :migrated_ab_test_id |
| 35 | + |
| 36 | + # Attribute mapping from ruby-style variable name to JSON key. |
| 37 | + def self.attribute_map |
| 38 | + { |
| 39 | + :ab_test_id => :abTestID, |
| 40 | + :updated_at => :updatedAt, |
| 41 | + :created_at => :createdAt, |
| 42 | + :end_at => :endAt, |
| 43 | + :name => :name, |
| 44 | + :status => :status, |
| 45 | + :variants => :variants, |
| 46 | + :configuration => :configuration, |
| 47 | + :migrated_ab_test_id => :migratedAbTestID |
| 48 | + } |
| 49 | + end |
| 50 | + |
| 51 | + # Attribute type mapping. |
| 52 | + def self.types_mapping |
| 53 | + { |
| 54 | + :ab_test_id => :"Integer", |
| 55 | + :updated_at => :"String", |
| 56 | + :created_at => :"String", |
| 57 | + :end_at => :"String", |
| 58 | + :name => :"String", |
| 59 | + :status => :"Status", |
| 60 | + :variants => :"Array<Variant>", |
| 61 | + :configuration => :"ABTestConfiguration", |
| 62 | + :migrated_ab_test_id => :"Integer" |
| 63 | + } |
| 64 | + end |
| 65 | + |
| 66 | + # List of attributes with nullable: true |
| 67 | + def self.openapi_nullable |
| 68 | + Set.new( |
| 69 | + [] |
| 70 | + ) |
| 71 | + end |
| 72 | + |
| 73 | + # Initializes the object |
| 74 | + # @param [Hash] attributes Model attributes in the form of hash |
| 75 | + def initialize(attributes = {}) |
| 76 | + if (!attributes.is_a?(Hash)) |
| 77 | + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::ABTest` initialize method" |
| 78 | + end |
| 79 | + |
| 80 | + # check to see if the attribute exists and convert string to symbol for hash key |
| 81 | + attributes = attributes.each_with_object({}) { |(k, v), h| |
| 82 | + if (!self.class.attribute_map.key?(k.to_sym)) |
| 83 | + raise( |
| 84 | + ArgumentError, |
| 85 | + "`#{k}` is not a valid attribute in `Algolia::ABTest`. Please check the name to make sure it's valid. List of attributes: " + |
| 86 | + self.class.attribute_map.keys.inspect |
| 87 | + ) |
| 88 | + end |
| 89 | + |
| 90 | + h[k.to_sym] = v |
| 91 | + } |
| 92 | + |
| 93 | + if attributes.key?(:ab_test_id) |
| 94 | + self.ab_test_id = attributes[:ab_test_id] |
| 95 | + else |
| 96 | + self.ab_test_id = nil |
| 97 | + end |
| 98 | + |
| 99 | + if attributes.key?(:updated_at) |
| 100 | + self.updated_at = attributes[:updated_at] |
| 101 | + else |
| 102 | + self.updated_at = nil |
| 103 | + end |
| 104 | + |
| 105 | + if attributes.key?(:created_at) |
| 106 | + self.created_at = attributes[:created_at] |
| 107 | + else |
| 108 | + self.created_at = nil |
| 109 | + end |
| 110 | + |
| 111 | + if attributes.key?(:end_at) |
| 112 | + self.end_at = attributes[:end_at] |
| 113 | + else |
| 114 | + self.end_at = nil |
| 115 | + end |
| 116 | + |
| 117 | + if attributes.key?(:name) |
| 118 | + self.name = attributes[:name] |
| 119 | + else |
| 120 | + self.name = nil |
| 121 | + end |
| 122 | + |
| 123 | + if attributes.key?(:status) |
| 124 | + self.status = attributes[:status] |
| 125 | + else |
| 126 | + self.status = nil |
| 127 | + end |
| 128 | + |
| 129 | + if attributes.key?(:variants) |
| 130 | + if (value = attributes[:variants]).is_a?(Array) |
| 131 | + self.variants = value |
| 132 | + end |
| 133 | + else |
| 134 | + self.variants = nil |
| 135 | + end |
| 136 | + |
| 137 | + if attributes.key?(:configuration) |
| 138 | + self.configuration = attributes[:configuration] |
| 139 | + end |
| 140 | + |
| 141 | + if attributes.key?(:migrated_ab_test_id) |
| 142 | + self.migrated_ab_test_id = attributes[:migrated_ab_test_id] |
| 143 | + end |
| 144 | + end |
| 145 | + |
| 146 | + # Checks equality by comparing each attribute. |
| 147 | + # @param [Object] Object to be compared |
| 148 | + def ==(other) |
| 149 | + return true if self.equal?(other) |
| 150 | + self.class == other.class && |
| 151 | + ab_test_id == other.ab_test_id && |
| 152 | + updated_at == other.updated_at && |
| 153 | + created_at == other.created_at && |
| 154 | + end_at == other.end_at && |
| 155 | + name == other.name && |
| 156 | + status == other.status && |
| 157 | + variants == other.variants && |
| 158 | + configuration == other.configuration && |
| 159 | + migrated_ab_test_id == other.migrated_ab_test_id |
| 160 | + end |
| 161 | + |
| 162 | + # @see the `==` method |
| 163 | + # @param [Object] Object to be compared |
| 164 | + def eql?(other) |
| 165 | + self == other |
| 166 | + end |
| 167 | + |
| 168 | + # Calculates hash code according to all attributes. |
| 169 | + # @return [Integer] Hash code |
| 170 | + def hash |
| 171 | + [ab_test_id, updated_at, created_at, end_at, name, status, variants, configuration, migrated_ab_test_id].hash |
| 172 | + end |
| 173 | + |
| 174 | + # Builds the object from hash |
| 175 | + # @param [Hash] attributes Model attributes in the form of hash |
| 176 | + # @return [Object] Returns the model itself |
| 177 | + def self.build_from_hash(attributes) |
| 178 | + return nil unless attributes.is_a?(Hash) |
| 179 | + attributes = attributes.transform_keys(&:to_sym) |
| 180 | + transformed_hash = {} |
| 181 | + types_mapping.each_pair do |key, type| |
| 182 | + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? |
| 183 | + transformed_hash[key.to_sym] = nil |
| 184 | + elsif type =~ /\AArray<(.*)>/i |
| 185 | + # check to ensure the input is an array given that the attribute |
| 186 | + # is documented as an array but the input is not |
| 187 | + if attributes[attribute_map[key]].is_a?(Array) |
| 188 | + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| |
| 189 | + _deserialize(::Regexp.last_match(1), v) |
| 190 | + } |
| 191 | + end |
| 192 | + elsif !attributes[attribute_map[key]].nil? |
| 193 | + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + new(transformed_hash) |
| 198 | + end |
| 199 | + |
| 200 | + # Deserializes the data based on type |
| 201 | + # @param string type Data type |
| 202 | + # @param string value Value to be deserialized |
| 203 | + # @return [Object] Deserialized data |
| 204 | + def self._deserialize(type, value) |
| 205 | + case type.to_sym |
| 206 | + when :Time |
| 207 | + Time.parse(value) |
| 208 | + when :Date |
| 209 | + Date.parse(value) |
| 210 | + when :String |
| 211 | + value.to_s |
| 212 | + when :Integer |
| 213 | + value.to_i |
| 214 | + when :Float |
| 215 | + value.to_f |
| 216 | + when :Boolean |
| 217 | + if value.to_s =~ /\A(true|t|yes|y|1)\z/i |
| 218 | + true |
| 219 | + else |
| 220 | + false |
| 221 | + end |
| 222 | + |
| 223 | + when :Object |
| 224 | + # generic object (usually a Hash), return directly |
| 225 | + value |
| 226 | + when /\AArray<(?<inner_type>.+)>\z/ |
| 227 | + inner_type = Regexp.last_match[:inner_type] |
| 228 | + value.map { |v| _deserialize(inner_type, v) } |
| 229 | + when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/ |
| 230 | + k_type = Regexp.last_match[:k_type] |
| 231 | + v_type = Regexp.last_match[:v_type] |
| 232 | + {}.tap do |hash| |
| 233 | + value.each do |k, v| |
| 234 | + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) |
| 235 | + end |
| 236 | + end |
| 237 | + # model |
| 238 | + else |
| 239 | + # models (e.g. Pet) or oneOf |
| 240 | + klass = Algolia::AbtestingV3.const_get(type) |
| 241 | + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass |
| 242 | + .build_from_hash(value) |
| 243 | + end |
| 244 | + end |
| 245 | + |
| 246 | + # Returns the string representation of the object |
| 247 | + # @return [String] String presentation of the object |
| 248 | + def to_s |
| 249 | + to_hash.to_s |
| 250 | + end |
| 251 | + |
| 252 | + # to_body is an alias to to_hash (backward compatibility) |
| 253 | + # @return [Hash] Returns the object in the form of hash |
| 254 | + def to_body |
| 255 | + to_hash |
| 256 | + end |
| 257 | + |
| 258 | + def to_json(*_args) |
| 259 | + to_hash.to_json |
| 260 | + end |
| 261 | + |
| 262 | + # Returns the object in the form of hash |
| 263 | + # @return [Hash] Returns the object in the form of hash |
| 264 | + def to_hash |
| 265 | + hash = {} |
| 266 | + self.class.attribute_map.each_pair do |attr, param| |
| 267 | + value = send(attr) |
| 268 | + if value.nil? |
| 269 | + is_nullable = self.class.openapi_nullable.include?(attr) |
| 270 | + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) |
| 271 | + end |
| 272 | + |
| 273 | + hash[param] = _to_hash(value) |
| 274 | + end |
| 275 | + |
| 276 | + hash |
| 277 | + end |
| 278 | + |
| 279 | + # Outputs non-array value in the form of hash |
| 280 | + # For object, use to_hash. Otherwise, just return the value |
| 281 | + # @param [Object] value Any valid value |
| 282 | + # @return [Hash] Returns the value in the form of hash |
| 283 | + def _to_hash(value) |
| 284 | + if value.is_a?(Array) |
| 285 | + value.compact.map { |v| _to_hash(v) } |
| 286 | + elsif value.is_a?(Hash) |
| 287 | + {}.tap do |hash| |
| 288 | + value.each { |k, v| hash[k] = _to_hash(v) } |
| 289 | + end |
| 290 | + elsif value.respond_to?(:to_hash) |
| 291 | + value.to_hash |
| 292 | + else |
| 293 | + value |
| 294 | + end |
| 295 | + end |
| 296 | + |
| 297 | + end |
| 298 | + |
| 299 | + end |
| 300 | +end |
0 commit comments