Current section
Files
Jump to
Current section
Files
lib/teac/api/schedule/segment.ex
defmodule Teac.Api.Schedule.Segment do
alias Teac.Api
def post(opts) do
token = Keyword.fetch!(opts, :token)
client_id = Keyword.get(opts, :client_id, Teac.client_id())
broadcaster_id = Keyword.fetch!(opts, :broadcaster_id)
start_time = Keyword.fetch!(opts, :start_time)
duration = Keyword.fetch!(opts, :duration)
timezone = Keyword.fetch!(opts, :timezone)
is_recurring = Keyword.get(opts, :is_recurring, nil)
title = Keyword.get(opts, :title, nil)
body =
%{
start_time: start_time,
duration: duration,
timezone: timezone,
is_recurring: is_recurring,
title: title
}
|> Enum.reject(fn {_, v} -> is_nil(v) end)
|> Map.new()
[
base_url: Api.uri("schedule/segment"),
params: [broadcaster_id: broadcaster_id],
headers: Api.headers(token, client_id),
json: body
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.post!()
|> Api.handle_response()
end
def patch(opts) do
token = Keyword.fetch!(opts, :token)
client_id = Keyword.get(opts, :client_id, Teac.client_id())
broadcaster_id = Keyword.fetch!(opts, :broadcaster_id)
id = Keyword.fetch!(opts, :id)
start_time = Keyword.get(opts, :start_time, nil)
duration = Keyword.get(opts, :duration, nil)
timezone = Keyword.get(opts, :timezone, nil)
title = Keyword.get(opts, :title, nil)
is_canceled = Keyword.get(opts, :is_canceled, nil)
body =
%{
start_time: start_time,
duration: duration,
timezone: timezone,
title: title,
is_canceled: is_canceled
}
|> Enum.reject(fn {_, v} -> is_nil(v) end)
|> Map.new()
[
base_url: Api.uri("schedule/segment"),
params: [broadcaster_id: broadcaster_id, id: id],
headers: Api.headers(token, client_id),
json: body
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.patch!()
|> Api.handle_response()
end
def delete(opts) do
token = Keyword.fetch!(opts, :token)
client_id = Keyword.get(opts, :client_id, Teac.client_id())
broadcaster_id = Keyword.fetch!(opts, :broadcaster_id)
id = Keyword.fetch!(opts, :id)
[
base_url: Api.uri("schedule/segment"),
params: [broadcaster_id: broadcaster_id, id: id],
headers: Api.headers(token, client_id)
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.delete!()
|> Api.handle_response()
end
end