# `Ltix.DeepLinking.ContentItem.File`
[🔗](https://github.com/DecoyLex/ltix/blob/main/lib/ltix/deep_linking/content_item/file.ex#L1)

A file content item for Deep Linking responses.

File URLs are short-lived. The platform downloads the file shortly
after receiving the response, so the URL only needs to remain valid
for a few minutes.

## Examples

    iex> {:ok, file} = Ltix.DeepLinking.ContentItem.File.new(
    ...>   url: "https://example.com/syllabus.pdf",
    ...>   media_type: "application/pdf"
    ...> )
    iex> Ltix.DeepLinking.ContentItem.to_map(file)
    %{"type" => "file", "url" => "https://example.com/syllabus.pdf", "mediaType" => "application/pdf"}

## Options

* `:title` (`t:String.t/0`) - Title for the content item.

* `:text` (`t:String.t/0`) - Plain-text description.

* `:extensions` (`nil` | `t:map/0`) - Required. Vendor-specific extension properties. The default value is `%{}`.

* `:url` (`t:String.t/0`) - Required. URL to download the file.

* `:expires_at` (`t:DateTime.t/0`) - When the download URL expires.

* `:media_type` (`t:String.t/0`) - MIME type of the file (e.g. `"application/pdf"`).

* `:icon` (`t:map/0`) - Icon or thumbnail for the file.

* `:thumbnail` (`t:map/0`) - Icon or thumbnail for the file.

# `t`

```elixir
@type t() :: %Ltix.DeepLinking.ContentItem.File{
  expires_at: nil | DateTime.t(),
  extensions: nil | %{optional(binary() | atom()) =&gt; any()},
  icon:
    nil
    | %{
        optional(:width) =&gt; integer(),
        :url =&gt; binary(),
        optional(:height) =&gt; integer()
      },
  media_type: nil | binary(),
  text: nil | binary(),
  thumbnail:
    nil
    | %{
        optional(:width) =&gt; integer(),
        :url =&gt; binary(),
        optional(:height) =&gt; integer()
      },
  title: nil | binary(),
  url: binary()
}
```

# `new`

```elixir
@spec new(keyword() | map()) :: {:ok, t()} | {:error, Exception.t()}
```

Create a new file content item.

Takes the module's options as a keyword list or map, and nested options such as
`icon` may also be keyword lists. Unknown or invalid options return an
`Ltix.Errors.Invalid.InvalidField` error.

## Examples

    iex> {:ok, file} = Ltix.DeepLinking.ContentItem.File.new(url: "https://example.com/doc.pdf")
    iex> file.url
    "https://example.com/doc.pdf"

    iex> {:error, error} = Ltix.DeepLinking.ContentItem.File.new([])
    iex> Exception.message(error)
    "Ltix.DeepLinking.ContentItem.File field :url is required [DL §3.3]"

# `new!`

```elixir
@spec new!(keyword() | map()) :: t()
```

Same as `new/1` but raises on error.

## Examples

    iex> Ltix.DeepLinking.ContentItem.File.new!(url: "https://example.com/doc.pdf").url
    "https://example.com/doc.pdf"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
