diff --git a/README.md b/README.md index b0d0df9..7b2c9c2 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add `mux` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:mux, "~> 1.9.0"} + {:mux, "~> 2.0.0"} ] end ``` diff --git a/lib/mux/support/fixtures.ex b/lib/mux/support/fixtures.ex index 5f1be58..61075a9 100644 --- a/lib/mux/support/fixtures.ex +++ b/lib/mux/support/fixtures.ex @@ -73,6 +73,17 @@ defmodule Mux.Fixtures do } end + def playback_id_full do + %{ + "policy" => "public", + "object" => %{ + "type" => "live_stream", + "id" => "ZXs9U1Wqr3C4GBVCOYRQOA00lLtijnVhehJIb8tlDzL00" + }, + "id" => "7IxC7stYLro5Z4nEs97J02OkLEKFME6mvhnuRJybhRKU" + } + end + def input_info() do %{ "file" => %{ diff --git a/lib/mux/video/assets.ex b/lib/mux/video/assets.ex index 22c01c8..e75f01e 100644 --- a/lib/mux/video/assets.ex +++ b/lib/mux/video/assets.ex @@ -4,7 +4,7 @@ defmodule Mux.Video.Assets do """ alias Mux.{Base, Fixtures} - @path "/video/v1" + @path "/video/v1/assets" @doc """ Create a new asset. @@ -21,7 +21,7 @@ defmodule Mux.Video.Assets do """ def create(client, params) do - Base.post(client, @path <> "/assets", params) + Base.post(client, @path, params) end @doc """ @@ -37,7 +37,7 @@ defmodule Mux.Video.Assets do #{inspect([Fixtures.asset(), Fixtures.asset()])} """ - def list(client, params \\ []), do: Base.get(client, @path <> "/assets", query: params) + def list(client, params \\ []), do: Base.get(client, @path, query: params) @doc """ Retrieve an asset by ID. @@ -53,7 +53,7 @@ defmodule Mux.Video.Assets do """ def get(client, asset_id, options \\ []) do - Base.get(client, @path <> "/assets/" <> asset_id, query: options) + Base.get(client, "#{@path}/#{asset_id}", query: options) end @doc """ @@ -70,7 +70,7 @@ defmodule Mux.Video.Assets do """ def delete(client, asset_id, params \\ []) do - Base.delete(client, @path <> "/assets/" <> asset_id, query: params) + Base.delete(client, "#{@path}/#{asset_id}", query: params) end @doc """ @@ -87,7 +87,7 @@ defmodule Mux.Video.Assets do """ def input_info(client, asset_id, params \\ []) do - Base.get(client, @path <> "/assets/" <> asset_id <> "/input-info", query: params) + Base.get(client, "#{@path}/#{asset_id}/input-info", query: params) end @doc """ @@ -104,7 +104,7 @@ defmodule Mux.Video.Assets do """ def update_mp4_support(client, asset_id, params) do - Base.put(client, @path <> "/assets/" <> asset_id <> "/mp4-support", params) + Base.put(client, "#{@path}/#{asset_id}/mp4-support", params) end @doc """ @@ -121,6 +121,57 @@ defmodule Mux.Video.Assets do """ def update_master_access(client, asset_id, params) do - Base.put(client, @path <> "/assets/" <> asset_id <> "/master-access", params) + Base.put(client, "#{@path}/#{asset_id}/master-access", params) + end + + @doc """ + Create a new playback ID. + + Returns `{:ok, playback_id, %Telsa.Env{}}`. + + ## Examples + + iex> client = Mux.Base.new("my_token_id", "my_token_secret") + iex> {:ok, playback_id, _env} = Mux.Video.Assets.create_playback_id(client, "00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc", %{policy: "public"}) + iex> playback_id + #{inspect(Fixtures.playback_id)} + + """ + def create_playback_id(client, asset_id, params) do + Base.post(client, "#{@path}/#{asset_id}/playback-ids", params) + end + + @doc """ + Retrieve a playback ID. + + Returns `{:ok, playback_id, %Telsa.Env{}}`. + + ## Examples + + iex> client = Mux.Base.new("my_token_id", "my_token_secret") + iex> {:ok, playback_id, _env} = Mux.Video.Assets.get_playback_id(client, "00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc", "FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE") + iex> playback_id + #{inspect(Fixtures.playback_id)} + + """ + def get_playback_id(client, asset_id, playback_id) do + Base.get(client, "#{@path}/#{asset_id}/playback-ids/#{playback_id}") + end + + @doc """ + Delete a playback ID. + + Returns `{:ok, nil, %Telsa.Env{}}`. + + ## Examples + + iex> client = Mux.Base.new("my_token_id", "my_token_secret") + iex> {status, "", _env} = Mux.Video.Assets.delete_playback_id(client, "00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc", "FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE") + iex> status + :ok + + """ + def delete_playback_id(client, asset_id, playback_id) do + Base.delete(client, "#{@path}/#{asset_id}/playback-ids/#{playback_id}") end end diff --git a/lib/mux/video/playback_ids.ex b/lib/mux/video/playback_ids.ex index 2d1bf75..06b2629 100644 --- a/lib/mux/video/playback_ids.ex +++ b/lib/mux/video/playback_ids.ex @@ -2,60 +2,26 @@ defmodule Mux.Video.PlaybackIds do @moduledoc """ This module provides functions around managing Playback IDs in Mux Video. Playback IDs are the public identifier for streaming a piece of content and can include policies such as `signed` or - `public`. [API Documentation](https://docs.mux.com/v1/reference#playback-ids). + `public`. [API Documentation](https://docs.mux.com/api-reference/video#tag/playback-id). """ alias Mux.{Base, Fixtures} - @doc """ - Create a new playback ID. - - Returns `{:ok, playback_id, raw_env}`. - - ## Examples - - iex> client = Mux.Base.new("my_token_id", "my_token_secret") - iex> {:ok, playback_id, _env} = Mux.Video.PlaybackIds.create(client, "00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc", %{policy: "public"}) - iex> playback_id - #{inspect(Fixtures.playback_id())} - - """ - def create(client, asset_id, params) do - Base.post(client, build_base_path(asset_id), params) - end - - @doc """ - Retrieve a playback ID by ID. - - Returns `{:ok, playback_id, raw_env}`. - - ## Examples - - iex> client = Mux.Base.new("my_token_id", "my_token_secret") - iex> {:ok, playback_id, _env} = Mux.Video.PlaybackIds.get(client, "00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc", "FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE") - iex> playback_id - #{inspect(Fixtures.playback_id())} - - """ - def get(client, asset_id, playback_id) do - Base.get(client, build_base_path(asset_id) <> "/" <> playback_id) - end + @path "/video/v1/playback-ids" @doc """ - Delete a playback ID. + Retrieve a asset or live stream identifier by Playback ID. - Returns `{:ok, nil, raw_env}`. + Returns `{:ok, playback_id_full, raw_env}`. ## Examples iex> client = Mux.Base.new("my_token_id", "my_token_secret") - iex> {status, "", _env} = Mux.Video.PlaybackIds.delete(client, "00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc", "FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE") - iex> status - :ok + iex> {:ok, playback_id_full, _env} = Mux.Video.PlaybackIds.get(client, "FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE") + iex> playback_id_full + #{inspect(Fixtures.playback_id_full())} """ - def delete(client, asset_id, playback_id) do - Base.delete(client, build_base_path(asset_id) <> "/" <> playback_id) + def get(client, playback_id) do + Base.get(client, "#{@path}/#{playback_id}") end - - defp build_base_path(asset_id), do: "/video/v1/assets/#{asset_id}/playback-ids" end diff --git a/mix.exs b/mix.exs index be087e9..7b74a24 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule Mux.MixProject do @github_url "https://github.com/muxinc/mux-elixir" - @version "1.9.0" + @version "2.0.0" def project do [ diff --git a/test/mux/video/assets_test.exs b/test/mux/video/assets_test.exs index 2e45ea1..db052dd 100644 --- a/test/mux/video/assets_test.exs +++ b/test/mux/video/assets_test.exs @@ -40,7 +40,7 @@ defmodule Mux.Video.AssetsTest do } } - %{method: :post} -> + %{method: :post, url: @base_url <> "/video/v1/assets"} -> %Tesla.Env{ status: 201, body: %{ @@ -70,6 +70,38 @@ defmodule Mux.Video.AssetsTest do } } + %{ + method: :post, + url: @base_url <> "/video/v1/assets/00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc/playback-ids" + } -> + %Tesla.Env{ + status: 201, + body: %{ + "data" => Mux.Fixtures.playback_id() + } + } + + %{ + method: :get, + url: + @base_url <> + "/video/v1/assets/00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc/playback-ids/FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE" + } -> + %Tesla.Env{ + status: 200, + body: %{ + "data" => Mux.Fixtures.playback_id() + } + } + + %{ + method: :delete, + url: + @base_url <> + "/video/v1/assets/00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc/playback-ids/FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE" + } -> + %Tesla.Env{status: 204, body: ""} + %{method: :delete} -> %Tesla.Env{status: 204, body: ""} end) diff --git a/test/mux/video/live_streams_test.exs b/test/mux/video/live_streams_test.exs index 353a09c..a537585 100644 --- a/test/mux/video/live_streams_test.exs +++ b/test/mux/video/live_streams_test.exs @@ -102,7 +102,7 @@ defmodule Mux.Video.LiveStreamsTest do "data" => "" } } - + %{method: :put, url: @base_url <> "/aA02skpHXoLrbQm49qIzAG6RtewFOcDEY/enable"} -> %Tesla.Env{ status: 200, @@ -110,8 +110,7 @@ defmodule Mux.Video.LiveStreamsTest do "data" => "" } } - - + %{method: :put, url: @base_url <> "/aA02skpHXoLrbQm49qIzAG6RtewFOcDEY/disable"} -> %Tesla.Env{ status: 200, diff --git a/test/mux/video/playback_ids_test.exs b/test/mux/video/playback_ids_test.exs index ec8e654..d82f016 100644 --- a/test/mux/video/playback_ids_test.exs +++ b/test/mux/video/playback_ids_test.exs @@ -1,32 +1,21 @@ -defmodule Mux.PlaybackIdsTest do +defmodule Mux.Video.PlaybackIdsTest do use ExUnit.Case import Tesla.Mock doctest Mux.Video.PlaybackIds - @base_url "https://api.mux.com/video/v1/assets/00ecNLnqiG8v00TLqqeZ00uCE5wCAaO3kKc/playback-ids" + @base_url "https://api.mux.com/video/v1/playback-ids" setup do client = Mux.Base.new("token_id", "token_secret", base_url: @base_url) mock(fn - %{method: :post, url: @base_url} -> - %Tesla.Env{ - status: 201, - body: %{ - "data" => Mux.Fixtures.playback_id() - } - } - %{method: :get, url: @base_url <> "/FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE"} -> %Tesla.Env{ status: 200, body: %{ - "data" => Mux.Fixtures.playback_id() + "data" => Mux.Fixtures.playback_id_full() } } - - %{method: :delete, url: @base_url <> "/FRDDXsjcNgD013rx1M4CDunZ86xkq8A02hfF3b6XAa7iE"} -> - %Tesla.Env{status: 204, body: ""} end) {:ok, %{client: client}}