Add /api/v1/notifications/dismiss

pull/103/head
buckket 2019-05-16 01:59:33 +02:00 committed by mattn
parent c09198f7c9
commit 8f6192e26b
3 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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 &notification, 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)

View File

@ -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)
}
}