From b3882dbe21dbb1d8ac5092f8ead4115fcf9fe31b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sat, 15 Apr 2017 00:16:48 +0900 Subject: [PATCH] add notifications --- notification.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 notification.go diff --git a/notification.go b/notification.go new file mode 100644 index 0000000..6fa2436 --- /dev/null +++ b/notification.go @@ -0,0 +1,41 @@ +package mastodon + +import ( + "fmt" + "net/http" + "time" +) + +// Notification hold information for mastodon notification. +type Notification struct { + ID int64 `json:"id"` + Type string `json:"type"` + CreatedAt time.Time `json:"created_at"` + Account Account `json:"account"` + Status *Status `json:"status"` +} + +// GetNotifications return notifications. +func (c *Client) GetNotifications() ([]*Notification, error) { + var notifications []*Notification + err := c.doAPI(http.MethodGet, "/api/v1/notifications", nil, ¬ifications) + if err != nil { + return nil, err + } + return notifications, nil +} + +// GetNotifications return notifications. +func (c *Client) GetNotification(id int64) (*Notification, error) { + var notification Notification + err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/notifications/%d", id), nil, ¬ification) + if err != nil { + return nil, err + } + return ¬ification, nil +} + +// ClearNotifications clear notifications. +func (c *Client) ClearNotifications() error { + return c.doAPI(http.MethodPost, "/api/v1/notifications/clear", nil, nil) +}