Skip to content

Commit

Permalink
implment delete file (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
yawlhead91 authored May 14, 2020
1 parent d386b79 commit 74c7e70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,14 @@ func (c *Client) DownloadFile(ctx context.Context, id string) (io.ReadCloser, er
}
return resp.Body, nil
}

// DeleteFile removes an existing file identified by the specified file ID.
// See: https://docs.nylas.com/reference#files-delete
func (c *Client) DeleteFile(ctx context.Context, id string) error {
endpoint := fmt.Sprintf("/files/%s", id)
req, err := c.newUserRequest(ctx, http.MethodDelete, endpoint, nil)
if err != nil {
return err
}
return c.do(req, nil)
}
17 changes: 17 additions & 0 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ func TestDownloadFile(t *testing.T) {
}
}

func TestDeleteFile(t *testing.T) {
accessToken := "accessToken"
id := "br57kcekhf1hsjq04y8aonkit"
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assertBasicAuth(t, r, accessToken, "")
assertMethodPath(t, r, http.MethodDelete, "/files/"+id)

}))
defer ts.Close()

client := NewClient("", "", withTestServer(ts), WithAccessToken(accessToken))
err := client.DeleteFile(context.Background(), id)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

var getFileJSON = []byte(`{
"account_id": "43jf3n4e***",
"content_type": "image/png",
Expand Down

0 comments on commit 74c7e70

Please sign in to comment.