lib/ultracart_api/models/coupon.rb in ultracart_api-3.10.144 vs lib/ultracart_api/models/coupon.rb in ultracart_api-3.10.145
- old
+ new
@@ -163,10 +163,32 @@
attr_accessor :tiered_percent_off_subtotal_based_on_msrp
# Who may use this coupon.
attr_accessor :usable_by
+ class EnumAttributeValidator
+ attr_reader :datatype
+ attr_reader :allowable_values
+
+ def initialize(datatype, allowable_values)
+ @allowable_values = allowable_values.map do |value|
+ case datatype.to_s
+ when /Integer/i
+ value.to_i
+ when /Float/i
+ value.to_f
+ else
+ value
+ end
+ end
+ end
+
+ def valid?(value)
+ !value || allowable_values.include?(value)
+ end
+ end
+
# Attribute mapping from ruby-style variable name to JSON key.
def self.attribute_map
{
:'affiliate_oid' => :'affiliate_oid',
:'allow_multiple_one_time_codes' => :'allow_multiple_one_time_codes',
@@ -625,10 +647,12 @@
return false if !@coupon_type.nil? && @coupon_type.to_s.length > 65
return false if !@description.nil? && @description.to_s.length > 50
return false if !@merchant_code.nil? && @merchant_code.to_s.length > 20
return false if !@merchant_notes.nil? && @merchant_notes.to_s.length > 250
return false if !@quickbooks_code.nil? && @quickbooks_code.to_s.length > 20
+ usable_by_validator = EnumAttributeValidator.new('String', ['Anyone', 'UniqueCode', 'OncePerCustomer', 'OncePerNewCustomer', 'OncePerNewCustomerForItem'])
+ return false unless usable_by_validator.valid?(@usable_by)
return false if !@usable_by.nil? && @usable_by.to_s.length > 50
true
end
# Custom attribute writer method with validation
@@ -679,16 +703,16 @@
end
@quickbooks_code = quickbooks_code
end
- # Custom attribute writer method with validation
- # @param [Object] usable_by Value to be assigned
+ # Custom attribute writer method checking allowed values (enum).
+ # @param [Object] usable_by Object to be assigned
def usable_by=(usable_by)
- if !usable_by.nil? && usable_by.to_s.length > 50
- fail ArgumentError, 'invalid value for "usable_by", the character length must be smaller than or equal to 50.'
+ validator = EnumAttributeValidator.new('String', ['Anyone', 'UniqueCode', 'OncePerCustomer', 'OncePerNewCustomer', 'OncePerNewCustomerForItem'])
+ unless validator.valid?(usable_by)
+ fail ArgumentError, 'invalid value for "usable_by", must be one of #{validator.allowable_values}.'
end
-
@usable_by = usable_by
end
# Checks equality by comparing each attribute.
# @param [Object] Object to be compared