Skip to main content

lib/coffrify/resources/domains.ex

defmodule Coffrify.Resources.Domains do
  @moduledoc "Custom domains — CNAME → coffrify.fr aliasing for branded share URLs."

  alias Coffrify

  @doc "List configured custom domains."
  @spec list(Coffrify.t()) :: {:ok, map()} | {:error, Exception.t()}
  def list(client), do: Coffrify.request(client, :get, "/domains")

  @doc "Get a domain by id."
  @spec get(Coffrify.t(), String.t()) :: {:ok, map()} | {:error, Exception.t()}
  def get(client, id), do: Coffrify.request(client, :get, "/domains/#{URI.encode(id)}")

  @doc "Add a new domain — returns the verification token and CNAME target."
  @spec create(Coffrify.t(), String.t()) :: {:ok, map()} | {:error, Exception.t()}
  def create(client, domain), do: Coffrify.request(client, :post, "/domains", %{domain: domain})

  @doc "Remove a custom domain."
  @spec delete(Coffrify.t(), String.t()) :: {:ok, map()} | {:error, Exception.t()}
  def delete(client, id), do: Coffrify.request(client, :delete, "/domains/#{URI.encode(id)}")

  @doc "Resolve the customer CNAME via DoH and flip `verified=true` on match."
  @spec verify(Coffrify.t(), String.t()) :: {:ok, map()} | {:error, Exception.t()}
  def verify(client, id), do: Coffrify.request(client, :post, "/domains/#{URI.encode(id)}/verify")
end