notifications.go
changeset 156 70aadba26338
parent 155 0c581e0108da
child 159 408aa794d9bb
equal deleted inserted replaced
155:0c581e0108da 156:70aadba26338
    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 // If lopt.All is true, several requests will be made until the API server
       
    17 // has nothing to return.
       
    18 // If lopt.Limit is set (and not All), several queries can be made until the
       
    19 // limit is reached.
    16 func (mc *Client) GetNotifications(lopt *LimitParams) ([]Notification, error) {
    20 func (mc *Client) GetNotifications(lopt *LimitParams) ([]Notification, error) {
    17 	var notifications []Notification
    21 	var notifications []Notification
    18 	var links apiLinks
    22 	var links apiLinks
    19 	if err := mc.apiCall("notifications", rest.Get, nil, lopt, &links, &notifications); err != nil {
    23 	if err := mc.apiCall("notifications", rest.Get, nil, lopt, &links, &notifications); err != nil {
    20 		return nil, err
    24 		return nil, err
    21 	}
    25 	}
    22 	if lopt != nil { // Fetch more pages to reach our limit
    26 	if lopt != nil { // Fetch more pages to reach our limit
    23 		var notifSlice []Notification
    27 		var notifSlice []Notification
    24 		for lopt.Limit > len(notifications) && links.next != nil {
    28 		for (lopt.All || lopt.Limit > len(notifications)) && links.next != nil {
    25 			newlopt := links.next
    29 			newlopt := links.next
    26 			links = apiLinks{}
    30 			links = apiLinks{}
    27 			if err := mc.apiCall("notifications", rest.Get, nil, newlopt, &links, &notifSlice); err != nil {
    31 			if err := mc.apiCall("notifications", rest.Get, nil, newlopt, &links, &notifSlice); err != nil {
    28 				return nil, err
    32 				return nil, err
    29 			}
    33 			}