diff --git a/incident/incident.go b/incident/incident.go index c5625fc..214db30 100644 --- a/incident/incident.go +++ b/incident/incident.go @@ -62,6 +62,15 @@ func (c *Client) List(context context.Context, request *ListRequest) (*ListResul return result, nil } +func (c *Client) Resolve(context context.Context, request *ResolveRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + func (c *Client) Close(context context.Context, request *CloseRequest) (*AsyncResult, error) { result := &AsyncResult{} err := c.client.Exec(context, request, result) diff --git a/incident/incident_test.go b/incident/incident_test.go index b8f1ccd..3fb575e 100644 --- a/incident/incident_test.go +++ b/incident/incident_test.go @@ -101,6 +101,28 @@ func TestListRequest_GetParams(t *testing.T) { assert.Equal(t, "asc", params["order"]) } +func TestResolveRequest_Validate(t *testing.T) { + request := &ResolveRequest{ + Identifier: Tiny, + } + 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) +} + +func TestResolveRequest_Endpoint(t *testing.T) { + request := &ResolveRequest{ + Id: "adea9e79-5527-4e49-b345-e55ae180ae59", + Identifier: Tiny, + } + endpoint := request.ResourcePath() + params := request.RequestParams() + assert.Equal(t, "/v1/incidents/adea9e79-5527-4e49-b345-e55ae180ae59/resolve", endpoint) + assert.Equal(t, "tiny", params["identifierType"]) +} + func TestCloseRequest_Validate(t *testing.T) { request := &CloseRequest{ Identifier: Tiny, diff --git a/incident/request.go b/incident/request.go index 3bfc673..8f878de 100644 --- a/incident/request.go +++ b/incident/request.go @@ -197,6 +197,44 @@ func (r *ListRequest) RequestParams() map[string]string { return params } +type ResolveRequest struct { + client.BaseRequest + Id string + Identifier IdentifierType + Note string `json:"note,omitempty"` +} + +func (r *ResolveRequest) 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 *ResolveRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/resolve" +} + +func (r *ResolveRequest) Method() string { + return http.MethodPost +} + +func (r *ResolveRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + type CloseRequest struct { client.BaseRequest Id string