View Source UspsEx.Address (usps_ex v2023.1.27)
Represents an address that can be passed to other UspsEx
functions. Do
not initialize this struct directly. Instead, use address/1
.
Link to this section Summary
Functions
Returns the list of non-nil
address lines. If no address_line_2
is
present, it returns a list of a single String
.
Returns the country code for the given common name, or nil if none was found.
Returns a common country name for the given country code. This removes
occurrences of "(the)"
that may be present in the ISO-3166-2 data. For
example, the code "US" normally maps to "United States of America (the)". We
can shorten this with
Initializes an Address
struct from the given params
, and performs minor
validations that do not require any service requests.
Calls new/1
and raises an error on failure.
Returns true
if addresses for the country require a postal code to be
specified to validate addresses.
Returns the state code without its country code prefix.
Returns true
if addresses for the country require a province, state, or
other subdivision to be specified to validate addresses.
Link to this section Types
@type t() :: %UspsEx.Address{ address: String.t(), address_line_2: nil | String.t(), address_line_3: nil | String.t(), city: String.t(), company_name: nil | String.t(), country: ISO.country_code(), first_name: nil | String.t(), last_name: nil | String.t(), meta: String.t(), name: nil | String.t(), phone: nil | String.t(), postal_code: String.t(), state: String.t(), type: String.t(), urbanization: String.t(), valid: String.t(), zip4: String.t() }
Link to this section Functions
Returns the list of non-nil
address lines. If no address_line_2
is
present, it returns a list of a single String
.
Returns the country code for the given common name, or nil if none was found.
iex> Address.common_country_code("United States")
"US"
iex> Address.common_country_code("United States of America")
"US"
Returns a common country name for the given country code. This removes
occurrences of "(the)"
that may be present in the ISO-3166-2 data. For
example, the code "US" normally maps to "United States of America (the)". We
can shorten this with:
iex> Address.common_country_name("US")
"United States"
Initializes an Address
struct from the given params
, and performs minor
validations that do not require any service requests.
You may specify first_name
and last_name
separately, which will be
concatenated to make the name
property, or just specify name
directly.
If name
is specified directly, UspsEx will try to infer the first and last
names in case they're required separately for API calls.
UspsEx.Address.new(%{
first_name: "Earl",
last_name: "Grey",
phone: "123-123-1234",
address: "9999 Hobby Lane",
address_line_2: nil,
address_line_3: nil,
city: "Austin",
state: "TX",
type: :residential,
postal_code: "78703",
zip_4: "0000",
valid: true,
email: nil,
meta: nil,
urbanization: ""
})
Calls new/1
and raises an error on failure.
@spec postal_code_required?(ISO.country_code()) :: boolean()
Returns true
if addresses for the country require a postal code to be
specified to validate addresses.
iex> Address.postal_code_required?("US")
true
iex> Address.postal_code_required?("CN")
true
iex> Address.postal_code_required?("HK")
false
Returns the state code without its country code prefix.
iex> address = UspsEx.Address.state_without_country(%{
...> first_name: "Earl",
...> last_name: "Grey",
...> phone: "123-123-1234",
...> address: "9999 Hobby Lane",
...> address_line_2: nil,
...> city: "Austin",
...> state: "US-TX",
...> postal_code: "78703",
...> type: :business,
...> country: "US",
...> meta: nil
...> })
iex> Address.state_without_country(address)
"TX"
@spec subdivision_required?(ISO.country_code()) :: boolean()
Returns true
if addresses for the country require a province, state, or
other subdivision to be specified to validate addresses.
iex> Address.subdivision_required?("US")
true
iex> Address.subdivision_required?("CN")
true
iex> Address.subdivision_required?("SG")
false