Current section

Files

Jump to
teac lib teac api moderation shield_mode.ex
Raw

lib/teac/api/moderation/shield_mode.ex

defmodule Teac.Api.Moderation.ShieldMode do
alias Teac.Api
@get_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true]
)
@put_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
is_active: [type: :boolean, required: true]
)
@doc """
Gets the broadcaster's Shield Mode activation status.
## Authorization
Requires a user access token with the `moderator:read:shield_mode` or `moderator:manage:shield_mode` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster whose Shield Mode status to get.
* `:moderator_id` - required. The ID of the moderator or broadcaster making the request.
"""
@spec get(Teac.Client.t(), keyword()) :: {:ok, list(map()), Teac.RateLimit.t()} | {:error, Teac.Error.t()}
def get(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @get_schema) do
{:ok, opts} ->
[
base_url: Api.uri("moderation/shield_mode"),
params: [broadcaster_id: opts[:broadcaster_id], moderator_id: opts[:moderator_id]],
headers: Api.headers(client)
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.get()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
@doc """
Activates or deactivates the broadcaster's Shield Mode.
## Authorization
Requires a user access token with the `moderator:manage:shield_mode` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster whose Shield Mode to update.
* `:moderator_id` - required. The ID of the moderator or broadcaster making the request.
* `:is_active` - required. `true` to activate Shield Mode, `false` to deactivate it.
"""
@spec put(Teac.Client.t(), keyword()) :: {:ok, list(map()), Teac.RateLimit.t()} | {:error, Teac.Error.t()}
def put(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @put_schema) do
{:ok, opts} ->
[
base_url: Api.uri("moderation/shield_mode"),
params: [broadcaster_id: opts[:broadcaster_id], moderator_id: opts[:moderator_id]],
headers: Api.headers(client),
json: %{is_active: opts[:is_active]}
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.put()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end