Current section
Files
Jump to
Current section
Files
lib/teac/api/schedule/settings.ex
defmodule Teac.Api.Schedule.Settings do
alias Teac.Api
@schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
is_vacation_enabled: [type: :boolean],
vacation_start_time: [type: :string],
vacation_end_time: [type: :string],
timezone: [type: :string]
)
@doc """
Updates the broadcaster's schedule settings, such as setting vacation mode.
## Authorization
Requires a user access token with the `channel:manage:schedule` scope.
## Options
* `:broadcaster_id` - required.
* `:is_vacation_enabled` - optional. If `true`, enables vacation mode.
* `:vacation_start_time` - optional. RFC3339 timestamp for vacation start.
* `:vacation_end_time` - optional. RFC3339 timestamp for vacation end.
* `:timezone` - optional. IANA time zone for vacation start/end times.
"""
@spec patch(Teac.Client.t(), keyword()) :: {:ok, nil} | {:error, Teac.Error.t()}
def patch(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @schema) do
{:ok, opts} ->
body =
%{
is_vacation_enabled: opts[:is_vacation_enabled],
vacation_start_time: opts[:vacation_start_time],
vacation_end_time: opts[:vacation_end_time],
timezone: opts[:timezone]
}
|> Enum.reject(fn {_, v} -> is_nil(v) end)
|> Map.new()
[
base_url: Api.uri("schedule/settings"),
params: [broadcaster_id: opts[:broadcaster_id]],
headers: Api.headers(client),
json: body
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.patch!()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end