author | Mikael Berthe <mikael@lilotux.net> |
Sat, 15 Apr 2017 10:26:36 +0200 | |
changeset 120 | 579912e9d0ef |
parent 102 | 187aa2a668a5 |
child 130 | c450bb73f59a |
permissions | -rw-r--r-- |
95 | 1 |
package gondole |
2 |
||
3 |
import ( |
|
4 |
"strconv" |
|
5 |
||
6 |
"github.com/sendgrid/rest" |
|
7 |
) |
|
8 |
||
9 |
// GetNotifications returns the list of the user's notifications |
|
10 |
func (g *Client) GetNotifications() ([]Notification, error) { |
|
11 |
var notifications []Notification |
|
120 | 12 |
if err := g.apiCall("notifications", rest.Get, nil, ¬ifications); err != nil { |
13 |
return nil, err |
|
95 | 14 |
} |
15 |
return notifications, nil |
|
16 |
} |
|
17 |
||
18 |
// GetNotification returns a notification |
|
102 | 19 |
// The returned notification can be nil if there is an error or if the |
20 |
// requested notification does not exist. |
|
95 | 21 |
func (g *Client) GetNotification(id int) (*Notification, error) { |
120 | 22 |
if id < 1 { |
23 |
return nil, ErrInvalidID |
|
95 | 24 |
} |
25 |
||
120 | 26 |
var endPoint = "notifications/" + strconv.Itoa(id) |
27 |
var notification Notification |
|
28 |
if err := g.apiCall(endPoint, rest.Get, nil, ¬ification); err != nil { |
|
29 |
return nil, err |
|
95 | 30 |
} |
99
6ec2a44a1bd1
Return error rather than empty entities
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
31 |
if notification.ID == 0 { |
6ec2a44a1bd1
Return error rather than empty entities
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
32 |
return nil, ErrEntityNotFound |
6ec2a44a1bd1
Return error rather than empty entities
Mikael Berthe <mikael@lilotux.net>
parents:
98
diff
changeset
|
33 |
} |
95 | 34 |
return ¬ification, nil |
35 |
} |
|
96 | 36 |
|
37 |
// ClearNotifications deletes all notifications from the Mastodon server for |
|
38 |
// the authenticated user |
|
39 |
func (g *Client) ClearNotifications() error { |
|
120 | 40 |
return g.apiCall("notifications/clear", rest.Post, nil, &Notification{}) |
96 | 41 |
} |