From ba2a9fa12fa6146911e3e90674bab4e8fbcb6070 Mon Sep 17 00:00:00 2001 From: Michel Perez Date: Fri, 23 Feb 2024 17:35:20 -0500 Subject: [PATCH] changing address model valitadion --- docs/Address.md | 89 ++- docs/CountryExtendedExpandedNoUs.md | 15 + docs/IntlAddress.md | 54 ++ docs/UsAddress.md | 54 ++ lib/openapi_client/models/address.rb | 663 ++---------------- .../models/country_extended_expanded_no_us.rb | 254 +++++++ lib/openapi_client/models/intl_address.rb | 624 +++++++++++++++++ lib/openapi_client/models/us_address.rb | 644 +++++++++++++++++ lib/openapi_client/version.rb | 2 +- 9 files changed, 1765 insertions(+), 634 deletions(-) mode change 100755 => 100644 docs/Address.md create mode 100644 docs/CountryExtendedExpandedNoUs.md create mode 100644 docs/IntlAddress.md create mode 100644 docs/UsAddress.md mode change 100755 => 100644 lib/openapi_client/models/address.rb create mode 100644 lib/openapi_client/models/country_extended_expanded_no_us.rb create mode 100644 lib/openapi_client/models/intl_address.rb create mode 100644 lib/openapi_client/models/us_address.rb diff --git a/docs/Address.md b/docs/Address.md old mode 100755 new mode 100644 index 6849a72..1e0ca60 --- a/docs/Address.md +++ b/docs/Address.md @@ -1,52 +1,49 @@ # Lob::Address -## Properties - -| Name | Type | Description | Notes | -| ---- | ---- | ----------- | ----- | -| **id** | **String** | Unique identifier prefixed with `adr_`. | [optional] | -| **description** | **String** | An internal description that identifies this resource. Must be no longer than 255 characters. | [optional] | -| **name** | **String** | name associated with address | [optional] | -| **company** | **String** | Either `name` or `company` is required, you may also add both. | [optional] | -| **phone** | **String** | Must be no longer than 40 characters. | [optional] | -| **email** | **String** | Must be no longer than 100 characters. | [optional] | -| **metadata** | **Hash<String, String>** | Use metadata to store custom information for tagging and labeling back to your internal systems. Must be an object with up to 20 key-value pairs. Keys must be at most 40 characters and values must be at most 500 characters. Neither can contain the characters `\"` and `\\`. i.e. '{\"customer_id\" : \"NEWYORK2015\"}' Nested objects are not supported. See [Metadata](#section/Metadata) for more information. | [optional] | -| **address_line1** | **String** | | [optional] | -| **address_line2** | **String** | | [optional] | -| **address_city** | **String** | | [optional] | -| **address_state** | **String** | 2 letter state short-name code | [optional] | -| **address_zip** | **String** | Must follow the ZIP format of `12345` or ZIP+4 format of `12345-1234`. | [optional] | -| **address_country** | [**CountryExtendedExpanded**](CountryExtendedExpanded.md) | | [optional] | -| **object** | **String** | | [optional][default to 'address'] | -| **date_created** | **Time** | A timestamp in ISO 8601 format of the date the resource was created. | [optional] | -| **date_modified** | **Time** | A timestamp in ISO 8601 format of the date the resource was last modified. | [optional] | -| **deleted** | **Boolean** | Only returned if the resource has been successfully deleted. | [optional] | -| **recipient_moved** | **Boolean** | Only returned for accounts on certain <a href=\"https://dashboard.lob.com/#/settings/editions\">Print &amp; Mail Editions</a>. Value is `true` if the address was altered because the recipient filed for a <a href=\"#ncoa\">National Change of Address (NCOA)</a>, `false` if the NCOA check was run but no altered address was found, and `null` if the NCOA check was not run. The NCOA check does not happen for non-US addresses, for non-deliverable US addresses, or for addresses created before the NCOA feature was added to your account. | [optional] | - -## Example +## Class instance methods + +### `openapi_one_of` + +Returns the list of classes defined in oneOf. + +#### Example + +```ruby +require 'lob' + +Lob::Address.openapi_one_of +# => +# [ +# :'IntlAddress', +# :'UsAddress' +# ] +``` + +### build + +Find the appropriate object from the `openapi_one_of` list and casts the data into it. + +#### Example ```ruby -require 'openapi_client' - -instance = Lob::Address.new( - id: null, - description: null, - name: null, - company: null, - phone: null, - email: null, - metadata: null, - address_line1: null, - address_line2: null, - address_city: null, - address_state: null, - address_zip: null, - address_country: null, - object: null, - date_created: null, - date_modified: null, - deleted: null, - recipient_moved: null -) +require 'lob' + +Lob::Address.build(data) +# => # + +Lob::Address.build(data_that_doesnt_match) +# => nil ``` +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| **data** | **Mixed** | data to be matched against the list of oneOf items | + +#### Return type + +- `IntlAddress` +- `UsAddress` +- `nil` (if no type matches) + diff --git a/docs/CountryExtendedExpandedNoUs.md b/docs/CountryExtendedExpandedNoUs.md new file mode 100644 index 0000000..5299a4a --- /dev/null +++ b/docs/CountryExtendedExpandedNoUs.md @@ -0,0 +1,15 @@ +# Lob::CountryExtendedExpandedNoUs + +## Properties + +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | + +## Example + +```ruby +require 'lob' + +instance = Lob::CountryExtendedExpandedNoUs.new() +``` + diff --git a/docs/IntlAddress.md b/docs/IntlAddress.md new file mode 100644 index 0000000..344e474 --- /dev/null +++ b/docs/IntlAddress.md @@ -0,0 +1,54 @@ +# Lob::IntlAddress + +## Properties + +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | +| **id** | **String** | Unique identifier prefixed with `adr_`. | [optional] | +| **description** | **String** | An internal description that identifies this resource. Must be no longer than 255 characters. | [optional] | +| **name** | **String** | name associated with address | [optional] | +| **company** | **String** | Either `name` or `company` is required, you may also add both. | [optional] | +| **phone** | **String** | Must be no longer than 40 characters. | [optional] | +| **email** | **String** | Must be no longer than 100 characters. | [optional] | +| **metadata** | **Hash<String, String>** | Use metadata to store custom information for tagging and labeling back to your internal systems. Must be an object with up to 20 key-value pairs. Keys must be at most 40 characters and values must be at most 500 characters. Neither can contain the characters `\"` and `\\`. i.e. '{\"customer_id\" : \"NEWYORK2015\"}' Nested objects are not supported. See [Metadata](#section/Metadata) for more information. | [optional] | +| **address_line1** | **String** | | [optional] | +| **address_line2** | **String** | | [optional] | +| **address_city** | **String** | | [optional] | +| **address_state** | **String** | 2 letter state short-name code | [optional] | +| **address_zip** | **String** | Must have a maximum of 12 characters | [optional] | +| **address_country** | [**CountryExtendedExpandedNoUs**](CountryExtendedExpandedNoUs.md) | | [optional] | +| **object** | **String** | | [optional][default to 'address'] | +| **date_created** | **Time** | A timestamp in ISO 8601 format of the date the resource was created. | [optional] | +| **date_modified** | **Time** | A timestamp in ISO 8601 format of the date the resource was last modified. | [optional] | +| **deleted** | **Boolean** | Only returned if the resource has been successfully deleted. | [optional] | +| **inline** | **Boolean** | Checks if address id is used or not | [optional] | +| **recipient_moved** | **Boolean** | Only returned for accounts on certain <a href=\"https://dashboard.lob.com/#/settings/editions\">Print &amp; Mail Editions</a>. Value is `true` if the address was altered because the recipient filed for a <a href=\"#ncoa\">National Change of Address (NCOA)</a>, `false` if the NCOA check was run but no altered address was found, and `null` if the NCOA check was not run. The NCOA check does not happen for non-US addresses, for non-deliverable US addresses, or for addresses created before the NCOA feature was added to your account. | [optional] | + +## Example + +```ruby +require 'lob' + +instance = Lob::IntlAddress.new( + id: null, + description: null, + name: null, + company: null, + phone: null, + email: null, + metadata: null, + address_line1: null, + address_line2: null, + address_city: null, + address_state: null, + address_zip: null, + address_country: null, + object: null, + date_created: null, + date_modified: null, + deleted: null, + inline: null, + recipient_moved: null +) +``` + diff --git a/docs/UsAddress.md b/docs/UsAddress.md new file mode 100644 index 0000000..d301ae2 --- /dev/null +++ b/docs/UsAddress.md @@ -0,0 +1,54 @@ +# Lob::UsAddress + +## Properties + +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | +| **id** | **String** | Unique identifier prefixed with `adr_`. | [optional] | +| **description** | **String** | An internal description that identifies this resource. Must be no longer than 255 characters. | [optional] | +| **name** | **String** | name associated with address | [optional] | +| **company** | **String** | Either `name` or `company` is required, you may also add both. | [optional] | +| **phone** | **String** | Must be no longer than 40 characters. | [optional] | +| **email** | **String** | Must be no longer than 100 characters. | [optional] | +| **metadata** | **Hash<String, String>** | Use metadata to store custom information for tagging and labeling back to your internal systems. Must be an object with up to 20 key-value pairs. Keys must be at most 40 characters and values must be at most 500 characters. Neither can contain the characters `\"` and `\\`. i.e. '{\"customer_id\" : \"NEWYORK2015\"}' Nested objects are not supported. See [Metadata](#section/Metadata) for more information. | [optional] | +| **address_line1** | **String** | | [optional] | +| **address_line2** | **String** | | [optional] | +| **address_city** | **String** | | [optional] | +| **address_state** | **String** | 2 letter state short-name code | [optional] | +| **address_zip** | **String** | Must follow the ZIP format of `12345` or ZIP+4 format of `12345-1234`. | [optional] | +| **address_country** | **String** | Full name of country | [optional] | +| **object** | **String** | | [optional][default to 'address'] | +| **date_created** | **Time** | A timestamp in ISO 8601 format of the date the resource was created. | [optional] | +| **date_modified** | **Time** | A timestamp in ISO 8601 format of the date the resource was last modified. | [optional] | +| **deleted** | **Boolean** | Only returned if the resource has been successfully deleted. | [optional] | +| **inline** | **Boolean** | Checks if address id is used or not | [optional] | +| **recipient_moved** | **Boolean** | Only returned for accounts on certain <a href=\"https://dashboard.lob.com/#/settings/editions\">Print &amp; Mail Editions</a>. Value is `true` if the address was altered because the recipient filed for a <a href=\"#ncoa\">National Change of Address (NCOA)</a>, `false` if the NCOA check was run but no altered address was found, and `null` if the NCOA check was not run. The NCOA check does not happen for non-US addresses, for non-deliverable US addresses, or for addresses created before the NCOA feature was added to your account. | [optional] | + +## Example + +```ruby +require 'lob' + +instance = Lob::UsAddress.new( + id: null, + description: null, + name: null, + company: null, + phone: null, + email: null, + metadata: null, + address_line1: null, + address_line2: null, + address_city: null, + address_state: null, + address_zip: null, + address_country: null, + object: null, + date_created: null, + date_modified: null, + deleted: null, + inline: null, + recipient_moved: null +) +``` + diff --git a/lib/openapi_client/models/address.rb b/lib/openapi_client/models/address.rb old mode 100755 new mode 100644 index 2f07124..8296fcd --- a/lib/openapi_client/models/address.rb +++ b/lib/openapi_client/models/address.rb @@ -14,603 +14,92 @@ require 'time' module Lob - class Address - # Unique identifier prefixed with `adr_`. - attr_accessor :id - - # An internal description that identifies this resource. Must be no longer than 255 characters. - attr_accessor :description - - # name associated with address - attr_accessor :name - - # Either `name` or `company` is required, you may also add both. - attr_accessor :company - - # Must be no longer than 40 characters. - attr_accessor :phone - - # Must be no longer than 100 characters. - attr_accessor :email - - # Use metadata to store custom information for tagging and labeling back to your internal systems. Must be an object with up to 20 key-value pairs. Keys must be at most 40 characters and values must be at most 500 characters. Neither can contain the characters `\"` and `\\`. i.e. '{\"customer_id\" : \"NEWYORK2015\"}' Nested objects are not supported. See [Metadata](#section/Metadata) for more information. - attr_accessor :metadata - - attr_accessor :address_line1 - - attr_accessor :address_line2 - - attr_accessor :address_city - - # 2 letter state short-name code - attr_accessor :address_state - - # Must follow the ZIP format of `12345` or ZIP+4 format of `12345-1234`. - attr_accessor :address_zip - - attr_accessor :address_country - - attr_accessor :object - - # A timestamp in ISO 8601 format of the date the resource was created. - attr_accessor :date_created - - # A timestamp in ISO 8601 format of the date the resource was last modified. - attr_accessor :date_modified - - # Only returned if the resource has been successfully deleted. - attr_accessor :deleted - - # Only returned for accounts on certain Print & Mail Editions. Value is `true` if the address was altered because the recipient filed for a National Change of Address (NCOA), `false` if the NCOA check was run but no altered address was found, and `null` if the NCOA check was not run. The NCOA check does not happen for non-US addresses, for non-deliverable US addresses, or for addresses created before the NCOA feature was added to your account. - attr_accessor :recipient_moved - - 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 + module Address + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :'IntlAddress', + :'UsAddress' + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + next if klass == :AnyType # "nullable: true" + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + rescue # rescue all errors so we keep iterating even if the current item lookup raises 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 - { - :'id' => :'id', - :'description' => :'description', - :'name' => :'name', - :'company' => :'company', - :'phone' => :'phone', - :'email' => :'email', - :'metadata' => :'metadata', - :'address_line1' => :'address_line1', - :'address_line2' => :'address_line2', - :'address_city' => :'address_city', - :'address_state' => :'address_state', - :'address_zip' => :'address_zip', - :'address_country' => :'address_country', - :'object' => :'object', - :'date_created' => :'date_created', - :'date_modified' => :'date_modified', - :'deleted' => :'deleted', - :'recipient_moved' => :'recipient_moved' - } - 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 - { - :'id' => :'String', - :'description' => :'String', - :'name' => :'String', - :'company' => :'String', - :'phone' => :'String', - :'email' => :'String', - :'metadata' => :'Hash', - :'address_line1' => :'String', - :'address_line2' => :'String', - :'address_city' => :'String', - :'address_state' => :'String', - :'address_zip' => :'String', - :'address_country' => :'CountryExtendedExpanded', - :'object' => :'String', - :'date_created' => :'Time', - :'date_modified' => :'Time', - :'deleted' => :'Boolean', - :'recipient_moved' => :'Boolean' - } - end - - # List of attributes with nullable: true - def self.openapi_nullable - Set.new([ - :'description', - :'name', - :'company', - :'phone', - :'email', - :'address_line2', - :'recipient_moved' - ]) - 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 `Lob::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 `Lob::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?(:'id') - self.id = attributes[:'id'] - end - - if attributes.key?(:'description') - self.description = attributes[:'description'] - end - - if attributes.key?(:'name') - self.name = attributes[:'name'] - end - - if attributes.key?(:'company') - self.company = attributes[:'company'] - end - - if attributes.key?(:'phone') - self.phone = attributes[:'phone'] - end - - if attributes.key?(:'email') - self.email = attributes[:'email'] - end - - if attributes.key?(:'metadata') - if (value = attributes[:'metadata']).is_a?(Hash) - self.metadata = value - end - end - - if attributes.key?(:'address_line1') - self.address_line1 = attributes[:'address_line1'] - end - - if attributes.key?(:'address_line2') - self.address_line2 = attributes[:'address_line2'] - end - - if attributes.key?(:'address_city') - self.address_city = attributes[:'address_city'] - end - - if attributes.key?(:'address_state') - self.address_state = attributes[:'address_state'] - end - - if attributes.key?(:'address_zip') - self.address_zip = attributes[:'address_zip'] - end - - if attributes.key?(:'address_country') - self.address_country = attributes[:'address_country'] - end - - if attributes.key?(:'object') - self.object = attributes[:'object'] - else - self.object = 'address' - end - - if attributes.key?(:'date_created') - self.date_created = attributes[:'date_created'] - end - - if attributes.key?(:'date_modified') - self.date_modified = attributes[:'date_modified'] - end - - if attributes.key?(:'deleted') - self.deleted = attributes[:'deleted'] - end - - if attributes.key?(:'recipient_moved') - self.recipient_moved = attributes[:'recipient_moved'] - 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 - invalid_properties = Array.new - pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/) - if !@id.nil? && @id !~ pattern - invalid_properties.push("invalid value for \"id\", must conform to the pattern #{pattern}.") - end - - if !@description.nil? && @description.to_s.length > 255 - invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 255.') - end - - if !@name.nil? && @name.to_s.length > 40 - invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 40.') - end - - if !@company.nil? && @company.to_s.length > 40 - invalid_properties.push('invalid value for "company", the character length must be smaller than or equal to 40.') - end - - if !@phone.nil? && @phone.to_s.length > 40 - invalid_properties.push('invalid value for "phone", the character length must be smaller than or equal to 40.') - end - - if !@email.nil? && @email.to_s.length > 100 - invalid_properties.push('invalid value for "email", the character length must be smaller than or equal to 100.') - end - - if !@address_line1.nil? && @address_line1.to_s.length > 64 - invalid_properties.push('invalid value for "address_line1", the character length must be smaller than or equal to 64.') - end - - if !@address_line2.nil? && @address_line2.to_s.length > 64 - invalid_properties.push('invalid value for "address_line2", the character length must be smaller than or equal to 64.') - end - if !@address_city.nil? && @address_city.to_s.length > 200 - invalid_properties.push('invalid value for "address_city", the character length must be smaller than or equal to 200.') - end - - pattern = Regexp.new(/^[a-zA-Z]{2}$/) - if !@address_state.nil? && @address_state !~ pattern - invalid_properties.push("invalid value for \"address_state\", must conform to the pattern #{pattern}.") - end - - pattern = Regexp.new(/^\d{5}(-\d{4})?$/) - if !@address_zip.nil? && @address_zip !~ pattern - invalid_properties.push("invalid value for \"address_zip\", must conform to the pattern #{pattern}.") - 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? - return false if !@id.nil? && @id !~ Regexp.new(/^adr_[a-zA-Z0-9]+$/) - return false if !@description.nil? && @description.to_s.length > 255 - return false if !@name.nil? && @name.to_s.length > 40 - return false if !@company.nil? && @company.to_s.length > 40 - return false if !@phone.nil? && @phone.to_s.length > 40 - return false if !@email.nil? && @email.to_s.length > 100 - return false if !@address_line1.nil? && @address_line1.to_s.length > 64 - return false if !@address_line2.nil? && @address_line2.to_s.length > 64 - return false if !@address_city.nil? && @address_city.to_s.length > 200 - return false if !@address_state.nil? && @address_state !~ Regexp.new(/^[a-zA-Z]{2}$/) - return false if !@address_zip.nil? && @address_zip !~ Regexp.new(/^\d{5}(-\d{4})?$/) - object_validator = EnumAttributeValidator.new('String', ["address"]) - return false unless object_validator.valid?(@object) - true - end - - # Custom attribute writer method with validation - # @param [Object] id Value to be assigned - def id=(id) - pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/) - if !id.nil? && id !~ pattern - fail ArgumentError, "invalid value for \"id\", must conform to the pattern #{pattern}." - end - - @id = id - end - - # Custom attribute writer method with validation - # @param [Object] description Value to be assigned - def description=(description) - if !description.nil? && description.to_s.length > 255 - fail ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 255.' - end - - @description = description - end - - # Custom attribute writer method with validation - # @param [Object] name Value to be assigned - def name=(name) - if !name.nil? && name.to_s.length > 40 - fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 40.' - end - - @name = name - end - - # Custom attribute writer method with validation - # @param [Object] company Value to be assigned - def company=(company) - if !company.nil? && company.to_s.length > 40 - fail ArgumentError, 'invalid value for "company", the character length must be smaller than or equal to 40.' - end - - @company = company - end - - # Custom attribute writer method with validation - # @param [Object] phone Value to be assigned - def phone=(phone) - if !phone.nil? && phone.to_s.length > 40 - fail ArgumentError, 'invalid value for "phone", the character length must be smaller than or equal to 40.' - end - - @phone = phone - end - - # Custom attribute writer method with validation - # @param [Object] email Value to be assigned - def email=(email) - if !email.nil? && email.to_s.length > 100 - fail ArgumentError, 'invalid value for "email", the character length must be smaller than or equal to 100.' - end - - @email = email - end - - # Custom attribute writer method with validation - # @param [Object] metadata Value to be assigned - def metadata=(metadata) - @metadata = metadata - end - - # Custom attribute writer method with validation - # @param [Object] address_line1 Value to be assigned - def address_line1=(address_line1) - if !address_line1.nil? && address_line1.to_s.length > 64 - fail ArgumentError, 'invalid value for "address_line1", the character length must be smaller than or equal to 64.' - end - - @address_line1 = address_line1 - end - - # Custom attribute writer method with validation - # @param [Object] address_line2 Value to be assigned - def address_line2=(address_line2) - if !address_line2.nil? && address_line2.to_s.length > 64 - fail ArgumentError, 'invalid value for "address_line2", the character length must be smaller than or equal to 64.' - end - - @address_line2 = address_line2 - end - - # Custom attribute writer method with validation - # @param [Object] address_city Value to be assigned - def address_city=(address_city) - if !address_city.nil? && address_city.to_s.length > 200 - fail ArgumentError, 'invalid value for "address_city", the character length must be smaller than or equal to 200.' - end - - @address_city = address_city - end - - # Custom attribute writer method with validation - # @param [Object] address_state Value to be assigned - def address_state=(address_state) - pattern = Regexp.new(/^[a-zA-Z]{2}$/) - if !address_state.nil? && address_state !~ pattern - fail ArgumentError, "invalid value for \"address_state\", must conform to the pattern #{pattern}." - end - - @address_state = address_state - end - - # Custom attribute writer method with validation - # @param [Object] address_zip Value to be assigned - def address_zip=(address_zip) - pattern = Regexp.new(/^\d{5}(-\d{4})?$/) - if !address_zip.nil? && address_zip !~ pattern - fail ArgumentError, "invalid value for \"address_zip\", must conform to the pattern #{pattern}." - end - - @address_zip = address_zip - end - - # Custom attribute writer method checking allowed values (enum). - # @param [Object] object Object to be assigned - def object=(object) - validator = EnumAttributeValidator.new('String', ["address"]) - unless validator.valid?(object) - fail ArgumentError, "invalid value for \"object\", must be one of #{validator.allowable_values}." - end - @object = object - 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 && - id == o.id && - description == o.description && - name == o.name && - company == o.company && - phone == o.phone && - email == o.email && - metadata == o.metadata && - address_line1 == o.address_line1 && - address_line2 == o.address_line2 && - address_city == o.address_city && - address_state == o.address_state && - address_zip == o.address_zip && - address_country == o.address_country && - object == o.object && - date_created == o.date_created && - date_modified == o.date_modified && - deleted == o.deleted && - recipient_moved == o.recipient_moved - 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 - [id, description, name, company, phone, email, metadata, address_line1, address_line2, address_city, address_state, address_zip, address_country, object, date_created, date_modified, deleted, recipient_moved].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) - new.build_from_hash(attributes) - end - - # Builds the object from hash - # @param [Hash] attributes Model attributes in the form of hash - # @return [Object] Returns the model itself - def build_from_hash(attributes) - return nil unless attributes.is_a?(Hash) - attributes = attributes.transform_keys(&:to_sym) - self.class.openapi_types.each_pair do |key, type| - if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) - self.send("#{key}=", nil) # // guardrails-disable-line - 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[self.class.attribute_map[key]].is_a?(Array) - self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) # // guardrails-disable-line + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse. + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when 'Boolean' + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when 'Float' + return data if data.instance_of?(Float) + when 'Integer' + return data if data.instance_of?(Integer) + when 'Time' + return Time.parse(data) + when 'Date' + return Date.parse(data) + when 'String' + return data if data.instance_of?(String) + when 'Object' # "type: object" + return data if data.instance_of?(Hash) + when /\AArray<(?.+)>\z/ # "type: array" + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } end - elsif !attributes[self.class.attribute_map[key]].nil? && type.kind_of?(Array) - for base_type in type do - res = _deserialize(base_type, attributes[self.class.attribute_map[key]]) - if !res.nil? - self.send("#{key}=", res) # // guardrails-disable-line - break - end + when /\AHash.+)>\z/ # "type: object" with "additionalProperties: { ... }" + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } end - elsif !attributes[self.class.attribute_map[key]].nil? - self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) # // guardrails-disable-line - end - end - - self - end - - # Deserializes the data based on type - # @param string type Data type - # @param string value Value to be deserialized - # @return [Object] Deserialized data - def _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) + else # model + const = Lob.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) # nested oneOf model + model = const.build(data) + return model if model + else + # raise if data contains keys that are not known to the model + raise unless (data.keys - const.acceptable_attributes).empty? + model = const.build_from_hash(data) + return model if model && model.valid? + end end end - else # model - # models (e.g. Pet) or oneOf - klass = Lob.const_get(type) - 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) # // guardrails-disable-line - 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) + raise # if no match by now, raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" 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 diff --git a/lib/openapi_client/models/country_extended_expanded_no_us.rb b/lib/openapi_client/models/country_extended_expanded_no_us.rb new file mode 100644 index 0000000..f67d854 --- /dev/null +++ b/lib/openapi_client/models/country_extended_expanded_no_us.rb @@ -0,0 +1,254 @@ +=begin +#Lob + +#The Lob API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and uses HTTP response codes to indicate any API errors.

Looking for our [previous documentation](https://lob.github.io/legacy-docs/)? + +The version of the OpenAPI document: 1.3.0 +Contact: lob-openapi@lob.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.2.1 + +=end + +require 'date' +require 'time' + +module Lob + class CountryExtendedExpandedNoUs + EMPTY = "".freeze + AFGHANISTAN = "AFGHANISTAN".freeze + ALBANIA = "ALBANIA".freeze + ALGERIA = "ALGERIA".freeze + AMERICAN_SAMOA = "AMERICAN SAMOA".freeze + ANDORRA = "ANDORRA".freeze + ANGOLA = "ANGOLA".freeze + ANGUILLA = "ANGUILLA".freeze + ANTARCTICA = "ANTARCTICA".freeze + ANTIGUA_AND_BARBUDA = "ANTIGUA AND BARBUDA".freeze + ARGENTINA = "ARGENTINA".freeze + ARUBA = "ARUBA".freeze + AUSTRALIA = "AUSTRALIA".freeze + AUSTRIA = "AUSTRIA".freeze + AZERBAIJAN = "AZERBAIJAN".freeze + BAHRAIN = "BAHRAIN".freeze + BANGLADESH = "BANGLADESH".freeze + BARBADOS = "BARBADOS".freeze + BELARUS = "BELARUS".freeze + BELGIUM = "BELGIUM".freeze + BELIZE = "BELIZE".freeze + BENIN = "BENIN".freeze + BERMUDA = "BERMUDA".freeze + BHUTAN = "BHUTAN".freeze + BOLIVIA__PLURINATIONAL_STATE_OF = "BOLIVIA (PLURINATIONAL STATE OF)".freeze + BONAIRE_SAINT_EUSTATIUS_AND_SABA = "BONAIRE, SAINT EUSTATIUS AND SABA".freeze + BOSNIA_AND_HERZEGOVINA = "BOSNIA AND HERZEGOVINA".freeze + BOTSWANA = "BOTSWANA".freeze + BRAZIL = "BRAZIL".freeze + BRITISH_INDIAN_OCEAN_TERRITORY = "BRITISH INDIAN OCEAN TERRITORY".freeze + BRITISH_VIRGIN_ISLANDS = "BRITISH VIRGIN ISLANDS".freeze + BRUNEI_DARUSSALAM = "BRUNEI DARUSSALAM".freeze + BULGARIA = "BULGARIA".freeze + BURKINA_FASO = "BURKINA FASO".freeze + BURUNDI = "BURUNDI".freeze + CABO_VERDE = "CABO VERDE".freeze + CAMBODIA = "CAMBODIA".freeze + CAMEROON = "CAMEROON".freeze + CANADA = "CANADA".freeze + CAYMAN_ISLANDS = "CAYMAN ISLANDS".freeze + CENTRAL_AFRICAN_REPUBLIC = "CENTRAL AFRICAN REPUBLIC".freeze + CHAD = "CHAD".freeze + CHILE = "CHILE".freeze + CHINA = "CHINA".freeze + COLOMBIA = "COLOMBIA".freeze + COMOROS = "COMOROS".freeze + CONGO = "CONGO".freeze + CONGO_DEMOCRATIC_REPUBLIC_OF_THE = "CONGO, DEMOCRATIC REPUBLIC OF THE".freeze + COOK_ISLANDS = "COOK ISLANDS".freeze + COSTA_RICA = "COSTA RICA".freeze + CTE_DIVOIRE = "CÔTE D`IVOIRE".freeze + CROATIA = "CROATIA".freeze + CUBA = "CUBA".freeze + CURAAO = "CURAÇAO".freeze + CYPRUS = "CYPRUS".freeze + CZECH_REPUBLIC = "CZECH REPUBLIC".freeze + DENMARK = "DENMARK".freeze + DJIBOUTI = "DJIBOUTI".freeze + DOMINICA = "DOMINICA".freeze + DOMINICAN_REPUBLIC = "DOMINICAN REPUBLIC".freeze + ECUADOR = "ECUADOR".freeze + EGYPT = "EGYPT".freeze + EL_SALVADOR = "EL SALVADOR".freeze + EQUATORIAL_GUINEA = "EQUATORIAL GUINEA".freeze + ERITREA = "ERITREA".freeze + ESTONIA = "ESTONIA".freeze + ESWATINI = "ESWATINI".freeze + ETHIOPIA = "ETHIOPIA".freeze + FALKLAND_ISLANDS__MALVINAS = "FALKLAND ISLANDS (MALVINAS)".freeze + FAROE_ISLANDS = "FAROE ISLANDS".freeze + FIJI = "FIJI".freeze + FINLAND = "FINLAND".freeze + FRANCE = "FRANCE".freeze + GABON = "GABON".freeze + GAMBIA = "GAMBIA".freeze + GEORGIA = "GEORGIA".freeze + GERMANY = "GERMANY".freeze + GHANA = "GHANA".freeze + GIBRALTAR = "GIBRALTAR".freeze + GREECE = "GREECE".freeze + GREENLAND = "GREENLAND".freeze + GRENADA = "GRENADA".freeze + GUATEMALA = "GUATEMALA".freeze + GUINEA = "GUINEA".freeze + GUINEA_BISSAU = "GUINEA-BISSAU".freeze + GUYANA = "GUYANA".freeze + HAITI = "HAITI".freeze + HOLY_SEE = "HOLY SEE".freeze + HONDURAS = "HONDURAS".freeze + HONG_KONG = "HONG KONG".freeze + HUNGARY = "HUNGARY".freeze + ICELAND = "ICELAND".freeze + INDIA = "INDIA".freeze + INDONESIA = "INDONESIA".freeze + IRAN__ISLAMIC_REPUBLIC_OF = "IRAN (ISLAMIC REPUBLIC OF)".freeze + IRAQ = "IRAQ".freeze + IRELAND = "IRELAND".freeze + ISRAEL = "ISRAEL".freeze + ITALY = "ITALY".freeze + JAMAICA = "JAMAICA".freeze + JAPAN = "JAPAN".freeze + JORDAN = "JORDAN".freeze + KAZAKHSTAN = "KAZAKHSTAN".freeze + KENYA = "KENYA".freeze + KIRIBATI = "KIRIBATI".freeze + KOREA__DEMOCRATIC_PEOPLES_REPUBLIC_OF = "KOREA (DEMOCRATIC PEOPLE’S REPUBLIC OF)".freeze + KOREA_REPUBLIC_OF = "KOREA, REPUBLIC OF".freeze + KUWAIT = "KUWAIT".freeze + KYRGYZSTAN = "KYRGYZSTAN".freeze + LAO_PEOPLES_DEMOCRATIC_REPUBLIC = "LAO PEOPLE’S DEMOCRATIC REPUBLIC".freeze + LATVIA = "LATVIA".freeze + LEBANON = "LEBANON".freeze + LESOTHO = "LESOTHO".freeze + LIBERIA = "LIBERIA".freeze + LIBYA = "LIBYA".freeze + LIECHTENSTEIN = "LIECHTENSTEIN".freeze + LITHUANIA = "LITHUANIA".freeze + LUXEMBOURG = "LUXEMBOURG".freeze + MACAO = "MACAO".freeze + MACEDONIA = "MACEDONIA".freeze + MADAGASCAR = "MADAGASCAR".freeze + MALAWI = "MALAWI".freeze + MALAYSIA = "MALAYSIA".freeze + MALDIVES = "MALDIVES".freeze + MALI = "MALI".freeze + MALTA = "MALTA".freeze + MAURITANIA = "MAURITANIA".freeze + MAURITIUS = "MAURITIUS".freeze + MEXICO = "MEXICO".freeze + MOLDOVA_REPUBLIC_OF = "MOLDOVA, REPUBLIC OF".freeze + MONACO = "MONACO".freeze + MONGOLIA = "MONGOLIA".freeze + MONTENEGRO = "MONTENEGRO".freeze + MONTSERRAT = "MONTSERRAT".freeze + MOROCCO = "MOROCCO".freeze + MOZAMBIQUE = "MOZAMBIQUE".freeze + MYANMAR = "MYANMAR".freeze + NAMIBIA = "NAMIBIA".freeze + NAURU = "NAURU".freeze + NEPAL = "NEPAL".freeze + NETHERLAND_ANTILLES = "NETHERLAND ANTILLES".freeze + NETHERLANDS = "NETHERLANDS".freeze + NEW_ZEALAND = "NEW ZEALAND".freeze + NICARAGUA = "NICARAGUA".freeze + NIGER = "NIGER".freeze + NIGERIA = "NIGERIA".freeze + NIUE = "NIUE".freeze + NORFOLK_ISLAND = "NORFOLK ISLAND".freeze + NORWAY = "NORWAY".freeze + OMAN = "OMAN".freeze + PAKISTAN = "PAKISTAN".freeze + PANAMA = "PANAMA".freeze + PAPUA_NEW_GUINEA = "PAPUA NEW GUINEA".freeze + PARAGUAY = "PARAGUAY".freeze + PERU = "PERU".freeze + PHILIPPINES = "PHILIPPINES".freeze + PITCAIRN = "PITCAIRN".freeze + POLAND = "POLAND".freeze + PORTUGAL = "PORTUGAL".freeze + QATAR = "QATAR".freeze + ROMANIA = "ROMANIA".freeze + RUSSIAN_FEDERATION = "RUSSIAN FEDERATION".freeze + RWANDA = "RWANDA".freeze + SAINT_HELENA = "SAINT HELENA".freeze + SAINT_KITTS_AND_NEVIS = "SAINT KITTS AND NEVIS".freeze + SAINT_LUCIA = "SAINT LUCIA".freeze + SAINT_VINCENT_AND_THE_GRENADINES = "SAINT VINCENT AND THE GRENADINES".freeze + SAMOA = "SAMOA".freeze + SAN_MARINO = "SAN MARINO".freeze + SAO_TOME_AND_PRINCIPE = "SAO TOME AND PRINCIPE".freeze + SAUDI_ARABIA = "SAUDI ARABIA".freeze + SENEGAL = "SENEGAL".freeze + SERBIA = "SERBIA".freeze + SEYCHELLES = "SEYCHELLES".freeze + SIERRA_LEONE = "SIERRA LEONE".freeze + SINGAPORE = "SINGAPORE".freeze + SINT_MAARTEN = "SINT MAARTEN".freeze + SLOVAKIA = "SLOVAKIA".freeze + SLOVENIA = "SLOVENIA".freeze + SOLOMON_ISLANDS = "SOLOMON ISLANDS".freeze + SOMALIA = "SOMALIA".freeze + SOUTH_AFRICA = "SOUTH AFRICA".freeze + SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS = "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS".freeze + SOUTH_SUDAN = "SOUTH SUDAN".freeze + SPAIN = "SPAIN".freeze + SRI_LANKA = "SRI LANKA".freeze + SUDAN = "SUDAN".freeze + SURINAME = "SURINAME".freeze + SWEDEN = "SWEDEN".freeze + SWITZERLAND = "SWITZERLAND".freeze + SYRIAN_ARAB_REPUBLIC = "SYRIAN ARAB REPUBLIC".freeze + TAIWAN = "TAIWAN".freeze + TAJIKISTAN = "TAJIKISTAN".freeze + TANZANIA = "TANZANIA".freeze + THAILAND = "THAILAND".freeze + THE_BAHAMAS = "THE BAHAMAS".freeze + TIMOR_LESTE = "TIMOR-LESTE".freeze + TOGO = "TOGO".freeze + TOKELAU = "TOKELAU".freeze + TONGA = "TONGA".freeze + TRINIDAD_AND_TOBAGO = "TRINIDAD AND TOBAGO".freeze + TUNISIA = "TUNISIA".freeze + TURKEY = "TURKEY".freeze + TURKMENISTAN = "TURKMENISTAN".freeze + TURKS_AND_CAICOS_ISLANDS = "TURKS AND CAICOS ISLANDS".freeze + TUVALU = "TUVALU".freeze + UGANDA = "UGANDA".freeze + UKRAINE = "UKRAINE".freeze + UNITED_ARAB_EMIRATES = "UNITED ARAB EMIRATES".freeze + UNITED_KINGDOM = "UNITED KINGDOM".freeze + URUGUAY = "URUGUAY".freeze + UZBEKISTAN = "UZBEKISTAN".freeze + VANUATU = "VANUATU".freeze + VENEZUELA = "VENEZUELA".freeze + VIET_NAM = "VIET NAM".freeze + WESTERN_SAHARA = "WESTERN SAHARA".freeze + YEMEN = "YEMEN".freeze + ZAMBIA = "ZAMBIA".freeze + ZIMBABWE = "ZIMBABWE".freeze + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + constantValues = CountryExtendedExpandedNoUs.constants.select { |c| CountryExtendedExpandedNoUs::const_get(c) == value } + raise "Invalid ENUM value #{value} for class #CountryExtendedExpandedNoUs" if constantValues.empty? + value + end + end +end diff --git a/lib/openapi_client/models/intl_address.rb b/lib/openapi_client/models/intl_address.rb new file mode 100644 index 0000000..c997c30 --- /dev/null +++ b/lib/openapi_client/models/intl_address.rb @@ -0,0 +1,624 @@ +=begin +#Lob + +#The Lob API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and uses HTTP response codes to indicate any API errors.

Looking for our [previous documentation](https://lob.github.io/legacy-docs/)? + +The version of the OpenAPI document: 1.3.0 +Contact: lob-openapi@lob.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.2.1 + +=end + +require 'date' +require 'time' + +module Lob + class IntlAddress + # Unique identifier prefixed with `adr_`. + attr_accessor :id + + # An internal description that identifies this resource. Must be no longer than 255 characters. + attr_accessor :description + + # name associated with address + attr_accessor :name + + # Either `name` or `company` is required, you may also add both. + attr_accessor :company + + # Must be no longer than 40 characters. + attr_accessor :phone + + # Must be no longer than 100 characters. + attr_accessor :email + + # Use metadata to store custom information for tagging and labeling back to your internal systems. Must be an object with up to 20 key-value pairs. Keys must be at most 40 characters and values must be at most 500 characters. Neither can contain the characters `\"` and `\\`. i.e. '{\"customer_id\" : \"NEWYORK2015\"}' Nested objects are not supported. See [Metadata](#section/Metadata) for more information. + attr_accessor :metadata + + attr_accessor :address_line1 + + attr_accessor :address_line2 + + attr_accessor :address_city + + # 2 letter state short-name code + attr_accessor :address_state + + # Must have a maximum of 12 characters + attr_accessor :address_zip + + attr_accessor :address_country + + attr_accessor :object + + # A timestamp in ISO 8601 format of the date the resource was created. + attr_accessor :date_created + + # A timestamp in ISO 8601 format of the date the resource was last modified. + attr_accessor :date_modified + + # Only returned if the resource has been successfully deleted. + attr_accessor :deleted + + # Checks if address id is used or not + attr_accessor :inline + + # Only returned for accounts on certain Print & Mail Editions. Value is `true` if the address was altered because the recipient filed for a National Change of Address (NCOA), `false` if the NCOA check was run but no altered address was found, and `null` if the NCOA check was not run. The NCOA check does not happen for non-US addresses, for non-deliverable US addresses, or for addresses created before the NCOA feature was added to your account. + attr_accessor :recipient_moved + + 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 + { + :'id' => :'id', + :'description' => :'description', + :'name' => :'name', + :'company' => :'company', + :'phone' => :'phone', + :'email' => :'email', + :'metadata' => :'metadata', + :'address_line1' => :'address_line1', + :'address_line2' => :'address_line2', + :'address_city' => :'address_city', + :'address_state' => :'address_state', + :'address_zip' => :'address_zip', + :'address_country' => :'address_country', + :'object' => :'object', + :'date_created' => :'date_created', + :'date_modified' => :'date_modified', + :'deleted' => :'deleted', + :'inline' => :'inline', + :'recipient_moved' => :'recipient_moved' + } + 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 + { + :'id' => :'String', + :'description' => :'String', + :'name' => :'String', + :'company' => :'String', + :'phone' => :'String', + :'email' => :'String', + :'metadata' => :'Hash', + :'address_line1' => :'String', + :'address_line2' => :'String', + :'address_city' => :'String', + :'address_state' => :'String', + :'address_zip' => :'String', + :'address_country' => :'CountryExtendedExpandedNoUs', + :'object' => :'String', + :'date_created' => :'Time', + :'date_modified' => :'Time', + :'deleted' => :'Boolean', + :'inline' => :'Boolean', + :'recipient_moved' => :'Boolean' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'description', + :'name', + :'company', + :'phone', + :'email', + :'address_line2', + :'recipient_moved' + ]) + 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 `Lob::IntlAddress` 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 `Lob::IntlAddress`. 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?(:'id') + self.id = attributes[:'id'] + end + + if attributes.key?(:'description') + self.description = attributes[:'description'] + end + + if attributes.key?(:'name') + self.name = attributes[:'name'] + end + + if attributes.key?(:'company') + self.company = attributes[:'company'] + end + + if attributes.key?(:'phone') + self.phone = attributes[:'phone'] + end + + if attributes.key?(:'email') + self.email = attributes[:'email'] + end + + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + + if attributes.key?(:'address_line1') + self.address_line1 = attributes[:'address_line1'] + end + + if attributes.key?(:'address_line2') + self.address_line2 = attributes[:'address_line2'] + end + + if attributes.key?(:'address_city') + self.address_city = attributes[:'address_city'] + end + + if attributes.key?(:'address_state') + self.address_state = attributes[:'address_state'] + end + + if attributes.key?(:'address_zip') + self.address_zip = attributes[:'address_zip'] + end + + if attributes.key?(:'address_country') + self.address_country = attributes[:'address_country'] + end + + if attributes.key?(:'object') + self.object = attributes[:'object'] + else + self.object = 'address' + end + + if attributes.key?(:'date_created') + self.date_created = attributes[:'date_created'] + end + + if attributes.key?(:'date_modified') + self.date_modified = attributes[:'date_modified'] + end + + if attributes.key?(:'deleted') + self.deleted = attributes[:'deleted'] + end + + if attributes.key?(:'inline') + self.inline = attributes[:'inline'] + end + + if attributes.key?(:'recipient_moved') + self.recipient_moved = attributes[:'recipient_moved'] + 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 + invalid_properties = Array.new + pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/) + if !@id.nil? && @id !~ pattern + invalid_properties.push("invalid value for \"id\", must conform to the pattern #{pattern}.") + end + + if !@description.nil? && @description.to_s.length > 255 + invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 255.') + end + + if !@name.nil? && @name.to_s.length > 40 + invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 40.') + end + + if !@company.nil? && @company.to_s.length > 40 + invalid_properties.push('invalid value for "company", the character length must be smaller than or equal to 40.') + end + + if !@phone.nil? && @phone.to_s.length > 40 + invalid_properties.push('invalid value for "phone", the character length must be smaller than or equal to 40.') + end + + if !@email.nil? && @email.to_s.length > 100 + invalid_properties.push('invalid value for "email", the character length must be smaller than or equal to 100.') + end + + if !@address_line1.nil? && @address_line1.to_s.length > 64 + invalid_properties.push('invalid value for "address_line1", the character length must be smaller than or equal to 64.') + end + + if !@address_line2.nil? && @address_line2.to_s.length > 64 + invalid_properties.push('invalid value for "address_line2", the character length must be smaller than or equal to 64.') + end + + if !@address_city.nil? && @address_city.to_s.length > 200 + invalid_properties.push('invalid value for "address_city", the character length must be smaller than or equal to 200.') + end + + pattern = Regexp.new(/^[a-zA-Z]{2}$/) + if !@address_state.nil? && @address_state !~ pattern + invalid_properties.push("invalid value for \"address_state\", must conform to the pattern #{pattern}.") + end + + if !@address_zip.nil? && @address_zip.to_s.length > 12 + invalid_properties.push('invalid value for "address_zip", the character length must be smaller than or equal to 12.') + 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? + return false if !@id.nil? && @id !~ Regexp.new(/^adr_[a-zA-Z0-9]+$/) + return false if !@description.nil? && @description.to_s.length > 255 + return false if !@name.nil? && @name.to_s.length > 40 + return false if !@company.nil? && @company.to_s.length > 40 + return false if !@phone.nil? && @phone.to_s.length > 40 + return false if !@email.nil? && @email.to_s.length > 100 + return false if !@address_line1.nil? && @address_line1.to_s.length > 64 + return false if !@address_line2.nil? && @address_line2.to_s.length > 64 + return false if !@address_city.nil? && @address_city.to_s.length > 200 + return false if !@address_state.nil? && @address_state !~ Regexp.new(/^[a-zA-Z]{2}$/) + return false if !@address_zip.nil? && @address_zip.to_s.length > 12 + object_validator = EnumAttributeValidator.new('String', ["address"]) + return false unless object_validator.valid?(@object) + true + end + + # Custom attribute writer method with validation + # @param [Object] id Value to be assigned + def id=(id) + pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/) + if !id.nil? && id !~ pattern + fail ArgumentError, "invalid value for \"id\", must conform to the pattern #{pattern}." + end + + @id = id + end + + # Custom attribute writer method with validation + # @param [Object] description Value to be assigned + def description=(description) + if !description.nil? && description.to_s.length > 255 + fail ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 255.' + end + + @description = description + end + + # Custom attribute writer method with validation + # @param [Object] name Value to be assigned + def name=(name) + if !name.nil? && name.to_s.length > 40 + fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 40.' + end + + @name = name + end + + # Custom attribute writer method with validation + # @param [Object] company Value to be assigned + def company=(company) + if !company.nil? && company.to_s.length > 40 + fail ArgumentError, 'invalid value for "company", the character length must be smaller than or equal to 40.' + end + + @company = company + end + + # Custom attribute writer method with validation + # @param [Object] phone Value to be assigned + def phone=(phone) + if !phone.nil? && phone.to_s.length > 40 + fail ArgumentError, 'invalid value for "phone", the character length must be smaller than or equal to 40.' + end + + @phone = phone + end + + # Custom attribute writer method with validation + # @param [Object] email Value to be assigned + def email=(email) + if !email.nil? && email.to_s.length > 100 + fail ArgumentError, 'invalid value for "email", the character length must be smaller than or equal to 100.' + end + + @email = email + end + + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + @metadata = metadata + end + + # Custom attribute writer method with validation + # @param [Object] address_line1 Value to be assigned + def address_line1=(address_line1) + if !address_line1.nil? && address_line1.to_s.length > 64 + fail ArgumentError, 'invalid value for "address_line1", the character length must be smaller than or equal to 64.' + end + + @address_line1 = address_line1 + end + + # Custom attribute writer method with validation + # @param [Object] address_line2 Value to be assigned + def address_line2=(address_line2) + if !address_line2.nil? && address_line2.to_s.length > 64 + fail ArgumentError, 'invalid value for "address_line2", the character length must be smaller than or equal to 64.' + end + + @address_line2 = address_line2 + end + + # Custom attribute writer method with validation + # @param [Object] address_city Value to be assigned + def address_city=(address_city) + if !address_city.nil? && address_city.to_s.length > 200 + fail ArgumentError, 'invalid value for "address_city", the character length must be smaller than or equal to 200.' + end + + @address_city = address_city + end + + # Custom attribute writer method with validation + # @param [Object] address_state Value to be assigned + def address_state=(address_state) + pattern = Regexp.new(/^[a-zA-Z]{2}$/) + if !address_state.nil? && address_state !~ pattern + fail ArgumentError, "invalid value for \"address_state\", must conform to the pattern #{pattern}." + end + + @address_state = address_state + end + + # Custom attribute writer method with validation + # @param [Object] address_zip Value to be assigned + def address_zip=(address_zip) + if !address_zip.nil? && address_zip.to_s.length > 12 + fail ArgumentError, 'invalid value for "address_zip", the character length must be smaller than or equal to 12.' + end + + @address_zip = address_zip + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] object Object to be assigned + def object=(object) + validator = EnumAttributeValidator.new('String', ["address"]) + unless validator.valid?(object) + fail ArgumentError, "invalid value for \"object\", must be one of #{validator.allowable_values}." + end + @object = object + 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 && + id == o.id && + description == o.description && + name == o.name && + company == o.company && + phone == o.phone && + email == o.email && + metadata == o.metadata && + address_line1 == o.address_line1 && + address_line2 == o.address_line2 && + address_city == o.address_city && + address_state == o.address_state && + address_zip == o.address_zip && + address_country == o.address_country && + object == o.object && + date_created == o.date_created && + date_modified == o.date_modified && + deleted == o.deleted && + inline == o.inline && + recipient_moved == o.recipient_moved + 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 + [id, description, name, company, phone, email, metadata, address_line1, address_line2, address_city, address_state, address_zip, address_country, object, date_created, date_modified, deleted, inline, recipient_moved].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) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + self.class.openapi_types.each_pair do |key, type| + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) # // guardrails-disable-line + 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[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) # // guardrails-disable-line + end + elsif !attributes[self.class.attribute_map[key]].nil? && type.kind_of?(Array) + for base_type in type do + res = _deserialize(base_type, attributes[self.class.attribute_map[key]]) + if !res.nil? + self.send("#{key}=", res) # // guardrails-disable-line + break + end + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) # // guardrails-disable-line + end + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _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 = Lob.const_get(type) + 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) # // guardrails-disable-line + 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 diff --git a/lib/openapi_client/models/us_address.rb b/lib/openapi_client/models/us_address.rb new file mode 100644 index 0000000..8d08663 --- /dev/null +++ b/lib/openapi_client/models/us_address.rb @@ -0,0 +1,644 @@ +=begin +#Lob + +#The Lob API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and uses HTTP response codes to indicate any API errors.

Looking for our [previous documentation](https://lob.github.io/legacy-docs/)? + +The version of the OpenAPI document: 1.3.0 +Contact: lob-openapi@lob.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.2.1 + +=end + +require 'date' +require 'time' + +module Lob + class UsAddress + # Unique identifier prefixed with `adr_`. + attr_accessor :id + + # An internal description that identifies this resource. Must be no longer than 255 characters. + attr_accessor :description + + # name associated with address + attr_accessor :name + + # Either `name` or `company` is required, you may also add both. + attr_accessor :company + + # Must be no longer than 40 characters. + attr_accessor :phone + + # Must be no longer than 100 characters. + attr_accessor :email + + # Use metadata to store custom information for tagging and labeling back to your internal systems. Must be an object with up to 20 key-value pairs. Keys must be at most 40 characters and values must be at most 500 characters. Neither can contain the characters `\"` and `\\`. i.e. '{\"customer_id\" : \"NEWYORK2015\"}' Nested objects are not supported. See [Metadata](#section/Metadata) for more information. + attr_accessor :metadata + + attr_accessor :address_line1 + + attr_accessor :address_line2 + + attr_accessor :address_city + + # 2 letter state short-name code + attr_accessor :address_state + + # Must follow the ZIP format of `12345` or ZIP+4 format of `12345-1234`. + attr_accessor :address_zip + + # Full name of country + attr_accessor :address_country + + attr_accessor :object + + # A timestamp in ISO 8601 format of the date the resource was created. + attr_accessor :date_created + + # A timestamp in ISO 8601 format of the date the resource was last modified. + attr_accessor :date_modified + + # Only returned if the resource has been successfully deleted. + attr_accessor :deleted + + # Checks if address id is used or not + attr_accessor :inline + + # Only returned for accounts on certain Print & Mail Editions. Value is `true` if the address was altered because the recipient filed for a National Change of Address (NCOA), `false` if the NCOA check was run but no altered address was found, and `null` if the NCOA check was not run. The NCOA check does not happen for non-US addresses, for non-deliverable US addresses, or for addresses created before the NCOA feature was added to your account. + attr_accessor :recipient_moved + + 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 + { + :'id' => :'id', + :'description' => :'description', + :'name' => :'name', + :'company' => :'company', + :'phone' => :'phone', + :'email' => :'email', + :'metadata' => :'metadata', + :'address_line1' => :'address_line1', + :'address_line2' => :'address_line2', + :'address_city' => :'address_city', + :'address_state' => :'address_state', + :'address_zip' => :'address_zip', + :'address_country' => :'address_country', + :'object' => :'object', + :'date_created' => :'date_created', + :'date_modified' => :'date_modified', + :'deleted' => :'deleted', + :'inline' => :'inline', + :'recipient_moved' => :'recipient_moved' + } + 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 + { + :'id' => :'String', + :'description' => :'String', + :'name' => :'String', + :'company' => :'String', + :'phone' => :'String', + :'email' => :'String', + :'metadata' => :'Hash', + :'address_line1' => :'String', + :'address_line2' => :'String', + :'address_city' => :'String', + :'address_state' => :'String', + :'address_zip' => :'String', + :'address_country' => :'String', + :'object' => :'String', + :'date_created' => :'Time', + :'date_modified' => :'Time', + :'deleted' => :'Boolean', + :'inline' => :'Boolean', + :'recipient_moved' => :'Boolean' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'description', + :'name', + :'company', + :'phone', + :'email', + :'address_line2', + :'recipient_moved' + ]) + 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 `Lob::UsAddress` 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 `Lob::UsAddress`. 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?(:'id') + self.id = attributes[:'id'] + end + + if attributes.key?(:'description') + self.description = attributes[:'description'] + end + + if attributes.key?(:'name') + self.name = attributes[:'name'] + end + + if attributes.key?(:'company') + self.company = attributes[:'company'] + end + + if attributes.key?(:'phone') + self.phone = attributes[:'phone'] + end + + if attributes.key?(:'email') + self.email = attributes[:'email'] + end + + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + + if attributes.key?(:'address_line1') + self.address_line1 = attributes[:'address_line1'] + end + + if attributes.key?(:'address_line2') + self.address_line2 = attributes[:'address_line2'] + end + + if attributes.key?(:'address_city') + self.address_city = attributes[:'address_city'] + end + + if attributes.key?(:'address_state') + self.address_state = attributes[:'address_state'] + end + + if attributes.key?(:'address_zip') + self.address_zip = attributes[:'address_zip'] + end + + if attributes.key?(:'address_country') + self.address_country = attributes[:'address_country'] + end + + if attributes.key?(:'object') + self.object = attributes[:'object'] + else + self.object = 'address' + end + + if attributes.key?(:'date_created') + self.date_created = attributes[:'date_created'] + end + + if attributes.key?(:'date_modified') + self.date_modified = attributes[:'date_modified'] + end + + if attributes.key?(:'deleted') + self.deleted = attributes[:'deleted'] + end + + if attributes.key?(:'inline') + self.inline = attributes[:'inline'] + end + + if attributes.key?(:'recipient_moved') + self.recipient_moved = attributes[:'recipient_moved'] + 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 + invalid_properties = Array.new + pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/) + if !@id.nil? && @id !~ pattern + invalid_properties.push("invalid value for \"id\", must conform to the pattern #{pattern}.") + end + + if !@description.nil? && @description.to_s.length > 255 + invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 255.') + end + + if !@name.nil? && @name.to_s.length > 40 + invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 40.') + end + + if !@company.nil? && @company.to_s.length > 40 + invalid_properties.push('invalid value for "company", the character length must be smaller than or equal to 40.') + end + + if !@phone.nil? && @phone.to_s.length > 40 + invalid_properties.push('invalid value for "phone", the character length must be smaller than or equal to 40.') + end + + if !@email.nil? && @email.to_s.length > 100 + invalid_properties.push('invalid value for "email", the character length must be smaller than or equal to 100.') + end + + if !@address_line1.nil? && @address_line1.to_s.length > 64 + invalid_properties.push('invalid value for "address_line1", the character length must be smaller than or equal to 64.') + end + + if !@address_line2.nil? && @address_line2.to_s.length > 64 + invalid_properties.push('invalid value for "address_line2", the character length must be smaller than or equal to 64.') + end + + if !@address_city.nil? && @address_city.to_s.length > 200 + invalid_properties.push('invalid value for "address_city", the character length must be smaller than or equal to 200.') + end + + pattern = Regexp.new(/^[a-zA-Z]{2}$/) + if !@address_state.nil? && @address_state !~ pattern + invalid_properties.push("invalid value for \"address_state\", must conform to the pattern #{pattern}.") + end + + pattern = Regexp.new(/^\d{5}(-\d{4})?$/) + if !@address_zip.nil? && @address_zip !~ pattern + invalid_properties.push("invalid value for \"address_zip\", must conform to the pattern #{pattern}.") + end + + if !@address_country.nil? && @address_country.to_s.length > 200 + invalid_properties.push('invalid value for "address_country", the character length must be smaller than or equal to 200.') + 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? + return false if !@id.nil? && @id !~ Regexp.new(/^adr_[a-zA-Z0-9]+$/) + return false if !@description.nil? && @description.to_s.length > 255 + return false if !@name.nil? && @name.to_s.length > 40 + return false if !@company.nil? && @company.to_s.length > 40 + return false if !@phone.nil? && @phone.to_s.length > 40 + return false if !@email.nil? && @email.to_s.length > 100 + return false if !@address_line1.nil? && @address_line1.to_s.length > 64 + return false if !@address_line2.nil? && @address_line2.to_s.length > 64 + return false if !@address_city.nil? && @address_city.to_s.length > 200 + return false if !@address_state.nil? && @address_state !~ Regexp.new(/^[a-zA-Z]{2}$/) + return false if !@address_zip.nil? && @address_zip !~ Regexp.new(/^\d{5}(-\d{4})?$/) + address_country_validator = EnumAttributeValidator.new('String', ["UNITED STATES"]) + return false unless address_country_validator.valid?(@address_country) + return false if !@address_country.nil? && @address_country.to_s.length > 200 + object_validator = EnumAttributeValidator.new('String', ["address"]) + return false unless object_validator.valid?(@object) + true + end + + # Custom attribute writer method with validation + # @param [Object] id Value to be assigned + def id=(id) + pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/) + if !id.nil? && id !~ pattern + fail ArgumentError, "invalid value for \"id\", must conform to the pattern #{pattern}." + end + + @id = id + end + + # Custom attribute writer method with validation + # @param [Object] description Value to be assigned + def description=(description) + if !description.nil? && description.to_s.length > 255 + fail ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 255.' + end + + @description = description + end + + # Custom attribute writer method with validation + # @param [Object] name Value to be assigned + def name=(name) + if !name.nil? && name.to_s.length > 40 + fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 40.' + end + + @name = name + end + + # Custom attribute writer method with validation + # @param [Object] company Value to be assigned + def company=(company) + if !company.nil? && company.to_s.length > 40 + fail ArgumentError, 'invalid value for "company", the character length must be smaller than or equal to 40.' + end + + @company = company + end + + # Custom attribute writer method with validation + # @param [Object] phone Value to be assigned + def phone=(phone) + if !phone.nil? && phone.to_s.length > 40 + fail ArgumentError, 'invalid value for "phone", the character length must be smaller than or equal to 40.' + end + + @phone = phone + end + + # Custom attribute writer method with validation + # @param [Object] email Value to be assigned + def email=(email) + if !email.nil? && email.to_s.length > 100 + fail ArgumentError, 'invalid value for "email", the character length must be smaller than or equal to 100.' + end + + @email = email + end + + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + @metadata = metadata + end + + # Custom attribute writer method with validation + # @param [Object] address_line1 Value to be assigned + def address_line1=(address_line1) + if !address_line1.nil? && address_line1.to_s.length > 64 + fail ArgumentError, 'invalid value for "address_line1", the character length must be smaller than or equal to 64.' + end + + @address_line1 = address_line1 + end + + # Custom attribute writer method with validation + # @param [Object] address_line2 Value to be assigned + def address_line2=(address_line2) + if !address_line2.nil? && address_line2.to_s.length > 64 + fail ArgumentError, 'invalid value for "address_line2", the character length must be smaller than or equal to 64.' + end + + @address_line2 = address_line2 + end + + # Custom attribute writer method with validation + # @param [Object] address_city Value to be assigned + def address_city=(address_city) + if !address_city.nil? && address_city.to_s.length > 200 + fail ArgumentError, 'invalid value for "address_city", the character length must be smaller than or equal to 200.' + end + + @address_city = address_city + end + + # Custom attribute writer method with validation + # @param [Object] address_state Value to be assigned + def address_state=(address_state) + pattern = Regexp.new(/^[a-zA-Z]{2}$/) + if !address_state.nil? && address_state !~ pattern + fail ArgumentError, "invalid value for \"address_state\", must conform to the pattern #{pattern}." + end + + @address_state = address_state + end + + # Custom attribute writer method with validation + # @param [Object] address_zip Value to be assigned + def address_zip=(address_zip) + pattern = Regexp.new(/^\d{5}(-\d{4})?$/) + if !address_zip.nil? && address_zip !~ pattern + fail ArgumentError, "invalid value for \"address_zip\", must conform to the pattern #{pattern}." + end + + @address_zip = address_zip + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] address_country Object to be assigned + def address_country=(address_country) + validator = EnumAttributeValidator.new('String', ["UNITED STATES"]) + unless validator.valid?(address_country) + fail ArgumentError, "invalid value for \"address_country\", must be one of #{validator.allowable_values}." + end + @address_country = address_country + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] object Object to be assigned + def object=(object) + validator = EnumAttributeValidator.new('String', ["address"]) + unless validator.valid?(object) + fail ArgumentError, "invalid value for \"object\", must be one of #{validator.allowable_values}." + end + @object = object + 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 && + id == o.id && + description == o.description && + name == o.name && + company == o.company && + phone == o.phone && + email == o.email && + metadata == o.metadata && + address_line1 == o.address_line1 && + address_line2 == o.address_line2 && + address_city == o.address_city && + address_state == o.address_state && + address_zip == o.address_zip && + address_country == o.address_country && + object == o.object && + date_created == o.date_created && + date_modified == o.date_modified && + deleted == o.deleted && + inline == o.inline && + recipient_moved == o.recipient_moved + 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 + [id, description, name, company, phone, email, metadata, address_line1, address_line2, address_city, address_state, address_zip, address_country, object, date_created, date_modified, deleted, inline, recipient_moved].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) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + self.class.openapi_types.each_pair do |key, type| + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) # // guardrails-disable-line + 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[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) # // guardrails-disable-line + end + elsif !attributes[self.class.attribute_map[key]].nil? && type.kind_of?(Array) + for base_type in type do + res = _deserialize(base_type, attributes[self.class.attribute_map[key]]) + if !res.nil? + self.send("#{key}=", res) # // guardrails-disable-line + break + end + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) # // guardrails-disable-line + end + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _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 = Lob.const_get(type) + 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) # // guardrails-disable-line + 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 diff --git a/lib/openapi_client/version.rb b/lib/openapi_client/version.rb index 23875a1..050c217 100755 --- a/lib/openapi_client/version.rb +++ b/lib/openapi_client/version.rb @@ -11,5 +11,5 @@ =end module Lob - VERSION = '6.0.7' + VERSION = '6.0.8' end