From 8f6192e26b66e06c5eea3a8d17e342ea57c4a86e Mon Sep 17 00:00:00 2001 From: buckket Date: Thu, 16 May 2019 01:59:33 +0200 Subject: [PATCH] Add /api/v1/notifications/dismiss --- README.md | 1 + notification.go | 12 ++++++++++++ notification_test.go | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 9be937f..59c6e5c 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ func main() { * [x] GET /api/v1/mutes * [x] GET /api/v1/notifications * [x] GET /api/v1/notifications/:id +* [x] POST /api/v1/notifications/dismiss * [x] POST /api/v1/notifications/clear * [x] GET /api/v1/reports * [x] POST /api/v1/reports diff --git a/notification.go b/notification.go index 0dfd8f8..c16f3be 100644 --- a/notification.go +++ b/notification.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "net/url" "time" ) @@ -36,6 +37,17 @@ func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, err return ¬ification, nil } +// DismissNotification deletes a single notification. +func (c *Client) DismissNotification(ctx context.Context, id ID) error { + params := url.Values{} + params.Add("id", string(id)) + err := c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/dismiss", params, nil, nil) + if err != nil { + return err + } + return nil +} + // ClearNotifications clear notifications. func (c *Client) ClearNotifications(ctx context.Context) error { return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil) diff --git a/notification_test.go b/notification_test.go index 3329d02..024e1b4 100644 --- a/notification_test.go +++ b/notification_test.go @@ -20,6 +20,9 @@ func TestGetNotifications(t *testing.T) { case "/api/v1/notifications/clear": fmt.Fprintln(w, `{}`) return + case "/api/v1/notifications/dismiss": + fmt.Fprintln(w, `{}`) + return } http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return @@ -56,4 +59,8 @@ func TestGetNotifications(t *testing.T) { if err != nil { t.Fatalf("should not be fail: %v", err) } + err = client.DismissNotification(context.Background(), "123") + if err != nil { + t.Fatalf("should not be fail: %v", err) + } }