Skip to content

Commit

Permalink
Merge pull request #127 from Staffbase/responder-alerts
Browse files Browse the repository at this point in the history
Implement get-responder-alerts API endpoint
  • Loading branch information
Dekunite authored May 22, 2023
2 parents fe35b34 + e728676 commit 630f160
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
9 changes: 9 additions & 0 deletions incident/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,12 @@ func (c *Client) ListNotes(context context.Context, request *ListNotesRequest) (
}
return result, nil
}

func (c *Client) GetResponderAlerts(context context.Context, request *GetResponderAlertsRequest) (*GetResponderAlertsResult, error) {
result := &GetResponderAlertsResult{}
err := c.client.Exec(context, request, result)
if err != nil {
return nil, err
}
return result, nil
}
34 changes: 34 additions & 0 deletions incident/incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,37 @@ func TestResponders_Validate(t *testing.T) {
err = validateResponders(Responders)
assert.Nil(t, err)
}

func TestGetResponderAlertsRequest_Endpoint(t *testing.T) {
request := &GetResponderAlertsRequest{
Id: "adea9e79-5527-4e49-b345-e55ae180ae59",
Identifier: Id,
}
endpoint := request.ResourcePath()
params := request.RequestParams()
assert.Equal(t, "/v1/incidents/adea9e79-5527-4e49-b345-e55ae180ae59/responder-alert-ids", endpoint)
assert.Equal(t, "id", params["identifierType"])
}

func TestGetResponderAlertsRequest_GetParams(t *testing.T) {
request := &GetResponderAlertsRequest{
Limit: 10,
Offset: 30,
Order: "desc",
Direction: "next",
}
params := request.RequestParams()
assert.Equal(t, "10", params["limit"])
assert.Equal(t, "30", params["offset"])
assert.Equal(t, "next", params["direction"])
assert.Equal(t, "desc", params["order"])
}

func TestGetResponderAlertsRequest_Validate(t *testing.T) {
request := &GetResponderAlertsRequest{}
err := request.Validate()
assert.Equal(t, err.Error(), errors.New("Incident ID cannot be blank.").Error())
request.Id = "adea9e79-5527-4e49-b345-e55ae180ae59"
err = request.Validate()
assert.Nil(t, err)
}
55 changes: 55 additions & 0 deletions incident/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,61 @@ func (r *ListNotesRequest) RequestParams() map[string]string {
return params
}

type GetResponderAlertsRequest struct {
client.BaseRequest
Identifier IdentifierType
Id string
Limit int
Offset int
Order Order
Direction string
}

func (r *GetResponderAlertsRequest) Validate() error {
if r.Id == "" {
return errors.New("Incident ID cannot be blank.")
}
if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny {
return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.")
}
return nil
}

func (r *GetResponderAlertsRequest) ResourcePath() string {
return "/v1/incidents/" + r.Id + "/responder-alert-ids"
}

func (r *GetResponderAlertsRequest) Method() string {
return http.MethodGet
}

func (r *GetResponderAlertsRequest) RequestParams() map[string]string {

params := make(map[string]string)

if r.Identifier == Tiny {
params["identifierType"] = "tiny"
} else {
params["identifierType"] = "id"
}

if r.Limit != 0 {
params["limit"] = strconv.Itoa(r.Limit)
}
if r.Offset != 0 {
params["offset"] = strconv.Itoa(r.Offset)
}
if r.Direction != "" {
params["direction"] = r.Direction

}
if r.Order != "" {
params["order"] = string(r.Order)
}

return params
}

type IdentifierType string
type ResponderType string
type Priority string
Expand Down
5 changes: 5 additions & 0 deletions incident/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ type Paging struct {
First string `json:"first"`
Last string `json:"last"`
}

type GetResponderAlertsResult struct {
client.ResultMetadata
AlertIds []string `json:"data"`
}

0 comments on commit 630f160

Please sign in to comment.