ExTwilio v0.2.0 ExTwilio.UrlGenerator

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

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

Specs

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//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//Resources/1.json"

iex> build_url(Resource, nil, page: 20)
"https://api.twilio.com/2010-04-01/Accounts//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//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"
resource_collection_name(module)

Specs

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"
resource_name(module)

Specs

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"
to_query_string(list)

Specs

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"