notifications.go
changeset 149 5f922977d7c7
parent 148 ae2cbcf18b55
child 155 0c581e0108da
equal deleted inserted replaced
148:ae2cbcf18b55 149:5f922977d7c7
    11 
    11 
    12 	"github.com/sendgrid/rest"
    12 	"github.com/sendgrid/rest"
    13 )
    13 )
    14 
    14 
    15 // GetNotifications returns the list of the user's notifications
    15 // GetNotifications returns the list of the user's notifications
    16 func (mc *Client) GetNotifications() ([]Notification, error) {
    16 func (mc *Client) GetNotifications(lopt *LimitParams) ([]Notification, error) {
    17 	var notifications []Notification
    17 	var notifications []Notification
    18 	if err := mc.apiCall("notifications", rest.Get, nil, &notifications); err != nil {
    18 	if err := mc.apiCall("notifications", rest.Get, nil, lopt, &notifications); err != nil {
    19 		return nil, err
    19 		return nil, err
    20 	}
    20 	}
    21 	return notifications, nil
    21 	return notifications, nil
    22 }
    22 }
    23 
    23 
    29 		return nil, ErrInvalidID
    29 		return nil, ErrInvalidID
    30 	}
    30 	}
    31 
    31 
    32 	var endPoint = "notifications/" + strconv.Itoa(notificationID)
    32 	var endPoint = "notifications/" + strconv.Itoa(notificationID)
    33 	var notification Notification
    33 	var notification Notification
    34 	if err := mc.apiCall(endPoint, rest.Get, nil, &notification); err != nil {
    34 	if err := mc.apiCall(endPoint, rest.Get, nil, nil, &notification); err != nil {
    35 		return nil, err
    35 		return nil, err
    36 	}
    36 	}
    37 	if notification.ID == 0 {
    37 	if notification.ID == 0 {
    38 		return nil, ErrEntityNotFound
    38 		return nil, ErrEntityNotFound
    39 	}
    39 	}
    46 		return ErrInvalidID
    46 		return ErrInvalidID
    47 	}
    47 	}
    48 
    48 
    49 	endPoint := "notifications/dismiss"
    49 	endPoint := "notifications/dismiss"
    50 	params := apiCallParams{"id": strconv.Itoa(notificationID)}
    50 	params := apiCallParams{"id": strconv.Itoa(notificationID)}
    51 	return mc.apiCall(endPoint, rest.Post, params, &Notification{})
    51 	return mc.apiCall(endPoint, rest.Post, params, nil, &Notification{})
    52 }
    52 }
    53 
    53 
    54 // ClearNotifications deletes all notifications from the Mastodon server for
    54 // ClearNotifications deletes all notifications from the Mastodon server for
    55 // the authenticated user
    55 // the authenticated user
    56 func (mc *Client) ClearNotifications() error {
    56 func (mc *Client) ClearNotifications() error {
    57 	return mc.apiCall("notifications/clear", rest.Post, nil, &Notification{})
    57 	return mc.apiCall("notifications/clear", rest.Post, nil, nil, &Notification{})
    58 }
    58 }