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
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"
Infer a lowercase and underscore collection name for a module.
Examples
iex> ExTwilio.UrlGenerator.resource_collection_name(Resource)
"resources"
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"
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"