Skip to content

Commit

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

return json.NewDecoder(res.Body).Decode(result)
}

func (a *miteApi) patch(resource string, body interface{}) error {
b, err := json.Marshal(body)
if err != nil {
return err
}

req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/%s", a.url, resource), bytes.NewBuffer(b))
if err != nil {
return err
}
req.Header.Add("X-MiteApiKey", a.key)
req.Header.Add("User-Agent", userAgent)
req.Header.Add("Content-Type", "application/json")

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 @@ -139,3 +139,7 @@ func (a *miteApi) CreateTimeEntry(command *TimeEntryCommand) (*TimeEntry, error)

return ter.ToTimeEntry(), nil
}

func (a *miteApi) EditTimeEntry(id string, command *TimeEntryCommand) error {
return a.patch(fmt.Sprintf("/time_entries/%s.json", id), command.toRequest())
}

0 comments on commit 1a9c797

Please sign in to comment.