2017-04-08 02:14:42 -04:00
|
|
|
defmodule Hunter.Attachment do
|
2017-04-08 01:30:17 -04:00
|
|
|
@moduledoc """
|
2017-04-08 02:14:42 -04:00
|
|
|
Attachment entity
|
2017-04-08 01:30:17 -04:00
|
|
|
|
2017-04-08 02:14:42 -04:00
|
|
|
This module defines a `Hunter.Attachment` struct and the main functions
|
|
|
|
for working with Attachments.
|
2017-04-08 01:30:17 -04:00
|
|
|
|
|
|
|
## Fields
|
|
|
|
|
|
|
|
* `id` - ID of the attachment
|
2017-10-26 15:39:42 -04:00
|
|
|
* `type` - One of: "image", "video", "gifv", "unknown"
|
2017-04-08 01:30:17 -04:00
|
|
|
* `url` - URL of the locally hosted version of the image
|
|
|
|
* `remote_url` - For remote images, the remote URL of the original image
|
|
|
|
* `preview_url` - URL of the preview image
|
2019-01-22 13:15:30 -05:00
|
|
|
* `text_url` - Shorter URL for the image, for insertion into text (only
|
|
|
|
present on local images)
|
|
|
|
* `meta` - May contain subtress `small` and `original`. Images may contain:
|
|
|
|
`width`, `height`, `size`, `aspect`, while videos (including `gifv`) may
|
|
|
|
contain: `width`, `height`, `frame_rate`, `duration`, and `bitrate`.
|
|
|
|
* `description` - attachment description
|
2017-10-26 15:39:42 -04:00
|
|
|
|
2019-01-22 13:15:30 -05:00
|
|
|
**Note**: When the type is "unknown", it is likely only `remote_url` is
|
|
|
|
available and local `url` is missing
|
2017-04-08 01:30:17 -04:00
|
|
|
|
|
|
|
"""
|
2019-03-19 13:18:34 -04:00
|
|
|
alias Hunter.Config
|
2017-04-08 02:14:42 -04:00
|
|
|
|
2017-04-08 01:30:17 -04:00
|
|
|
@type t :: %__MODULE__{
|
2017-10-26 15:16:42 -04:00
|
|
|
id: non_neg_integer,
|
|
|
|
type: String.t(),
|
|
|
|
url: String.t(),
|
|
|
|
remote_url: String.t(),
|
|
|
|
preview_url: String.t(),
|
|
|
|
text_url: String.t(),
|
2019-01-22 13:15:30 -05:00
|
|
|
meta: String.t(),
|
|
|
|
description: String.t()
|
2017-10-26 15:16:42 -04:00
|
|
|
}
|
2017-04-08 01:30:17 -04:00
|
|
|
|
|
|
|
@derive [Poison.Encoder]
|
2019-01-22 13:15:30 -05:00
|
|
|
defstruct [:id, :type, :url, :remote_url, :preview_url, :text_url, :meta, :description]
|
2017-04-08 02:14:42 -04:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Upload a media attachment
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
|
|
|
* `conn` - connection credentials
|
|
|
|
* `file` - media to be uploaded
|
2019-01-22 13:15:30 -05:00
|
|
|
* `options` - option list
|
|
|
|
|
|
|
|
## Options
|
|
|
|
* `description` - plain-text description of the media for accessibility (max 420 chars)
|
|
|
|
* `focus` - two floating points, comma-delimited.
|
2017-04-08 02:14:42 -04:00
|
|
|
|
|
|
|
"""
|
2019-01-22 13:15:30 -05:00
|
|
|
@spec upload_media(Hunter.Client.t(), Path.t(), Keyword.t()) :: Hunter.Attachment.t()
|
|
|
|
def upload_media(conn, file, options \\ []) do
|
2019-03-19 13:18:34 -04:00
|
|
|
Config.hunter_api().upload_media(conn, file, options)
|
2017-04-08 02:14:42 -04:00
|
|
|
end
|
2017-04-08 01:30:17 -04:00
|
|
|
end
|