Current section

Files

Jump to
teac lib teac api guest_star slot.ex
Raw

lib/teac/api/guest_star/slot.ex

defmodule Teac.Api.GuestStar.Slot do
alias Teac.Api
@post_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
session_id: [type: :string, required: true],
guest_id: [type: :string, required: true],
slot_id: [type: :string, required: true]
)
@patch_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
session_id: [type: :string, required: true],
source_slot_id: [type: :string, required: true],
destination_slot_id: [type: :string, required: true]
)
@delete_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
session_id: [type: :string, required: true],
guest_id: [type: :string, required: true],
slot_id: [type: :string, required: true],
should_reinvite_guest: [type: :boolean]
)
@doc """
Allows a host to invite a guest into a specific Guest Star slot.
## Authorization
Requires a user access token with the `channel:manage:guest_star` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster running the session.
* `:moderator_id` - required. The ID of the moderator or broadcaster performing the action.
* `:session_id` - required. The ID of the Guest Star session.
* `:guest_id` - required. The ID of the guest to assign to the slot.
* `:slot_id` - required. The slot ID to assign the guest to.
"""
@spec post(Teac.Client.t(), keyword()) :: {:ok, nil} | {:error, Teac.Error.t()}
def post(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @post_schema) do
{:ok, opts} ->
[
base_url: Api.uri("guest_star/slot"),
headers: Api.headers(client),
params: [
broadcaster_id: opts[:broadcaster_id],
moderator_id: opts[:moderator_id],
session_id: opts[:session_id],
guest_id: opts[:guest_id],
slot_id: opts[:slot_id]
]
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.post()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
@doc """
Allows a host to swap guests between two Guest Star slots.
## Authorization
Requires a user access token with the `channel:manage:guest_star` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster running the session.
* `:moderator_id` - required. The ID of the moderator or broadcaster performing the action.
* `:session_id` - required. The ID of the Guest Star session.
* `:source_slot_id` - required. The ID of the slot to move the guest from.
* `:destination_slot_id` - required. The ID of the slot to move the guest to.
"""
@spec patch(Teac.Client.t(), keyword()) :: {:ok, nil} | {:error, Teac.Error.t()}
def patch(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @patch_schema) do
{:ok, opts} ->
[
base_url: Api.uri("guest_star/slot"),
headers: Api.headers(client),
params: [
broadcaster_id: opts[:broadcaster_id],
moderator_id: opts[:moderator_id],
session_id: opts[:session_id],
source_slot_id: opts[:source_slot_id],
destination_slot_id: opts[:destination_slot_id]
]
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.patch()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
@doc """
Removes a guest from their assigned Guest Star slot.
## Authorization
Requires a user access token with the `channel:manage:guest_star` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster running the session.
* `:moderator_id` - required. The ID of the moderator or broadcaster performing the action.
* `:session_id` - required. The ID of the Guest Star session.
* `:guest_id` - required. The ID of the guest to remove.
* `:slot_id` - required. The slot ID to remove the guest from.
* `:should_reinvite_guest` - optional. If `true`, sends a new invite after removing.
"""
@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} ->
params =
[
broadcaster_id: opts[:broadcaster_id],
moderator_id: opts[:moderator_id],
session_id: opts[:session_id],
guest_id: opts[:guest_id],
slot_id: opts[:slot_id],
should_reinvite_guest: opts[:should_reinvite_guest]
]
|> Enum.reject(fn {_k, v} -> is_nil(v) end)
[
base_url: Api.uri("guest_star/slot"),
headers: Api.headers(client),
params: params
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.delete()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end