lib/mail_slurp_api/api/attachment_controller.ex

# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# https://openapi-generator.tech
# Do not edit the class manually.

defmodule MailSlurpAPI.Api.AttachmentController do
  @moduledoc """
  API calls for all endpoints tagged `AttachmentController`.
  """

  alias MailSlurpAPI.Connection
  import MailSlurpAPI.RequestBuilder


  @doc """
  Delete all attachments

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, %{}} on success
  {:error, info} on failure
  """
  @spec delete_all_attachments(Tesla.Env.client, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
  def delete_all_attachments(connection, _opts \\ []) do
    %{}
    |> method(:delete)
    |> url("/attachments")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 204, false}
    ])
  end

  @doc """
  Delete an attachment

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - attachment_id (String.t): ID of attachment
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, %{}} on success
  {:error, info} on failure
  """
  @spec delete_attachment(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
  def delete_attachment(connection, attachment_id, _opts \\ []) do
    %{}
    |> method(:delete)
    |> url("/attachments/#{attachment_id}")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 204, false}
    ])
  end

  @doc """
  Get email attachment as base64 encoded string as alternative to binary responses. To read the content decode the Base64 encoded contents.
  Returns the specified attachment for a given email as a base 64 encoded string. The response type is application/json. This method is similar to the `downloadAttachment` method but allows some clients to get around issues with binary responses.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - attachment_id (String.t): ID of attachment
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, %MailSlurpAPI.Model.DownloadAttachmentDto{}} on success
  {:error, info} on failure
  """
  @spec download_attachment_as_base64_encoded(Tesla.Env.client, String.t, keyword()) :: {:ok, MailSlurpAPI.Model.DownloadAttachmentDto.t} | {:error, Tesla.Env.t}
  def download_attachment_as_base64_encoded(connection, attachment_id, _opts \\ []) do
    %{}
    |> method(:get)
    |> url("/attachments/#{attachment_id}/base64")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.DownloadAttachmentDto{}}
    ])
  end

  @doc """
  Download attachments. Get email attachment bytes. If you have trouble with byte responses try the `downloadAttachmentBase64` response endpoints.
  Returns the specified attachment for a given email as a stream / array of bytes. You can find attachment ids in email responses endpoint responses. The response type is application/octet-stream.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - attachment_id (String.t): ID of attachment
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, %MailSlurpAPI.Model.binary(){}} on success
  {:error, info} on failure
  """
  @spec download_attachment_as_bytes(Tesla.Env.client, String.t, keyword()) :: {:ok, String.t} | {:error, Tesla.Env.t}
  def download_attachment_as_bytes(connection, attachment_id, _opts \\ []) do
    %{}
    |> method(:get)
    |> url("/attachments/#{attachment_id}/bytes")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { :default, false}
    ])
  end

  @doc """
  Get an attachment entity

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - attachment_id (String.t): ID of attachment
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, %MailSlurpAPI.Model.AttachmentEntity{}} on success
  {:error, info} on failure
  """
  @spec get_attachment(Tesla.Env.client, String.t, keyword()) :: {:ok, MailSlurpAPI.Model.AttachmentEntity.t} | {:error, Tesla.Env.t}
  def get_attachment(connection, attachment_id, _opts \\ []) do
    %{}
    |> method(:get)
    |> url("/attachments/#{attachment_id}")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.AttachmentEntity{}}
    ])
  end

  @doc """
  Get email attachment metadata information
  Returns the metadata for an attachment. It is saved separately to the content of the attachment. Contains properties `name` and `content-type` and `content-length` in bytes for a given attachment.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - attachment_id (String.t): ID of attachment
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, %MailSlurpAPI.Model.AttachmentMetaData{}} on success
  {:error, info} on failure
  """
  @spec get_attachment_info(Tesla.Env.client, String.t, keyword()) :: {:ok, MailSlurpAPI.Model.AttachmentMetaData.t} | {:error, Tesla.Env.t}
  def get_attachment_info(connection, attachment_id, _opts \\ []) do
    %{}
    |> method(:get)
    |> url("/attachments/#{attachment_id}/metadata")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.AttachmentMetaData{}}
    ])
  end

  @doc """
  Get email attachments
  Get all attachments in paginated response. Each entity contains meta data for the attachment such as `name` and `content-type`. Use the `attachmentId` and the download endpoints to get the file contents.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :page (integer()): Optional page index for list pagination
    - :size (integer()): Optional page size for list pagination
    - :sort (String.t): Optional createdAt sort direction ASC or DESC
    - :file_name_filter (String.t): Optional file name and content type search filter
    - :since (DateTime.t): Filter by created at after the given timestamp
    - :before (DateTime.t): Filter by created at before the given timestamp
  ## Returns

  {:ok, %MailSlurpAPI.Model.PageAttachmentEntity{}} on success
  {:error, info} on failure
  """
  @spec get_attachments(Tesla.Env.client, keyword()) :: {:ok, MailSlurpAPI.Model.PageAttachmentEntity.t} | {:error, Tesla.Env.t}
  def get_attachments(connection, opts \\ []) do
    optional_params = %{
      :"page" => :query,
      :"size" => :query,
      :"sort" => :query,
      :"fileNameFilter" => :query,
      :"since" => :query,
      :"before" => :query
    }
    %{}
    |> method(:get)
    |> url("/attachments")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.PageAttachmentEntity{}}
    ])
  end

  @doc """
  Upload an attachment for sending using base64 file encoding. Returns an array whose first element is the ID of the uploaded attachment.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - upload_attachment_options (UploadAttachmentOptions): 
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, [%String{}, ...]} on success
  {:error, info} on failure
  """
  @spec upload_attachment(Tesla.Env.client, MailSlurpAPI.Model.UploadAttachmentOptions.t, keyword()) :: {:ok, list(String.t)} | {:error, Tesla.Env.t}
  def upload_attachment(connection, upload_attachment_options, _opts \\ []) do
    %{}
    |> method(:post)
    |> url("/attachments")
    |> add_param(:body, :body, upload_attachment_options)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 201, []}
    ])
  end

  @doc """
  Upload an attachment for sending using file byte stream input octet stream. Returns an array whose first element is the ID of the uploaded attachment.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - inline_object1 (InlineObject1): 
  - opts (KeywordList): [optional] Optional parameters
    - :content_type (String.t): Optional contentType for file. For instance `application/pdf`
    - :filename (String.t): Optional filename to save upload with
  ## Returns

  {:ok, [%String{}, ...]} on success
  {:error, info} on failure
  """
  @spec upload_attachment_bytes(Tesla.Env.client, MailSlurpAPI.Model.InlineObject1.t, keyword()) :: {:ok, list(String.t)} | {:error, Tesla.Env.t}
  def upload_attachment_bytes(connection, inline_object1, opts \\ []) do
    optional_params = %{
      :"contentType" => :headers,
      :"filename" => :query
    }
    %{}
    |> method(:post)
    |> url("/attachments/bytes")
    |> add_param(:body, :body, inline_object1)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 201, []}
    ])
  end

  @doc """
  Upload an attachment for sending using a Multipart Form request. Returns an array whose first element is the ID of the uploaded attachment.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :content_type (String.t): Optional content type of attachment
    - :filename (String.t): Optional name of file
    - :x_filename (String.t): Optional content type header of attachment
    - :inline_object (InlineObject): 
  ## Returns

  {:ok, [%String{}, ...]} on success
  {:error, info} on failure
  """
  @spec upload_multipart_form(Tesla.Env.client, keyword()) :: {:ok, list(String.t)} | {:error, Tesla.Env.t}
  def upload_multipart_form(connection, opts \\ []) do
    optional_params = %{
      :"contentType" => :query,
      :"filename" => :query,
      :"x-filename" => :query,
      :"InlineObject" => :body
    }
    %{}
    |> method(:post)
    |> url("/attachments/multipart")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 201, []}
    ])
  end
end