Current section

Files

Jump to
teac lib teac api moderation suspicious_users.ex
Raw

lib/teac/api/moderation/suspicious_users.ex

defmodule Teac.Api.Moderation.SuspiciousUsers do
alias Teac.Api
@post_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
user_id: [type: :string, required: true],
status: [type: {:in, ["restricted", "monitored"]}, required: true]
)
@delete_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
user_id: [type: :string, required: true]
)
@doc """
Adds a suspicious user status to a chatter in the broadcaster's channel.
## Authorization
Requires a user access token with the `moderator:manage:suspicious_users` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster's channel.
* `:moderator_id` - required. The ID of the moderator adding the status.
* `:user_id` - required. The ID of the user to flag as suspicious.
* `:status` - required. The suspicious status. Valid values: `"restricted"`, `"monitored"`.
"""
@spec post(Teac.Client.t(), keyword()) :: {:ok, list(map())} | {:error, Teac.Error.t()}
def post(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @post_schema) do
{:ok, opts} ->
[
base_url: Api.uri("moderation/suspicious_users"),
params: [
broadcaster_id: opts[:broadcaster_id],
moderator_id: opts[:moderator_id]
],
headers: Api.headers(client),
json: %{user_id: opts[:user_id], status: opts[:status]}
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.post()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
@doc """
Removes the suspicious user status from a chatter in the broadcaster's channel.
## Authorization
Requires a user access token with the `moderator:manage:suspicious_users` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster's channel.
* `:moderator_id` - required. The ID of the moderator removing the status.
* `:user_id` - required. The ID of the user to remove the suspicious status from.
"""
@spec delete(Teac.Client.t(), keyword()) :: {:ok, nil} | {:error, Teac.Error.t()}
def delete(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @delete_schema) do
{:ok, opts} ->
[
base_url: Api.uri("moderation/suspicious_users"),
params: [
broadcaster_id: opts[:broadcaster_id],
moderator_id: opts[:moderator_id],
user_id: opts[:user_id]
],
headers: Api.headers(client)
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.delete()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end