ExTwilio.Resource
Mixin to include ExTwilio.Api module functionality in a module with slightly prettier syntax. Under the hood, it delegates all the work to ExTwilio.Api.
Example
Define a module, and use ExTwilio.Resource.
defmodule ExTwilio.Call do
use ExTwilio.Resource, import: [:stream, :all, :list]
defstruct sid: nil, ...
end
The import option specifies which of the ExTwilio.Api methods you want to be able to use. Under the hood, this creates three methods on your new module, and they look like this:
def stream(options \ []), do: Api.stream(__MODULE__, options)
def all(options \ []), do: Api.all(__MODULE__, options)
def list(options \ []), do: Api.list(__MODULE__, options)
As you can see, they're simple aliases to Api methods. However, they do make your code look a lot nicer.
# Instead of this:
ExTwilio.Api.all(ExTwilio.Call)
# You can write:
ExTwilio.Call.all
Important: You must define a struct for each module in which you use ExTwilio.Resource. Items from Twilio will be converted into instances of this struct.
Summary↑
| __using__(options) | Provide a |
Macros
Provide a use macro for use extending.