Skip to content

Commit

Permalink
Merge branch 'master' of github.com:muxinc/mux-elixir
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjha committed Jun 4, 2021
2 parents 81cf2ad + 9ddf50b commit ab11146
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
11 changes: 11 additions & 0 deletions lib/mux/support/fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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" => %{
Expand Down
67 changes: 59 additions & 8 deletions lib/mux/video/assets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 """
Expand All @@ -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.
Expand All @@ -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 """
Expand All @@ -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 """
Expand All @@ -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 """
Expand All @@ -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 """
Expand All @@ -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
52 changes: 9 additions & 43 deletions lib/mux/video/playback_ids.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down
34 changes: 33 additions & 1 deletion test/mux/video/assets_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Mux.Video.AssetsTest do
}
}

%{method: :post} ->
%{method: :post, url: @base_url <> "/video/v1/assets"} ->
%Tesla.Env{
status: 201,
body: %{
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions test/mux/video/live_streams_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@ defmodule Mux.Video.LiveStreamsTest do
"data" => ""
}
}

%{method: :put, url: @base_url <> "/aA02skpHXoLrbQm49qIzAG6RtewFOcDEY/enable"} ->
%Tesla.Env{
status: 200,
body: %{
"data" => ""
}
}



%{method: :put, url: @base_url <> "/aA02skpHXoLrbQm49qIzAG6RtewFOcDEY/disable"} ->
%Tesla.Env{
status: 200,
Expand Down
17 changes: 3 additions & 14 deletions test/mux/video/playback_ids_test.exs
Original file line number Diff line number Diff line change
@@ -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}}
Expand Down

0 comments on commit ab11146

Please sign in to comment.