Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added type docs for structs #7

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/incident_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,46 @@ defmodule LogpointApi.IncidentApi do
alias LogpointApi.Credential

defmodule TimeRange do
@moduledoc """
@typedoc """
Struct representing a time range with timestamps in epoch.
"""
@type t :: %__MODULE__{ts_from: Number.t(), ts_to: Number.t(), version: String.t()}
@derive {Jason.Encoder, only: [:version, :ts_from, :ts_to]}
defstruct [:ts_from, :ts_to, version: "0.1"]
end

defmodule Incident do
@moduledoc """
@typedoc """
Struct used to fetch an incident.
"""
@type t :: %__MODULE__{incident_obj_id: String.t(), incident_id: String.t()}
@derive {Jason.Encoder, only: [:incident_obj_id, :incident_id]}
defstruct [:incident_obj_id, :incident_id]
end

defmodule IncidentComment do
@moduledoc """
@typedoc """
Struct to add comments to a particular incident.
"""
@type t :: %__MODULE__{_id: String.t(), comments: list()}
@derive {Jason.Encoder, only: [:_id, :comments]}
defstruct _id: "", comments: []
end

defmodule IncidentCommentData do
@moduledoc """
@typedoc """
Struct to add comments to a list of incidents using the `IncidentComment` struct.
"""
@type t :: %__MODULE__{version: String.t(), states: list()}
@derive {Jason.Encoder, only: [:version, :states]}
defstruct version: "0.1", states: [%IncidentComment{}]
end

defmodule IncidentIDs do
@moduledoc """
@typedoc """
Struct that represents a list of incidents.
"""
@type t :: %__MODULE__{version: String.t(), incident_ids: list()}
@derive {Jason.Encoder, only: [:version, :incident_ids]}
defstruct version: "0.1", incident_ids: []
end
Expand Down Expand Up @@ -137,7 +142,8 @@ defmodule LogpointApi.IncidentApi do
end

@doc false
@spec make_request(String.t(), String.t(), atom(), String.t()) :: {:ok, map()} | {:error, String.t()}
@spec make_request(String.t(), String.t(), atom(), String.t()) ::
{:ok, map()} | {:error, String.t()}
defp make_request(ip, path, method, payload) do
url = build_url(ip, path)
headers = [{"Content-Type", "application/json"}]
Expand Down Expand Up @@ -176,7 +182,7 @@ defmodule LogpointApi.IncidentApi do
defp make_payload(%Credential{} = credential) do
%{
"username" => credential.username,
"secret_key" => credential.secret_key,
"secret_key" => credential.secret_key
}
|> Jason.encode!()
end
Expand Down
3 changes: 2 additions & 1 deletion lib/logpoint_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ defmodule LogpointApi do
@moduledoc false

defmodule Credential do
@moduledoc """
@typedoc """
Struct representing credentials used for authorization.
"""
@type t :: %__MODULE__{username: String.t(), secret_key: String.t()}
defstruct [:username, :secret_key]
end
end
14 changes: 11 additions & 3 deletions lib/search_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ defmodule LogpointApi.SearchApi do
@allowed_types ["user_preference", "loginspects", "logpoint_repos", "devices", "livesearches"]

defmodule Query do
@moduledoc """
@typedoc """
Struct representing a Logpoint search query.
"""
@type t :: %__MODULE__{
query: String.t(),
time_range: list(),
limit: Number.t(),
repos: list()
}
@derive {Jason.Encoder, only: [:query, :time_range, :limit, :repos]}
defstruct [:query, :time_range, :limit, :repos]
end

defmodule SearchID do
@moduledoc """
@typedoc """
Struct representing a search id.
"""
@type t :: %__MODULE__{search_id: String.t()}
@derive {Jason.Encoder, only: [:search_id]}
defstruct [:search_id]
end
Expand Down Expand Up @@ -100,7 +107,8 @@ defmodule LogpointApi.SearchApi do
defp build_url(ip, path), do: "https://" <> ip <> path

@doc false
@spec get_allowed_data(String.t(), Credential.t(), String.t()) :: {:ok, map()} | {:error, String.t()}
@spec get_allowed_data(String.t(), Credential.t(), String.t()) ::
{:ok, map()} | {:error, String.t()}
defp get_allowed_data(ip, credential, type) when type in @allowed_types do
payload = build_payload(credential, %{"type" => type})
make_request(ip, "/getalloweddata", payload)
Expand Down
Loading