klaviyo-api-sdk 14.0.0 → 14.0.1

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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +3 -3
  4. data/klaviyo-api-sdk.gemspec +1 -1
  5. data/lib/klaviyo-api-sdk/api/campaigns_api.rb +7 -7
  6. data/lib/klaviyo-api-sdk/api/coupons_api.rb +5 -5
  7. data/lib/klaviyo-api-sdk/api/events_api.rb +1 -1
  8. data/lib/klaviyo-api-sdk/api/lists_api.rb +1 -1
  9. data/lib/klaviyo-api-sdk/api/profiles_api.rb +6 -6
  10. data/lib/klaviyo-api-sdk/api/segments_api.rb +1 -1
  11. data/lib/klaviyo-api-sdk/api_client.rb +1 -1
  12. data/lib/klaviyo-api-sdk/models/ab_test_action_data_current_experiment.rb +2 -15
  13. data/lib/klaviyo-api-sdk/models/coupon_create_query_resource_object_attributes.rb +16 -5
  14. data/lib/klaviyo-api-sdk/models/coupon_update_query_resource_object_attributes.rb +16 -5
  15. data/lib/klaviyo-api-sdk/models/custom_timeframe.rb +2 -0
  16. data/lib/klaviyo-api-sdk/models/has_sms_marketing_subscribed_filters_inner.rb +2 -1
  17. data/lib/klaviyo-api-sdk/models/is_rcs_capable_enum.rb +35 -0
  18. data/lib/klaviyo-api-sdk/models/low_inventory_condition.rb +1 -1
  19. data/lib/klaviyo-api-sdk/models/low_inventory_condition_filter2.rb +117 -0
  20. data/lib/klaviyo-api-sdk/models/metric_property_condition.rb +1 -1
  21. data/lib/klaviyo-api-sdk/models/metric_property_condition_filter.rb +195 -87
  22. data/lib/klaviyo-api-sdk/models/metric_property_condition_filter2.rb +117 -0
  23. data/lib/klaviyo-api-sdk/models/price_drop_condition.rb +1 -1
  24. data/lib/klaviyo-api-sdk/models/price_drop_condition_filter2.rb +117 -0
  25. data/lib/klaviyo-api-sdk/models/subscribed_smsis_rcs_capable_filter.rb +237 -0
  26. data/lib/klaviyo-api-sdk.rb +6 -1
  27. data/lib/klaviyo-api-sdk.rb.bak +6 -1
  28. metadata +7 -2
@@ -0,0 +1,117 @@
1
+ =begin
2
+ #Klaviyo API
3
+
4
+ #The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
5
+
6
+ Contact: developers@klaviyo.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 6.2.1
9
+
10
+ =end
11
+
12
+ require 'date'
13
+ require 'time'
14
+
15
+ module KlaviyoAPI
16
+ module LowInventoryConditionFilter2
17
+ class << self
18
+ # List of class defined in oneOf (OpenAPI v3)
19
+ def openapi_one_of
20
+ [
21
+ :'AnniversaryDateFilter',
22
+ :'BooleanFilter',
23
+ :'CalendarDateFilter',
24
+ :'ExistenceOperatorFilter',
25
+ :'ListContainsOperatorFilter',
26
+ :'ListLengthFilter',
27
+ :'NumericOperatorFilter',
28
+ :'NumericRangeFilter',
29
+ :'RelativeAnniversaryDateFilter',
30
+ :'RelativeDateOperatorBaseFilter',
31
+ :'RelativeDateRangeFilter',
32
+ :'StaticDateFilter',
33
+ :'StaticDateRangeFilter',
34
+ :'StringArrayOperatorFilter',
35
+ :'StringOperatorFilter'
36
+ ]
37
+ end
38
+
39
+ # Builds the object
40
+ # @param [Mixed] Data to be matched against the list of oneOf items
41
+ # @return [Object] Returns the model or the data itself
42
+ def build(data)
43
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
44
+ # Note:
45
+ # - We do not attempt to check whether exactly one item matches.
46
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
47
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
48
+ # - TODO: scalar values are de facto behaving as if they were nullable.
49
+ # - TODO: logging when debugging is set.
50
+ openapi_one_of.each do |klass|
51
+ begin
52
+ next if klass == :AnyType # "nullable: true"
53
+ typed_data = find_and_cast_into_type(klass, data)
54
+ return typed_data if typed_data
55
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
56
+ end
57
+ end
58
+
59
+ openapi_one_of.include?(:AnyType) ? data : nil
60
+ end
61
+
62
+ private
63
+
64
+ SchemaMismatchError = Class.new(StandardError)
65
+
66
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
67
+ def find_and_cast_into_type(klass, data)
68
+ return if data.nil?
69
+
70
+ case klass.to_s
71
+ when 'Boolean'
72
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
73
+ when 'Float'
74
+ return data if data.instance_of?(Float)
75
+ when 'Integer'
76
+ return data if data.instance_of?(Integer)
77
+ when 'Time'
78
+ return Time.parse(data)
79
+ when 'Date'
80
+ return Date.parse(data)
81
+ when 'String'
82
+ return data if data.instance_of?(String)
83
+ when 'Object' # "type: object"
84
+ return data if data.instance_of?(Hash)
85
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
86
+ if data.instance_of?(Array)
87
+ sub_type = Regexp.last_match[:sub_type]
88
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
89
+ end
90
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
91
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
92
+ sub_type = Regexp.last_match[:sub_type]
93
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
94
+ end
95
+ else # model
96
+ const = KlaviyoAPI.const_get(klass)
97
+ if const
98
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
99
+ model = const.build(data)
100
+ return model if model
101
+ else
102
+ # raise if data contains keys that are not known to the model
103
+ raise unless (data.keys - const.acceptable_attributes).empty?
104
+ model = const.build_from_hash(data)
105
+ return model if model && model.valid?
106
+ end
107
+ end
108
+ end
109
+
110
+ raise # if no match by now, raise
111
+ rescue
112
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
113
+ end
114
+ end
115
+ end
116
+
117
+ end
@@ -43,7 +43,7 @@ module KlaviyoAPI
43
43
  :'type' => :'MetricPropertyEnum',
44
44
  :'metric_id' => :'String',
45
45
  :'field' => :'String',
46
- :'filter' => :'MetricPropertyConditionFilter'
46
+ :'filter' => :'MetricPropertyConditionFilter2'
47
47
  }
48
48
  end
49
49
 
@@ -13,105 +13,213 @@ require 'date'
13
13
  require 'time'
14
14
 
15
15
  module KlaviyoAPI
16
- module MetricPropertyConditionFilter
17
- class << self
18
- # List of class defined in oneOf (OpenAPI v3)
19
- def openapi_one_of
20
- [
21
- :'AnniversaryDateFilter',
22
- :'BooleanFilter',
23
- :'CalendarDateFilter',
24
- :'ExistenceOperatorFilter',
25
- :'ListContainsOperatorFilter',
26
- :'ListLengthFilter',
27
- :'NumericOperatorFilter',
28
- :'NumericRangeFilter',
29
- :'RelativeAnniversaryDateFilter',
30
- :'RelativeDateOperatorBaseFilter',
31
- :'RelativeDateRangeFilter',
32
- :'StaticDateFilter',
33
- :'StaticDateRangeFilter',
34
- :'StringArrayOperatorFilter',
35
- :'StringOperatorFilter'
36
- ]
16
+ class MetricPropertyConditionFilter
17
+ attr_accessor :condition_groups
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+ :'condition_groups' => :'condition_groups'
23
+ }
24
+ end
25
+
26
+ # Returns all the JSON keys this model knows about
27
+ def self.acceptable_attributes
28
+ attribute_map.values
29
+ end
30
+
31
+ # Attribute type mapping.
32
+ def self.openapi_types
33
+ {
34
+ :'condition_groups' => :'Array<MetricPropertyConditionGroup>'
35
+ }
36
+ end
37
+
38
+ # List of attributes with nullable: true
39
+ def self.openapi_nullable
40
+ Set.new([
41
+ ])
42
+ end
43
+
44
+ # Initializes the object
45
+ # @param [Hash] attributes Model attributes in the form of hash
46
+ def initialize(attributes = {})
47
+ if (!attributes.is_a?(Hash))
48
+ fail ArgumentError, "The input argument (attributes) must be a hash in `KlaviyoAPI::MetricPropertyConditionFilter` initialize method"
37
49
  end
38
50
 
39
- # Builds the object
40
- # @param [Mixed] Data to be matched against the list of oneOf items
41
- # @return [Object] Returns the model or the data itself
42
- def build(data)
43
- # Go through the list of oneOf items and attempt to identify the appropriate one.
44
- # Note:
45
- # - We do not attempt to check whether exactly one item matches.
46
- # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
47
- # due to the way the deserialization is made in the base_object template (it just casts without verifying).
48
- # - TODO: scalar values are de facto behaving as if they were nullable.
49
- # - TODO: logging when debugging is set.
50
- openapi_one_of.each do |klass|
51
- begin
52
- next if klass == :AnyType # "nullable: true"
53
- typed_data = find_and_cast_into_type(klass, data)
54
- return typed_data if typed_data
55
- rescue # rescue all errors so we keep iterating even if the current item lookup raises
56
- end
51
+ # check to see if the attribute exists and convert string to symbol for hash key
52
+ attributes = attributes.each_with_object({}) { |(k, v), h|
53
+ if (!self.class.attribute_map.key?(k.to_sym))
54
+ fail ArgumentError, "`#{k}` is not a valid attribute in `KlaviyoAPI::MetricPropertyConditionFilter`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
57
55
  end
56
+ h[k.to_sym] = v
57
+ }
58
58
 
59
- openapi_one_of.include?(:AnyType) ? data : nil
59
+ if attributes.key?(:'condition_groups')
60
+ if (value = attributes[:'condition_groups']).is_a?(Array)
61
+ self.condition_groups = value
62
+ end
60
63
  end
64
+ end
61
65
 
62
- private
63
-
64
- SchemaMismatchError = Class.new(StandardError)
65
-
66
- # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
67
- def find_and_cast_into_type(klass, data)
68
- return if data.nil?
69
-
70
- case klass.to_s
71
- when 'Boolean'
72
- return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
73
- when 'Float'
74
- return data if data.instance_of?(Float)
75
- when 'Integer'
76
- return data if data.instance_of?(Integer)
77
- when 'Time'
78
- return Time.parse(data)
79
- when 'Date'
80
- return Date.parse(data)
81
- when 'String'
82
- return data if data.instance_of?(String)
83
- when 'Object' # "type: object"
84
- return data if data.instance_of?(Hash)
85
- when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
86
- if data.instance_of?(Array)
87
- sub_type = Regexp.last_match[:sub_type]
88
- return data.map { |item| find_and_cast_into_type(sub_type, item) }
89
- end
90
- when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
91
- if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
92
- sub_type = Regexp.last_match[:sub_type]
93
- return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
66
+ # Show invalid properties with the reasons. Usually used together with valid?
67
+ # @return Array for valid properties with the reasons
68
+ def list_invalid_properties
69
+ invalid_properties = Array.new
70
+ if @condition_groups.nil?
71
+ invalid_properties.push('invalid value for "condition_groups", condition_groups cannot be nil.')
72
+ end
73
+
74
+ invalid_properties
75
+ end
76
+
77
+ # Check to see if the all the properties in the model are valid
78
+ # @return true if the model is valid
79
+ def valid?
80
+ return false if @condition_groups.nil?
81
+ true
82
+ end
83
+
84
+ # Checks equality by comparing each attribute.
85
+ # @param [Object] Object to be compared
86
+ def ==(o)
87
+ return true if self.equal?(o)
88
+ self.class == o.class &&
89
+ condition_groups == o.condition_groups
90
+ end
91
+
92
+ # @see the `==` method
93
+ # @param [Object] Object to be compared
94
+ def eql?(o)
95
+ self == o
96
+ end
97
+
98
+ # Calculates hash code according to all attributes.
99
+ # @return [Integer] Hash code
100
+ def hash
101
+ [condition_groups].hash
102
+ end
103
+
104
+ # Builds the object from hash
105
+ # @param [Hash] attributes Model attributes in the form of hash
106
+ # @return [Object] Returns the model itself
107
+ def self.build_from_hash(attributes)
108
+ new.build_from_hash(attributes)
109
+ end
110
+
111
+ # Builds the object from hash
112
+ # @param [Hash] attributes Model attributes in the form of hash
113
+ # @return [Object] Returns the model itself
114
+ def build_from_hash(attributes)
115
+ return nil unless attributes.is_a?(Hash)
116
+ attributes = attributes.transform_keys(&:to_sym)
117
+ self.class.openapi_types.each_pair do |key, type|
118
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
119
+ self.send("#{key}=", nil)
120
+ elsif type =~ /\AArray<(.*)>/i
121
+ # check to ensure the input is an array given that the attribute
122
+ # is documented as an array but the input is not
123
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
124
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
94
125
  end
95
- else # model
96
- const = KlaviyoAPI.const_get(klass)
97
- if const
98
- if const.respond_to?(:openapi_one_of) # nested oneOf model
99
- model = const.build(data)
100
- return model if model
101
- else
102
- # raise if data contains keys that are not known to the model
103
- raise unless (data.keys - const.acceptable_attributes).empty?
104
- model = const.build_from_hash(data)
105
- return model if model && model.valid?
106
- end
126
+ elsif !attributes[self.class.attribute_map[key]].nil?
127
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
128
+ end
129
+ end
130
+
131
+ self
132
+ end
133
+
134
+ # Deserializes the data based on type
135
+ # @param string type Data type
136
+ # @param string value Value to be deserialized
137
+ # @return [Object] Deserialized data
138
+ def _deserialize(type, value)
139
+ case type.to_sym
140
+ when :Time
141
+ Time.parse(value)
142
+ when :Date
143
+ Date.parse(value)
144
+ when :String
145
+ value.to_s
146
+ when :Integer
147
+ value.to_i
148
+ when :Float
149
+ value.to_f
150
+ when :Boolean
151
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
152
+ true
153
+ else
154
+ false
155
+ end
156
+ when :Object
157
+ # generic object (usually a Hash), return directly
158
+ value
159
+ when /\AArray<(?<inner_type>.+)>\z/
160
+ inner_type = Regexp.last_match[:inner_type]
161
+ value.map { |v| _deserialize(inner_type, v) }
162
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
163
+ k_type = Regexp.last_match[:k_type]
164
+ v_type = Regexp.last_match[:v_type]
165
+ {}.tap do |hash|
166
+ value.each do |k, v|
167
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
107
168
  end
108
169
  end
170
+ else # model
171
+ # models (e.g. Pet) or oneOf
172
+ klass = KlaviyoAPI.const_get(type)
173
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
174
+ end
175
+ end
109
176
 
110
- raise # if no match by now, raise
111
- rescue
112
- raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
177
+ # Returns the string representation of the object
178
+ # @return [String] String presentation of the object
179
+ def to_s
180
+ to_hash.to_s
181
+ end
182
+
183
+ # to_body is an alias to to_hash (backward compatibility)
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_body
186
+ to_hash
187
+ end
188
+
189
+ # Returns the object in the form of hash
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_hash
192
+ hash = {}
193
+ self.class.attribute_map.each_pair do |attr, param|
194
+ value = self.send(attr)
195
+ if value.nil?
196
+ is_nullable = self.class.openapi_nullable.include?(attr)
197
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
198
+ end
199
+
200
+ hash[param] = _to_hash(value)
113
201
  end
202
+ hash
114
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
+
115
223
  end
116
224
 
117
225
  end
@@ -0,0 +1,117 @@
1
+ =begin
2
+ #Klaviyo API
3
+
4
+ #The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
5
+
6
+ Contact: developers@klaviyo.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 6.2.1
9
+
10
+ =end
11
+
12
+ require 'date'
13
+ require 'time'
14
+
15
+ module KlaviyoAPI
16
+ module MetricPropertyConditionFilter2
17
+ class << self
18
+ # List of class defined in oneOf (OpenAPI v3)
19
+ def openapi_one_of
20
+ [
21
+ :'AnniversaryDateFilter',
22
+ :'BooleanFilter',
23
+ :'CalendarDateFilter',
24
+ :'ExistenceOperatorFilter',
25
+ :'ListContainsOperatorFilter',
26
+ :'ListLengthFilter',
27
+ :'NumericOperatorFilter',
28
+ :'NumericRangeFilter',
29
+ :'RelativeAnniversaryDateFilter',
30
+ :'RelativeDateOperatorBaseFilter',
31
+ :'RelativeDateRangeFilter',
32
+ :'StaticDateFilter',
33
+ :'StaticDateRangeFilter',
34
+ :'StringArrayOperatorFilter',
35
+ :'StringOperatorFilter'
36
+ ]
37
+ end
38
+
39
+ # Builds the object
40
+ # @param [Mixed] Data to be matched against the list of oneOf items
41
+ # @return [Object] Returns the model or the data itself
42
+ def build(data)
43
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
44
+ # Note:
45
+ # - We do not attempt to check whether exactly one item matches.
46
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
47
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
48
+ # - TODO: scalar values are de facto behaving as if they were nullable.
49
+ # - TODO: logging when debugging is set.
50
+ openapi_one_of.each do |klass|
51
+ begin
52
+ next if klass == :AnyType # "nullable: true"
53
+ typed_data = find_and_cast_into_type(klass, data)
54
+ return typed_data if typed_data
55
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
56
+ end
57
+ end
58
+
59
+ openapi_one_of.include?(:AnyType) ? data : nil
60
+ end
61
+
62
+ private
63
+
64
+ SchemaMismatchError = Class.new(StandardError)
65
+
66
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
67
+ def find_and_cast_into_type(klass, data)
68
+ return if data.nil?
69
+
70
+ case klass.to_s
71
+ when 'Boolean'
72
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
73
+ when 'Float'
74
+ return data if data.instance_of?(Float)
75
+ when 'Integer'
76
+ return data if data.instance_of?(Integer)
77
+ when 'Time'
78
+ return Time.parse(data)
79
+ when 'Date'
80
+ return Date.parse(data)
81
+ when 'String'
82
+ return data if data.instance_of?(String)
83
+ when 'Object' # "type: object"
84
+ return data if data.instance_of?(Hash)
85
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
86
+ if data.instance_of?(Array)
87
+ sub_type = Regexp.last_match[:sub_type]
88
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
89
+ end
90
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
91
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
92
+ sub_type = Regexp.last_match[:sub_type]
93
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
94
+ end
95
+ else # model
96
+ const = KlaviyoAPI.const_get(klass)
97
+ if const
98
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
99
+ model = const.build(data)
100
+ return model if model
101
+ else
102
+ # raise if data contains keys that are not known to the model
103
+ raise unless (data.keys - const.acceptable_attributes).empty?
104
+ model = const.build_from_hash(data)
105
+ return model if model && model.valid?
106
+ end
107
+ end
108
+ end
109
+
110
+ raise # if no match by now, raise
111
+ rescue
112
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
113
+ end
114
+ end
115
+ end
116
+
117
+ end
@@ -43,7 +43,7 @@ module KlaviyoAPI
43
43
  :'type' => :'PriceDropPropertyEnum',
44
44
  :'metric_id' => :'String',
45
45
  :'field' => :'String',
46
- :'filter' => :'MetricPropertyConditionFilter'
46
+ :'filter' => :'PriceDropConditionFilter2'
47
47
  }
48
48
  end
49
49
 
@@ -0,0 +1,117 @@
1
+ =begin
2
+ #Klaviyo API
3
+
4
+ #The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
5
+
6
+ Contact: developers@klaviyo.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 6.2.1
9
+
10
+ =end
11
+
12
+ require 'date'
13
+ require 'time'
14
+
15
+ module KlaviyoAPI
16
+ module PriceDropConditionFilter2
17
+ class << self
18
+ # List of class defined in oneOf (OpenAPI v3)
19
+ def openapi_one_of
20
+ [
21
+ :'AnniversaryDateFilter',
22
+ :'BooleanFilter',
23
+ :'CalendarDateFilter',
24
+ :'ExistenceOperatorFilter',
25
+ :'ListContainsOperatorFilter',
26
+ :'ListLengthFilter',
27
+ :'NumericOperatorFilter',
28
+ :'NumericRangeFilter',
29
+ :'RelativeAnniversaryDateFilter',
30
+ :'RelativeDateOperatorBaseFilter',
31
+ :'RelativeDateRangeFilter',
32
+ :'StaticDateFilter',
33
+ :'StaticDateRangeFilter',
34
+ :'StringArrayOperatorFilter',
35
+ :'StringOperatorFilter'
36
+ ]
37
+ end
38
+
39
+ # Builds the object
40
+ # @param [Mixed] Data to be matched against the list of oneOf items
41
+ # @return [Object] Returns the model or the data itself
42
+ def build(data)
43
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
44
+ # Note:
45
+ # - We do not attempt to check whether exactly one item matches.
46
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
47
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
48
+ # - TODO: scalar values are de facto behaving as if they were nullable.
49
+ # - TODO: logging when debugging is set.
50
+ openapi_one_of.each do |klass|
51
+ begin
52
+ next if klass == :AnyType # "nullable: true"
53
+ typed_data = find_and_cast_into_type(klass, data)
54
+ return typed_data if typed_data
55
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
56
+ end
57
+ end
58
+
59
+ openapi_one_of.include?(:AnyType) ? data : nil
60
+ end
61
+
62
+ private
63
+
64
+ SchemaMismatchError = Class.new(StandardError)
65
+
66
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
67
+ def find_and_cast_into_type(klass, data)
68
+ return if data.nil?
69
+
70
+ case klass.to_s
71
+ when 'Boolean'
72
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
73
+ when 'Float'
74
+ return data if data.instance_of?(Float)
75
+ when 'Integer'
76
+ return data if data.instance_of?(Integer)
77
+ when 'Time'
78
+ return Time.parse(data)
79
+ when 'Date'
80
+ return Date.parse(data)
81
+ when 'String'
82
+ return data if data.instance_of?(String)
83
+ when 'Object' # "type: object"
84
+ return data if data.instance_of?(Hash)
85
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
86
+ if data.instance_of?(Array)
87
+ sub_type = Regexp.last_match[:sub_type]
88
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
89
+ end
90
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
91
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
92
+ sub_type = Regexp.last_match[:sub_type]
93
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
94
+ end
95
+ else # model
96
+ const = KlaviyoAPI.const_get(klass)
97
+ if const
98
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
99
+ model = const.build(data)
100
+ return model if model
101
+ else
102
+ # raise if data contains keys that are not known to the model
103
+ raise unless (data.keys - const.acceptable_attributes).empty?
104
+ model = const.build_from_hash(data)
105
+ return model if model && model.valid?
106
+ end
107
+ end
108
+ end
109
+
110
+ raise # if no match by now, raise
111
+ rescue
112
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
113
+ end
114
+ end
115
+ end
116
+
117
+ end