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