URL.Tel (URL v2.0.3)

Copy Markdown View Source

Parses the scheme-specific part of a tel URL as defined in RFC 3966.

When the optional ex_phone_number dependency is available the number is formatted in international form, with a phone-context parameter that is itself a number prepended first. The territory used for numbers without a country code comes from the current localize locale, then the current gettext locale, then "US". Numbers that ex_phone_number cannot parse are kept as written. The primary API is parse/1, which URL.new/1 calls for any URL with the tel scheme.

Summary

Functions

Parses the path of a tel URI into a t/0 struct.

Types

t()

@type t() :: %URL.Tel{params: map(), tel: String.t()}

Functions

parse(uri)

@spec parse(URI.t()) :: {:ok, t()} | {:error, {module(), binary()}}

Parses the path of a tel URI into a t/0 struct.

Arguments

  • uri is a URI.t/0 whose :scheme is "tel".

Returns

  • {:ok, t:t/0} with the formatted (or, if it cannot be parsed, unformatted) telephone number in :tel and any parameters in :params, or

  • {:error, {URL.Parser.ParseError, reason}} if the path is not a valid telephone subscriber string, including an empty path.

Examples

iex> tel = URI.parse "tel:+61-0407-555-987"
iex> URL.Tel.parse(tel)
{:ok, %URL.Tel{tel: "+61 407 555 987", params: %{}}}

iex> tel = URI.parse "tel:0407-555-987;phone-context=+61"
iex> URL.Tel.parse(tel)
{:ok, %URL.Tel{tel: "+61 407 555 987", params: %{"phone-context" => "+61"}}}

iex> {:error, {URL.Parser.ParseError, _reason}} = URL.Tel.parse(URI.parse("tel:abc"))