Shippex.Address (shippex v0.15.0) View Source
Represents an address that can be passed to other Shippex
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
Specs
t() :: %Shippex.Address{ address: String.t(), address_line_2: 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(), name: nil | String.t(), phone: nil | String.t(), postal_code: String.t(), state: String.t() }
Link to this section Functions
Specs
Returns the list of non-nil
address lines. If no address_line_2
is
present, it returns a list of a single String
.
Specs
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"
Specs
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"
Specs
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, Shippex will try to infer the first and last
names in case they're required separately for API calls.
Shippex.Address.new(%{
first_name: "Earl",
last_name: "Grey",
phone: "123-123-1234",
address: "9999 Hobby Lane",
address_line_2: nil,
city: "Austin",
state: "TX",
postal_code: "78703"
})
Specs
Calls new/1
and raises an error on failure.
Specs
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
Specs
Returns the state code without its country code prefix.
iex> address = Shippex.Address.new!(%{
...> 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",
...> country: "US"
...> })
iex> Address.state_without_country(address)
"TX"
Specs
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