Current section
Files
Jump to
Current section
Files
lib/teac/api/chat/shoutouts.ex
defmodule Teac.Api.Chat.Shoutouts do
alias Teac.Api
@schema NimbleOptions.new!(
from_broadcaster_id: [type: :string, required: true],
to_broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true]
)
@doc """
Sends a shoutout to the specified broadcaster.
Rate limits: the broadcaster may send a shoutout once every 2 minutes, and a given broadcaster may be shouted out once every 60 minutes.
## Authorization
Requires a user access token with the `moderator:manage:shoutouts` scope.
## Options
* `:from_broadcaster_id` - required. The ID of the broadcaster sending the shoutout.
* `:to_broadcaster_id` - required. The ID of the broadcaster being shouted out.
* `:moderator_id` - required. The ID of the moderator or broadcaster making the request.
"""
@spec post(Teac.Client.t(), keyword()) :: {:ok, nil} | {:error, Teac.Error.t()}
def post(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @schema) do
{:ok, opts} ->
[
base_url: Api.uri("chat/shoutouts"),
params: [
from_broadcaster_id: opts[:from_broadcaster_id],
to_broadcaster_id: opts[:to_broadcaster_id],
moderator_id: opts[:moderator_id]
],
headers: Api.headers(client)
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.post()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end