Skip to content

Commit

Permalink
Adds update method with respect to current values russellcardullo#26
Browse files Browse the repository at this point in the history
  • Loading branch information
RafPe committed May 14, 2018
1 parent 3448ee0 commit 5c7ce16
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pingdom/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,35 @@ func (cs *CheckService) Update(id int, check Check) (*PingdomResponse, error) {
return m, err
}

// UpdateTarget will update the check represented by the given ID with the values
// in the given check. It will remove values which are empty ones.
func (cs *CheckService) UpdateTarget(id int, check Check) (*PingdomResponse, error) {
if err := check.Valid(); err != nil {
return nil, err
}

targetValues := check.PutParams()

//To avoid modification of check into default values - remove unwanted params
for k, v := range targetValues {
if v == "" {
delete(targetValues, k)
}
}

req, err := cs.client.NewRequest("PUT", "/checks/"+strconv.Itoa(id), targetValues)
if err != nil {
return nil, err
}

m := &PingdomResponse{}
_, err = cs.client.Do(req, m)
if err != nil {
return nil, err
}
return m, err
}

// DeleteCheck will delete the check for the given ID.
func (cs *CheckService) Delete(id int) (*PingdomResponse, error) {
req, err := cs.client.NewRequest("DELETE", "/checks/"+strconv.Itoa(id), nil)
Expand Down

0 comments on commit 5c7ce16

Please sign in to comment.