Current section
Files
Jump to
Current section
Files
lib/slack/bot/credentials.ex
defmodule Slack.Bot.Credentials do
@moduledoc ~S"""
Slack bot credential details.
Includes the bot Slack user and team.
"""
alias Slack.{Team, User}
@typedoc @moduledoc
@type t :: %__MODULE__{
self: Slack.User.t(),
team: Slack.Team.t(),
url: String.t()
}
@enforce_keys [
:self,
:team,
:url
]
defstruct @enforce_keys
@doc ~S"""
Parse Slack bot credentials.
"""
@spec parse(map) :: {:ok, t} | {:error, atom}
def parse(data = %{}) do
with {:ok, self} <- User.parse(MapX.get(data, :self)),
{:ok, team} <- Team.parse(MapX.get(data, :team)),
url when is_binary(url) <- MapX.get(data, :url) || {:error, :invalid_url} do
{:ok, %__MODULE__{self: self, team: team, url: url}}
end
end
def parse(_), do: {:error, :invalid_credentials}
end