Current section

Files

Jump to
barrel_ex_http lib barrel replication.ex
Raw

lib/barrel/replication.ex

defmodule BarrelEx.Replication do
@moduledoc """
Manage database replication tasks
"""
alias BarrelEx.Request
@doc """
Retrieve the list of replications tasks and
the response status.
"""
@spec get() :: {atom(), map()}
def get do
with url = make_url() do
Request.get(url)
end
end
@doc """
Retrieve the list of replications tasks.
"""
@spec get!() :: map()
def get! do
with url = make_url() do
Request.get!(url)
end
end
@doc """
Create a new replication task.
Returns also the response status.
"""
@spec create(String.t(), String.t()) :: {atom(), map()}
def create(source, target) do
body = %{source: source, target: target}
with url = make_url() do
Request.post(url, body)
end
end
@doc """
Create a new replication task.
"""
@spec create!(String.t(), String.t()) :: map()
def create!(source, target) do
body = %{source: source, target: target}
with url = make_url() do
Request.post!(url, body)
end
end
@doc """
Delete a replication task with the id `rep_id`.
Returns also the response status.
"""
@spec delete(String.t()) :: {atom(), map()}
def delete(rep_id) do
with url = make_url(rep_id) do
Request.delete(url)
end
end
@doc """
Delete a replication task with the id `rep_id`.
"""
@spec delete!(String.t()) :: map()
def delete!(rep_id) do
with url = make_url(rep_id) do
Request.delete!(url)
end
end
defp make_url do
"replicate/"
end
defp make_url(rep_id) do
make_url() <> rep_id
end
end