View Source ExTwilio.UrlGenerator (ExTwilio v0.10.0)

Generates Twilio URLs for modules. See build_url/3 for more information.

Summary

Functions

Infers the proper Twilio URL for a resource when given a module, an optional SID, and a list of options.

Infer a lowercase and underscore collection name for a module.

Converts a module name into a pluralized Twilio-compatible resource name.

Generate a list of querystring parameters for a url from an Elixir list.

Functions

Link to this function

build_url(module, id \\ nil, options \\ [])

View Source
@spec build_url(atom(), String.t() | nil, list()) :: String.t()

Infers the proper Twilio URL for a resource when given a module, an optional SID, and a list of options.

Note that the module should have the following two functions:

  • resource_name/0
  • resource_collection_name/0

Examples

iex> build_url(Resource)
"https://api.twilio.com/2010-04-01/Accounts/<production account sid here>/Resources.json"

iex> build_url(Resource, nil, account: 2)
"https://api.twilio.com/2010-04-01/Accounts/2/Resources.json"

iex> build_url(Resource, 1, account: 2)
"https://api.twilio.com/2010-04-01/Accounts/2/Resources/1.json"

iex> build_url(Resource, 1)
"https://api.twilio.com/2010-04-01/Accounts/<production account sid here>/Resources/1.json"

iex> build_url(Resource, nil, page: 20)
"https://api.twilio.com/2010-04-01/Accounts/<production account sid here>/Resources.json?Page=20"

iex> build_url(Resource, nil, iso_country_code: "US", type: "Mobile", page: 20)
"https://api.twilio.com/2010-04-01/Accounts/<production account sid here>/Resources/US/Mobile.json?Page=20"

iex> build_url(Resource, 1, sip_ip_access_control_list: "list", account: "account_sid")
"https://api.twilio.com/2010-04-01/Accounts/account_sid/SIP/IpAccessControlLists/list/Resources/1.json"
Link to this function

resource_collection_name(module)

View Source
@spec resource_collection_name(atom()) :: String.t()

Infer a lowercase and underscore collection name for a module.

Examples

iex> ExTwilio.UrlGenerator.resource_collection_name(Resource)
"resources"
@spec resource_name(atom() | String.t()) :: String.t()

Converts a module name into a pluralized Twilio-compatible resource name.

Examples

iex> ExTwilio.UrlGenerator.resource_name(:"Elixir.ExTwilio.Call")
"Calls"

# Uses only the last segment of the module name
iex> ExTwilio.UrlGenerator.resource_name(:"ExTwilio.Resources.Call")
"Calls"
@spec to_query_string(list()) :: String.t()

Generate a list of querystring parameters for a url from an Elixir list.

Examples

iex> ExTwilio.UrlGenerator.to_query_string([hello: "world", how_are: "you"])
"Hello=world&HowAre=you"