Current section
Files
Jump to
Current section
Files
lib/teac/api/raids.ex
defmodule Teac.Api.Raids do
alias Teac.Api
@post_schema NimbleOptions.new!(
from_broadcaster_id: [type: :string, required: true],
to_broadcaster_id: [type: :string, required: true]
)
@delete_schema NimbleOptions.new!(broadcaster_id: [type: :string, required: true])
@doc """
Raids another channel by sending the broadcaster's viewers to the targeted channel.
## Authorization
Requires a user access token with the `channel:manage:raids` scope.
## Options
* `:from_broadcaster_id` - required. The ID of the broadcaster initiating the raid.
* `:to_broadcaster_id` - required. The ID of the broadcaster to raid.
"""
@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, @post_schema) do
{:ok, opts} ->
[
base_url: Api.uri("raids"),
params: [
from_broadcaster_id: opts[:from_broadcaster_id],
to_broadcaster_id: opts[:to_broadcaster_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
@doc """
Cancels a pending raid.
## Authorization
Requires a user access token with the `channel:manage:raids` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster that initiated the raid.
"""
@spec delete(Teac.Client.t(), keyword()) :: {:ok, nil, Teac.RateLimit.t()} | {:error, Teac.Error.t()}
def delete(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @delete_schema) do
{:ok, opts} ->
[
base_url: Api.uri("raids"),
params: [broadcaster_id: opts[:broadcaster_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