Skip to content

Commit

Permalink
incident_api: added resolve incidents
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelFangel committed Apr 27, 2024
1 parent 358ea44 commit 0b12bea
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/incident_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ defmodule LogpointApi.IncidentApi do
defstruct version: "0.1", states: [%IncidentComment{}]
end

defmodule IncidentIDs do
@derive {Jason.Encoder, only: [:version, :incident_ids]}
defstruct version: "0.1", incident_ids: []
end

@spec get_incidents(String.t(), Credential.t(), TimeRange.t()) ::
{:ok, map()} | {:error, String.t()}
def get_incidents(ip, credential, %TimeRange{} = time_range),
Expand Down Expand Up @@ -48,15 +53,23 @@ defmodule LogpointApi.IncidentApi do

@spec add_comments(String.t(), Credential.t(), IncidentCommentData.t()) ::
{:ok, map()} | {:error, String.t()}
def add_comments(ip, %Credential{} = credential, %IncidentCommentData{} = request_data) do
payload =
%{
"username" => credential.username,
"secret_key" => credential.secret_key,
"requestData" => request_data
}

make_request(ip, "/add_incident_comment", :post, payload)
def add_comments(ip, credential, %IncidentCommentData{} = incident_comment_data),
do: update_incident_state(ip, "/add_incident_comment", credential, incident_comment_data)

@spec resolve_incidents(String.t(), Credential.t(), IncidentIDs.t()) ::
{:ok, map()} | {:error, String.t()}
def resolve_incidents(ip, credential, %IncidentIDs{} = incident_ids),
do: update_incident_state(ip, "/resolve_incident", credential, incident_ids)

@spec update_incident_state(String.t(), String.t(), Credential.t(), map()) :: {:ok, map()} | {:error, String.t()}
defp update_incident_state(ip, path, %Credential{} = credential, request_data) do
payload = %{
"username" => credential.username,
"secret_key" => credential.secret_key,
"requestData" => request_data
}

make_request(ip, path, :post, payload)
end

@spec get_incident_information(String.t(), String.t(), Credential.t(), map()) ::
Expand Down

0 comments on commit 0b12bea

Please sign in to comment.