ExTwilio v0.1.8 ExTwilio.Api
Provides a basic HTTP interface to allow easy communication with the Twilio API, by wrapping HTTPotion.
Examples
Requests are made to the Twilio API by passing in a resource module into one of this Api module's functions. The correct URL to the resource is inferred from the module name.
ExTwilio.Api.find(Resource, "sid")
%Resource{ sid: "sid", ... }
Items are returned as instances of the given module's struct. For more details, see the documentation for each function.
Summary
Functions
Create a new resource in the Twilio API with a POST request
A shortcut for request(:delete, url, options)
Destroy an existing resource in the Twilio Api
Find a given resource in the Twilio API by its SID
A shortcut for request(:get, url, options)
A shortcut for request(:head, url, options)
A shortcut for request(:options, url, options)
A shortcut for request(:patch, url, options)
A shortcut for request(:post, url, options)
Adds the Account SID and Auth Token to every request through HTTP basic auth
If the request body is a list, then convert the list to a query string. Otherwise, pass it through unmodified
Automatically add the Content-Type application/x-www-form-urlencoded. This allows POST request data to be processed properly. It seems to have no negative effect on GET calls, so it is added to all requests
A shortcut for request(:put, url, options)
Sends an HTTP request
Deprecated form of request; body and headers are now options, see request/3
Deprecated form of request with the direct option; body and headers are now options, see request/3
Starts a linked worker process for use with the direct option
Starts a worker process for use with the direct option
Ensures that HTTPotion and its dependencies are started
Stops a worker process started with spawn_worker_process/2 or spawn_link_worker_process/2
Update an existing resource in the Twilio Api
Functions
Specs
create(atom, list, list) ::
ExTwilio.Parser.success |
ExTwilio.Parser.error
Create a new resource in the Twilio API with a POST request.
Examples
ExTwilio.Api.create(ExTwilio.Call, [to: "1112223333", from: "4445556666"])
{:ok, %Call{ ... }}
ExTwilio.Api.create(ExTwilio.Call, [])
{:error, "No 'To' number is specified", 400}
Destroy an existing resource in the Twilio Api.
Examples
ExTwilio.Api.destroy(ExTwilio.Call, "<sid>")
:ok
ExTwilio.Api.destroy(ExTwilio.Call, "nonexistent")
{:error, "The requested resource ... was not found", 404}
Specs
find(atom, String.t | nil, list) ::
ExTwilio.Parser.success |
ExTwilio.Parser.error
Find a given resource in the Twilio API by its SID.
Examples
If the resource was found, find/2 will return a two-element tuple in this format, {:ok, item}.
ExTwilio.Api.find(ExTwilio.Call, "<sid here>")
{:ok, %Call{ ... }}
If the resource could not be loaded, find/2 will return a 3-element tuple in this format, {:error, message, code}. The code is the HTTP status code returned by the Twilio API, for example, 404.
ExTwilio.Api.find(ExTwilio.Call, "nonexistent sid")
{:error, "The requested resource couldn't be found...", 404}
Specs
process_options(list) :: list
Adds the Account SID and Auth Token to every request through HTTP basic auth.
Example
iex> ExTwilio.Api.process_options([])
[basic_auth: { nil, nil }]
If the request body is a list, then convert the list to a query string. Otherwise, pass it through unmodified.
Examples
iex> ExTwilio.Api.process_request_body([hello: "world"])
"Hello=world"
iex> ExTwilio.Api.process_request_body("Hello, world!")
"Hello, world!"
Specs
process_request_headers(list) :: list
Automatically add the Content-Type application/x-www-form-urlencoded. This allows POST request data to be processed properly. It seems to have no negative effect on GET calls, so it is added to all requests.
Example
iex> ExTwilio.Api.process_request_headers([])
[{:"Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"}]
Specs
request(atom, String.t, [{atom, any}]) ::
%HTTPotion.Response{body: term, headers: term, status_code: term} |
%HTTPotion.AsyncResponse{id: term}
Sends an HTTP request.
Args:
method- HTTP method, atom (:get, :head, :post, :put, :delete, etc.)url- URL, binary string or char listoptions- orddict of options
Options:
body- request body, binary string or char listheaders- HTTP headers, orddict (eg.["Accept": "application/json"])timeout- timeout in ms, integerbasic_auth- basic auth credentials (eg.{"user", "password"})stream_to- if you want to make an async request, the pid of the processdirect- if you want to use ibrowse's direct feature, the pid of the worker spawned byspawn_worker_process/2orspawn_link_worker_process/2follow_redirects- if true and a response is a redirect, header[:Location] is taken for the next request
Returns HTTPotion.Response or HTTPotion.AsyncResponse if successful. Raises HTTPotion.HTTPError if failed.
Deprecated form of request; body and headers are now options, see request/3.
Deprecated form of request with the direct option; body and headers are now options, see request/3.
Starts a linked worker process for use with the direct option.
Stops a worker process started with spawn_worker_process/2 or spawn_link_worker_process/2.
Specs
update(atom, String.t, list, list) ::
ExTwilio.Parser.success |
ExTwilio.Parser.error
Update an existing resource in the Twilio Api.
Examples
ExTwilio.Api.update(ExTwilio.Call, "<sid>", [status: "canceled"])
{:ok, %Call{ status: "canceled" ... }}
ExTwilio.Api.update(ExTwilio.Call, "nonexistent", [status: "complete"])
{:error, "The requested resource ... was not found", 404}