Skip to content

Commit

Permalink
Add DeleteTimeEntry()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 3, 2019
1 parent 1a9c797 commit 0cf7a8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type MiteApi interface {
TimeEntry(id string) (*TimeEntry, error)
CreateTimeEntry(command *TimeEntryCommand) (*TimeEntry, error)
EditTimeEntry(id string, command *TimeEntryCommand) error
DeleteTimeEntry(id string) error
Projects() ([]*Project, error)
Services() ([]*Service, error)
}
Expand Down Expand Up @@ -100,3 +101,18 @@ func (a *miteApi) patch(resource string, body interface{}) error {

return err
}

func (a *miteApi) delete(resource string) error {
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/%s", a.url, resource), nil)
if err != nil {
return err
}
req.Header.Add("X-MiteApiKey", a.key)
req.Header.Add("User-Agent", userAgent)

res, err := a.client.Do(req)

defer func() { _ = res.Body.Close() }()

return err
}
4 changes: 4 additions & 0 deletions mite/time_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,7 @@ func (a *miteApi) CreateTimeEntry(command *TimeEntryCommand) (*TimeEntry, error)
func (a *miteApi) EditTimeEntry(id string, command *TimeEntryCommand) error {
return a.patch(fmt.Sprintf("/time_entries/%s.json", id), command.toRequest())
}

func (a *miteApi) DeleteTimeEntry(id string) error {
return a.delete(fmt.Sprintf("/time_entries/%s.json", id))
}

0 comments on commit 0cf7a8d

Please sign in to comment.