Current section
Files
Jump to
Current section
Files
lib/twilio/api/v2010/account_service.ex
# File generated from Twilio's OpenAPI spec — do not edit manually
defmodule Twilio.Api.V2010.AccountService do
@moduledoc """
Twilio accounts (aka Project) or subaccounts
Operations: `list`, `create`, `fetch`, `update`
"""
alias Twilio.Client
alias Twilio.Deserializer
@doc """
Retrieves a collection of Accounts belonging to the account used to make the request
Operation: `ListAccount` | Tags: Api20100401Account
## Query Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `FriendlyName` | string | Only return the Account resources with friendly names that exactly match this name. |
| `Status` | string | Only return Account resources with the given status. Can be `closed`, `suspended` or `active`. |
"""
@spec list(Client.t(), map(), keyword()) ::
{:ok, Twilio.Page.t()} | {:ok, map(), map()} | :ok | {:error, Twilio.Error.t()}
def list(client, params \\ %{}, opts \\ []) do
case Client.request(client, :get, "/2010-04-01/Accounts.json",
params: params,
opts: opts,
base_url: "https://api.twilio.com"
) do
{:ok, data} ->
page = Twilio.Page.from_response(data, "accounts")
{:ok,
%{
page
| items: Deserializer.deserialize_list(page.items, Twilio.Resources.Api.V2010.Account)
}}
error ->
error
end
end
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
@doc "Stream: Retrieves a collection of Accounts belonging to the account used to make the request (lazy auto-pagination)."
@spec stream(Client.t(), map(), keyword()) :: Enumerable.t()
def stream(client, params \\ %{}, opts \\ []) do
Twilio.Page.stream(
fn page_opts ->
list(client, Map.merge(params, page_opts), opts)
end,
"accounts"
)
end
@doc """
Create a new Twilio Subaccount from the account making the request
Operation: `CreateAccount` | Tags: Api20100401Account
## Optional Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `FriendlyName` | string | A human readable description of the account to create, defaults to `SubAccount Created at {YYYY-MM-DD HH:MM meridian}` |
"""
@spec create(Client.t(), map(), keyword()) ::
{:ok, Twilio.Resources.Api.V2010.Account.t()}
| {:ok, map(), map()}
| :ok
| {:error, Twilio.Error.t()}
def create(client, params \\ %{}, opts \\ []) do
with {:ok, data} <-
Client.request(client, :post, "/2010-04-01/Accounts.json",
params: params,
opts: opts,
base_url: "https://api.twilio.com",
content_type: :form
) do
{:ok, Deserializer.deserialize(data, Twilio.Resources.Api.V2010.Account)}
end
end
@doc """
Fetch the account specified by the provided Account Sid
Operation: `FetchAccount` | Tags: Api20100401Account
"""
@spec fetch(Client.t(), String.t(), keyword()) ::
{:ok, Twilio.Resources.Api.V2010.Account.t()}
| {:ok, map(), map()}
| :ok
| {:error, Twilio.Error.t()}
def fetch(client, sid, opts \\ []) do
with {:ok, data} <-
Client.request(client, :get, "/2010-04-01/Accounts/#{sid}.json",
opts: opts,
base_url: "https://api.twilio.com"
) do
{:ok, Deserializer.deserialize(data, Twilio.Resources.Api.V2010.Account)}
end
end
@doc """
Modify the properties of a given Account
Operation: `UpdateAccount` | Tags: Api20100401Account
## Optional Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `FriendlyName` | string | Update the human-readable description of this Account |
| `Status` | string | Values: `active`, `suspended`, `closed` |
"""
@spec update(Client.t(), String.t(), map(), keyword()) ::
{:ok, Twilio.Resources.Api.V2010.Account.t()}
| {:ok, map(), map()}
| :ok
| {:error, Twilio.Error.t()}
def update(client, sid, params \\ %{}, opts \\ []) do
with {:ok, data} <-
Client.request(client, :post, "/2010-04-01/Accounts/#{sid}.json",
params: params,
opts: opts,
base_url: "https://api.twilio.com",
content_type: :form
) do
{:ok, Deserializer.deserialize(data, Twilio.Resources.Api.V2010.Account)}
end
end
end