Skip to content

Commit

Permalink
Merge pull request #13 from opsgenie/add-delete-heartbeat-feature
Browse files Browse the repository at this point in the history
Added delete request to heartbeat also fixed bug while creating heart…
  • Loading branch information
ErenKizilay authored Sep 9, 2019
2 parents 8602e5f + 21d388b commit 4f8ae35
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions heartbeat/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,13 @@ func (c *Client) Disable(context context.Context, heartbeatName string) (*Heartb
}
return result, nil
}

func (c *Client) Delete(context context.Context, heartbeatName string) (*DeleteResult, error) {
deleteResult := &DeleteResult{}
request := &deleteRequest{HeartbeatName: heartbeatName}
err := c.client.Exec(context, request, deleteResult)
if err != nil {
return nil, err
}
return deleteResult, nil
}
7 changes: 7 additions & 0 deletions heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ func TestGetRequest_Validate(t *testing.T) {

assert.Equal(t, err.Error(), errors.New("HeartbeatName cannot be empty").Error())
}

func TestDeleteRequest_Validate(t *testing.T) {
deleteRequest := &deleteRequest{}
err := deleteRequest.Validate()

assert.Equal(t, err.Error(), errors.New("HeartbeatName cannot be empty").Error())
}
19 changes: 18 additions & 1 deletion heartbeat/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type AddRequest struct {
Description string `json:"description,omitempty"`
Interval int `json:"interval"`
IntervalUnit Unit `json:"intervalUnit"`
Enabled bool `json:"enabled,omitempty"`
Enabled bool `json:"enabled"`
OwnerTeam og.OwnerTeam `json:"ownerTeam"`
AlertMessage string `json:"alertMessage,omitempty"`
AlertTag []string `json:"alertTags,omitempty"`
Expand Down Expand Up @@ -186,3 +186,20 @@ func (r disableRequest) ResourcePath() string {
func (r disableRequest) Method() string {
return http.MethodPost
}

type deleteRequest struct {
client.BaseRequest
HeartbeatName string
}

func (r deleteRequest) Validate() error {
return nameValidation(r.HeartbeatName)
}

func (r deleteRequest) ResourcePath() string {
return "/v2/heartbeats/" + r.HeartbeatName
}

func (r deleteRequest) Method() string {
return http.MethodDelete
}
5 changes: 5 additions & 0 deletions heartbeat/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ type AddResult struct {
client.ResultMetadata
Heartbeat
}

type DeleteResult struct {
client.ResultMetadata
Message string `json:"result"`
}

0 comments on commit 4f8ae35

Please sign in to comment.