CatalogApi v0.0.13 CatalogApi.Address View Source
Defines the CatalogApi.Address struct and functions which are responsible for validation and interpretation of physical shipping addresses as they relate to CatalogApi.
To see the CatalogApi documentation for what is and isn’t a valid Address see
http://username.catalogapi.com/docs/methods/cart_methods/#cart_set_address
An overview of the address fields is as follows:
first_name
(required): The first name of the person receiving shipment.last_name
(required): The last name of the person receiving shipment.address_1
(required): The street address.address_2
(optional): The second line of the street address.address_3
(optional): The third line of the street address.city
(required): The city.state_province
(required): The state or province. If it is a US state, this should be the 2 digit abbreviation. (Example: OH)postal_code
(required) : The postal code. This should be a string.country
(required): The ISO 3166-1 alpha-2 country code.email
(optional): The email of the person receiving shipment.phone_number
(optional): The phone number of the person receiving shipment.
Link to this section Summary
Functions
Returns a valid fake address. Useful for testing
Validates an address struct to ensure that its values will not be rejected by CatalogApi endpoints. This ensures that an error can be thrown before the CatalogApi endpoint is actually hit
Validates a specific address field in the context of what is valid as input to a CatalogApi address
Validates a map with string or atom keys that is intended to represent a CatalogApi address
Link to this section Types
Link to this section Functions
Returns a valid fake address. Useful for testing.
validate(t()) :: :ok | {:error, invalid_address_error()}
Validates an address struct to ensure that its values will not be rejected by CatalogApi endpoints. This ensures that an error can be thrown before the CatalogApi endpoint is actually hit.
If the Address struct is valid, :ok
is returned.
If there are validation errors, than an error tuple is returned which enumerates the field specific errors.
To see the CatalogApi documentation for what is and isn’t a valid Address see
http://username.catalogapi.com/docs/methods/cart_methods/#cart_set_address
Examples
iex> address = %CatalogApi.Address{
...> first_name: "Jo",
...> last_name: "Bob",
...> address_1: "123 Street Road",
...> city: "Cleveland",
...> state_province: "OH",
...> postal_code: "44444",
...> country: "US"}
...> CatalogApi.Address.validate(address)
:ok
iex> address = %CatalogApi.Address{
...> first_name: "Jo",
...> last_name: "Bob",
...> address_1: "123 Street Road",
...> city: "",
...> state_province: "OH",
...> postal_code: "44444",
...> country: "AJ"}
...> CatalogApi.Address.validate(address)
{:error, {:invalid_address, %{country: ["country code must be valid ISO 3166-1 alpha 2 country code"], city: ["cannot be blank"]}}}
Validates a specific address field in the context of what is valid as input to a CatalogApi address.
validate_params(t() | map()) :: :ok | {:error, invalid_address_error()}
Validates a map with string or atom keys that is intended to represent a CatalogApi address.
If the params are valid, :ok
is returned.
If there are validation errors, than an error tuple is returned which enumerates the field specific errors.
To see the CatalogApi documentation for what is and isn’t a valid Address see
http://username.catalogapi.com/docs/methods/cart_methods/#cart_set_address
Example
iex> address = %{
...> first_name: "Jo",
...> last_name: "Bob",
...> address_1: "123 Street Road",
...> city: "Cleveland",
...> state_province: "OH",
...> postal_code: "44444",
...> country: "US"}
...> CatalogApi.Address.validate_params(address)
:ok
This function also properly validates a map where the keys are strings.
Example
iex> address = %{
...> "first_name" => "Jo",
...> "last_name" => "Bob",
...> "address_1" => "123 Street Road",
...> "city" => "Cleveland",
...> "state_province" => "OH",
...> "postal_code" => "44444",
...> "country" => "US"}
...> CatalogApi.Address.validate_params(address)
:ok