Current section

Files

Jump to
lab lib lab.ex
Raw

lib/lab.ex

defmodule Lab do
@moduledoc """
Documentation for Lab.
"""
alias Lab.Agent
@doc """
Gets all projects available for the authenticated user.
Returns `[%Lab.Project{}]`.
## Examples
iex> alias Lab.Project
Lab.Project
iex> Lab.all(Project)
[%Lab.Project{}]
iex> Lab.all(Lab.Project, per_page: 2)
[%Lab.Project{}]
"""
def all(resource, opts \\ []) do
resource = to_resource_string(resource)
Agent.all(resource, opts)
end
@doc """
Gets a single project.
Returns `%Lab.Project{}`.
## Examples
iex> alias Lab.Project
Lab.Project
iex> Lab.get(Project, 1)
%Lab.Project{}
"""
def get(resource, id, opts \\ []) do
resource = to_resource_string(resource) <> "/#{id}"
Agent.get(resource, opts)
end
defp to_resource_string(resource) do
resource = Atom.to_string(resource)
resource = resource |> String.split(".")
|> List.last
|> String.downcase
"/" <> resource <> "s"
end
end