From 7c56bd30340590e5c8bd1e34a82369f3e2712860 Mon Sep 17 00:00:00 2001 From: blfletcher Date: Thu, 5 Aug 2021 01:59:34 -0600 Subject: [PATCH] Added delete endpoint (#8) * Added a files endpoint, corrected a documents bug in answers requests, added error messages to API error handling * Added file upload endpoint * Added DeleteFile endpoint Co-authored-by: eyelevelai <33876565+eyelevelai@users.noreply.github.com> --- api.go | 6 ++++-- files.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index 9023a3e..9f7e445 100644 --- a/api.go +++ b/api.go @@ -74,8 +74,10 @@ func (c *Client) sendRequest(req *http.Request, v interface{}) error { return fmt.Errorf("error, status code: %d, message: %s", res.StatusCode, errRes.Error.Message) } - if err = json.NewDecoder(res.Body).Decode(&v); err != nil { - return err + if v != nil { + if err = json.NewDecoder(res.Body).Decode(&v); err != nil { + return err + } } return nil diff --git a/files.go b/files.go index 69763bd..7d56a90 100644 --- a/files.go +++ b/files.go @@ -116,6 +116,18 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File return } +// DeleteFile deletes an existing file +func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error) { + req, err := http.NewRequest("DELETE", c.fullURL("/files/"+fileID), nil) + if err != nil { + return + } + + req = req.WithContext(ctx) + err = c.sendRequest(req, nil) + return +} + // ListFiles Lists the currently available files, // and provides basic information about each file such as the file name and purpose. func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) {