Current section
Files
Jump to
Current section
Files
lib/teac/api/channels/commercial.ex
defmodule Teac.Api.Channels.Commercial do
alias Teac.Api
@schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
length: [type: :integer, required: true]
)
@doc """
Starts a commercial on the broadcaster's channel.
## Authorization
Requires a user access token with the `channel:edit:commercial` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster who wants to run the commercial.
* `:length` - required. The length of the commercial in seconds. Valid values: 30, 60, 90, 120, 150, 180.
"""
@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, @schema) do
{:ok, opts} ->
[
base_url: Api.uri("channels/commercial"),
headers: Api.headers(client),
json: %{broadcaster_id: opts[:broadcaster_id], length: opts[:length]}
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.post()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end