=begin #Commerce Platform API #RESTful API for the creation of Commerce Cases with Checkouts and the execution of Payments. The version of the OpenAPI document: 1.8.0 Generated by: https://openapi-generator.tech Generator version: 7.7.0 =end require 'date' require 'time' module PCPServerSDK # Object containing billing address details class Address # Second line of street or additional address information such as apartments and suits attr_accessor :additional_info # City attr_accessor :city # ISO 3166-1 alpha-2 country code attr_accessor :country_code # House number attr_accessor :house_number # State (ISO 3166-2 subdivisions), only if country=US, CA, CN, JP, MX, BR, AR, ID, TH, IN. attr_accessor :state # Street name attr_accessor :street # Zip code attr_accessor :zip # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { :'additional_info' => :'additionalInfo', :'city' => :'city', :'country_code' => :'countryCode', :'house_number' => :'houseNumber', :'state' => :'state', :'street' => :'street', :'zip' => :'zip' } end # Returns all the JSON keys this model knows about def self.acceptable_attributes attribute_map.values end # Attribute type mapping. def self.openapi_types { :'additional_info' => :'String', :'city' => :'String', :'country_code' => :'String', :'house_number' => :'String', :'state' => :'String', :'street' => :'String', :'zip' => :'String' } end # List of attributes with nullable: true def self.openapi_nullable Set.new([ ]) end # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) if (!attributes.is_a?(Hash)) fail ArgumentError, "The input argument (attributes) must be a hash in `PCPServerSDK::Address` initialize method" end # check to see if the attribute exists and convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| if (!self.class.attribute_map.key?(k.to_sym)) fail ArgumentError, "`#{k}` is not a valid attribute in `PCPServerSDK::Address`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect end h[k.to_sym] = v } if attributes.key?(:'additional_info') self.additional_info = attributes[:'additional_info'] end if attributes.key?(:'city') self.city = attributes[:'city'] end if attributes.key?(:'country_code') self.country_code = attributes[:'country_code'] end if attributes.key?(:'house_number') self.house_number = attributes[:'house_number'] end if attributes.key?(:'state') self.state = attributes[:'state'] end if attributes.key?(:'street') self.street = attributes[:'street'] end if attributes.key?(:'zip') self.zip = attributes[:'zip'] end end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new if !@additional_info.nil? && @additional_info.to_s.length > 50 invalid_properties.push('invalid value for "additional_info", the character length must be smaller than or equal to 50.') end if !@city.nil? && @city.to_s.length > 40 invalid_properties.push('invalid value for "city", the character length must be smaller than or equal to 40.') end if !@city.nil? && @city.to_s.length < 2 invalid_properties.push('invalid value for "city", the character length must be great than or equal to 2.') end if !@country_code.nil? && @country_code.to_s.length > 2 invalid_properties.push('invalid value for "country_code", the character length must be smaller than or equal to 2.') end pattern = Regexp.new(/^[a-zA-Z]{2}$/) if !@country_code.nil? && @country_code !~ pattern invalid_properties.push("invalid value for \"country_code\", must conform to the pattern #{pattern}.") end if !@house_number.nil? && @house_number.to_s.length > 10 invalid_properties.push('invalid value for "house_number", the character length must be smaller than or equal to 10.') end if !@state.nil? && @state.to_s.length > 3 invalid_properties.push('invalid value for "state", the character length must be smaller than or equal to 3.') end if !@state.nil? && @state.to_s.length < 1 invalid_properties.push('invalid value for "state", the character length must be great than or equal to 1.') end pattern = Regexp.new(/^[a-zA-Z0-9]{1,3}$/) if !@state.nil? && @state !~ pattern invalid_properties.push("invalid value for \"state\", must conform to the pattern #{pattern}.") end if !@street.nil? && @street.to_s.length > 50 invalid_properties.push('invalid value for "street", the character length must be smaller than or equal to 50.') end if !@zip.nil? && @zip.to_s.length > 10 invalid_properties.push('invalid value for "zip", the character length must be smaller than or equal to 10.') end if !@zip.nil? && @zip.to_s.length < 2 invalid_properties.push('invalid value for "zip", the character length must be great than or equal to 2.') end invalid_properties end # Check to see if the all the properties in the model are valid # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' return false if !@additional_info.nil? && @additional_info.to_s.length > 50 return false if !@city.nil? && @city.to_s.length > 40 return false if !@city.nil? && @city.to_s.length < 2 return false if !@country_code.nil? && @country_code.to_s.length > 2 return false if !@country_code.nil? && @country_code !~ Regexp.new(/^[a-zA-Z]{2}$/) return false if !@house_number.nil? && @house_number.to_s.length > 10 return false if !@state.nil? && @state.to_s.length > 3 return false if !@state.nil? && @state.to_s.length < 1 return false if !@state.nil? && @state !~ Regexp.new(/^[a-zA-Z0-9]{1,3}$/) return false if !@street.nil? && @street.to_s.length > 50 return false if !@zip.nil? && @zip.to_s.length > 10 return false if !@zip.nil? && @zip.to_s.length < 2 true end # Custom attribute writer method with validation # @param [Object] additional_info Value to be assigned def additional_info=(additional_info) if additional_info.nil? fail ArgumentError, 'additional_info cannot be nil' end if additional_info.to_s.length > 50 fail ArgumentError, 'invalid value for "additional_info", the character length must be smaller than or equal to 50.' end @additional_info = additional_info end # Custom attribute writer method with validation # @param [Object] city Value to be assigned def city=(city) if city.nil? fail ArgumentError, 'city cannot be nil' end if city.to_s.length > 40 fail ArgumentError, 'invalid value for "city", the character length must be smaller than or equal to 40.' end if city.to_s.length < 2 fail ArgumentError, 'invalid value for "city", the character length must be great than or equal to 2.' end @city = city end # Custom attribute writer method with validation # @param [Object] country_code Value to be assigned def country_code=(country_code) if country_code.nil? fail ArgumentError, 'country_code cannot be nil' end if country_code.to_s.length > 2 fail ArgumentError, 'invalid value for "country_code", the character length must be smaller than or equal to 2.' end pattern = Regexp.new(/^[a-zA-Z]{2}$/) if country_code !~ pattern fail ArgumentError, "invalid value for \"country_code\", must conform to the pattern #{pattern}." end @country_code = country_code end # Custom attribute writer method with validation # @param [Object] house_number Value to be assigned def house_number=(house_number) if house_number.nil? fail ArgumentError, 'house_number cannot be nil' end if house_number.to_s.length > 10 fail ArgumentError, 'invalid value for "house_number", the character length must be smaller than or equal to 10.' end @house_number = house_number end # Custom attribute writer method with validation # @param [Object] state Value to be assigned def state=(state) if state.nil? fail ArgumentError, 'state cannot be nil' end if state.to_s.length > 3 fail ArgumentError, 'invalid value for "state", the character length must be smaller than or equal to 3.' end if state.to_s.length < 1 fail ArgumentError, 'invalid value for "state", the character length must be great than or equal to 1.' end pattern = Regexp.new(/^[a-zA-Z0-9]{1,3}$/) if state !~ pattern fail ArgumentError, "invalid value for \"state\", must conform to the pattern #{pattern}." end @state = state end # Custom attribute writer method with validation # @param [Object] street Value to be assigned def street=(street) if street.nil? fail ArgumentError, 'street cannot be nil' end if street.to_s.length > 50 fail ArgumentError, 'invalid value for "street", the character length must be smaller than or equal to 50.' end @street = street end # Custom attribute writer method with validation # @param [Object] zip Value to be assigned def zip=(zip) if zip.nil? fail ArgumentError, 'zip cannot be nil' end if zip.to_s.length > 10 fail ArgumentError, 'invalid value for "zip", the character length must be smaller than or equal to 10.' end if zip.to_s.length < 2 fail ArgumentError, 'invalid value for "zip", the character length must be great than or equal to 2.' end @zip = zip end # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) self.class == o.class && additional_info == o.additional_info && city == o.city && country_code == o.country_code && house_number == o.house_number && state == o.state && street == o.street && zip == o.zip end # @see the `==` method # @param [Object] Object to be compared def eql?(o) self == o end # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash [additional_info, city, country_code, house_number, state, street, zip].hash end # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) transformed_hash = {} openapi_types.each_pair do |key, type| if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not if attributes[attribute_map[key]].is_a?(Array) transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } end elsif !attributes[attribute_map[key]].nil? transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) end end new(transformed_hash) end # Deserializes the data based on type # @param string type Data type # @param string value Value to be deserialized # @return [Object] Deserialized data def self._deserialize(type, value) case type.to_sym when :Time Time.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f when :Boolean if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else false end when :Object # generic object (usually a Hash), return directly value when /\AArray<(?.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?.+?), (?.+)>\z/ k_type = Regexp.last_match[:k_type] v_type = Regexp.last_match[:v_type] {}.tap do |hash| value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model # models (e.g. Pet) or oneOf klass = PCPServerSDK.const_get(type) klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) end end # Returns the string representation of the object # @return [String] String presentation of the object def to_s to_hash.to_s end # to_body is an alias to to_hash (backward compatibility) # @return [Hash] Returns the object in the form of hash def to_body to_hash end # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? is_nullable = self.class.openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end hash[param] = _to_hash(value) end hash end # Outputs non-array value in the form of hash # For object, use to_hash. Otherwise, just return the value # @param [Object] value Any valid value # @return [Hash] Returns the value in the form of hash def _to_hash(value) if value.is_a?(Array) value.compact.map { |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end end end