add GetNotificationsExclude
parent
ad3aa348dd
commit
fe547bf14f
|
@ -37,8 +37,19 @@ type PushAlerts struct {
|
||||||
|
|
||||||
// GetNotifications returns notifications.
|
// GetNotifications returns notifications.
|
||||||
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
|
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
|
||||||
|
return c.GetNotificationsExclude(ctx, nil, pg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNotificationsExclude returns notifications with excluded notifications
|
||||||
|
func (c *Client) GetNotificationsExclude(ctx context.Context, exclude *[]string, pg *Pagination) ([]*Notification, error) {
|
||||||
var notifications []*Notification
|
var notifications []*Notification
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, ¬ifications, pg)
|
params := url.Values{}
|
||||||
|
if exclude != nil {
|
||||||
|
for _, ex := range *exclude {
|
||||||
|
params.Add("exclude_types[]", ex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", params, ¬ifications, pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,11 @@ func TestGetNotifications(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/api/v1/notifications":
|
case "/api/v1/notifications":
|
||||||
fmt.Fprintln(w, `[{"id": 122, "action_taken": false}, {"id": 123, "action_taken": true}]`)
|
if r.URL.Query().Get("exclude_types[]") == "follow" {
|
||||||
|
fmt.Fprintln(w, `[{"id": 321, "action_taken": true}]`)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(w, `[{"id": 122, "action_taken": false}, {"id": 123, "action_taken": true}]`)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
case "/api/v1/notifications/123":
|
case "/api/v1/notifications/123":
|
||||||
fmt.Fprintln(w, `{"id": 123, "action_taken": true}`)
|
fmt.Fprintln(w, `{"id": 123, "action_taken": true}`)
|
||||||
|
@ -50,6 +54,16 @@ func TestGetNotifications(t *testing.T) {
|
||||||
if ns[1].ID != "123" {
|
if ns[1].ID != "123" {
|
||||||
t.Fatalf("want %v but %v", "123", ns[1].ID)
|
t.Fatalf("want %v but %v", "123", ns[1].ID)
|
||||||
}
|
}
|
||||||
|
nse, err := client.GetNotificationsExclude(context.Background(), &[]string{"follow"}, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(nse) != 1 {
|
||||||
|
t.Fatalf("result should be one: %d", len(nse))
|
||||||
|
}
|
||||||
|
if nse[0].ID != "321" {
|
||||||
|
t.Fatalf("want %v but %v", "321", nse[0].ID)
|
||||||
|
}
|
||||||
n, err := client.GetNotification(context.Background(), "123")
|
n, err := client.GetNotification(context.Background(), "123")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue