Current section
Files
Jump to
Current section
Files
lib/twilio/api/v2010/message/media_service.ex
# File generated from Twilio's OpenAPI spec — do not edit manually
defmodule Twilio.Api.V2010.Message.MediaService do
@moduledoc """
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
The Media subresource of a Message resource represents a piece of media, such as an image, that is associated with the Message.
Operations: `list`, `fetch`, `delete`
"""
alias Twilio.Client
alias Twilio.Deserializer
@doc """
Read a list of Media resources associated with a specific Message resource
Operation: `ListMedia` | Tags: Api20100401Media
## Query Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `DateCreated` | string (date-time) | Only include Media resources that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read Media that were created on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read Media that were created on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read Media that were created on or after midnight of this date. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `DateCreated<` | string (date-time) | Only include Media resources that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read Media that were created on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read Media that were created on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read Media that were created on or after midnight of this date. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `DateCreated>` | string (date-time) | Only include Media resources that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read Media that were created on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read Media that were created on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read Media that were created on or after midnight of this date. |
"""
@spec list(Client.t(), String.t(), map(), keyword()) ::
{:ok, Twilio.Page.t()} | {:ok, map(), map()} | :ok | {:error, Twilio.Error.t()}
def list(client, message_sid, params \\ %{}, opts \\ []) do
case Client.request(
client,
:get,
"/2010-04-01/Accounts/#{client.account_sid}/Messages/#{message_sid}/Media.json",
params: params,
opts: opts,
base_url: "https://api.twilio.com"
) do
{:ok, data} ->
page = Twilio.Page.from_response(data, "media_list")
{:ok,
%{
page
| items:
Deserializer.deserialize_list(page.items, Twilio.Resources.Api.V2010.Message.Media)
}}
error ->
error
end
end
@doc "Stream: Read a list of Media resources associated with a specific Message resource (lazy auto-pagination)."
@spec stream(Client.t(), String.t(), map(), keyword()) :: Enumerable.t()
def stream(client, message_sid, params \\ %{}, opts \\ []) do
Twilio.Page.stream(
fn page_opts ->
list(client, message_sid, Map.merge(params, page_opts), opts)
end,
"media_list"
)
end
@doc """
Fetch a single Media resource associated with a specific Message resource
Operation: `FetchMedia` | Tags: Api20100401MediaInstance
"""
@spec fetch(Client.t(), String.t(), String.t(), keyword()) ::
{:ok, Twilio.Resources.Api.V2010.Message.Media.t()}
| {:ok, map(), map()}
| :ok
| {:error, Twilio.Error.t()}
def fetch(client, message_sid, sid, opts \\ []) do
with {:ok, data} <-
Client.request(
client,
:get,
"/2010-04-01/Accounts/#{client.account_sid}/Messages/#{message_sid}/Media/#{sid}.json",
opts: opts,
base_url: "https://api.twilio.com"
) do
{:ok, Deserializer.deserialize(data, Twilio.Resources.Api.V2010.Message.Media)}
end
end
@doc """
Delete the Media resource.
Operation: `DeleteMedia` | Tags: Api20100401MediaInstance
"""
@spec delete(Client.t(), String.t(), String.t(), keyword()) ::
{:ok, map()} | {:ok, map(), map()} | :ok | {:error, Twilio.Error.t()}
def delete(client, message_sid, sid, opts \\ []) do
Client.request(
client,
:delete,
"/2010-04-01/Accounts/#{client.account_sid}/Messages/#{message_sid}/Media/#{sid}.json",
opts: opts,
base_url: "https://api.twilio.com"
)
end
end