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