ExTwilio.UrlGenerator

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

Source

Summary

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

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

resource_collection_name(module)

Infer a lowercase and underscore collection name for a module

resource_name(module)

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

to_query_string(list)

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

Functions

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

Specs:

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> ExTwilio.UrlGenerator.build_url(Resource)
"https://api.twilio.com/2010-04-01/Accounts//Resources.json"

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

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

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

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

iex> ExTwilio.UrlGenerator.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> ExTwilio.UrlGenerator.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"
Source
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"
Source
resource_name(module)

Specs:

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

Specs:

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"
Source