Current section
Files
Jump to
Current section
Files
lib/teac/api/moderation/warnings.ex
defmodule Teac.Api.Moderation.Warnings do
alias Teac.Api
@schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
user_id: [type: :string, required: true],
reason: [type: :string, required: true]
)
@doc """
Warns a user in the specified broadcaster's chat room.
## Authorization
Requires a user access token with the `moderator:manage:warnings` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster whose chat the user is being warned in.
* `:moderator_id` - required. The ID of the moderator warning the user.
* `:user_id` - required. The ID of the user being warned.
* `:reason` - required. The reason for the warning. Max 500 characters.
"""
@spec post(Teac.Client.t(), keyword()) :: {:ok, list(map()), Teac.RateLimit.t()} | {:error, Teac.Error.t()}
def post(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @schema) do
{:ok, opts} ->
[
base_url: Api.uri("moderation/warnings"),
params: [broadcaster_id: opts[:broadcaster_id], moderator_id: opts[:moderator_id]],
headers: Api.headers(client),
json: %{data: %{user_id: opts[:user_id], reason: opts[:reason]}}
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.post()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end