Current section
Files
Jump to
Current section
Files
lib/teac/api/streams/key.ex
defmodule Teac.Api.Streams.Key do
alias Teac.Api
@schema NimbleOptions.new!(broadcaster_id: [type: :string, required: true])
@doc """
Gets the channel's stream key.
## Authorization
Requires a user access token with the `channel:read:stream_key` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster whose stream key to get.
"""
@spec get(Teac.Client.t(), keyword()) :: {:ok, list(map())} | {:error, Teac.Error.t()}
def get(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @schema) do
{:ok, opts} ->
[
base_url: Api.uri("streams/key"),
params: [broadcaster_id: opts[:broadcaster_id]],
headers: Api.headers(client)
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.get()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end