From 0cf7a8d829d1af80855d332f1dddd6e480eda2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20Liss=C3=A9?= Date: Wed, 3 Apr 2019 13:34:57 +0200 Subject: [PATCH] Add DeleteTimeEntry() --- mite/api.go | 16 ++++++++++++++++ mite/time_entry.go | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/mite/api.go b/mite/api.go index 7a4b774..2f66b33 100644 --- a/mite/api.go +++ b/mite/api.go @@ -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) } @@ -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 +} diff --git a/mite/time_entry.go b/mite/time_entry.go index 6a205c5..7fe7ee3 100644 --- a/mite/time_entry.go +++ b/mite/time_entry.go @@ -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)) +}