notifications.go
changeset 212 21d7dc38c0e4
parent 207 301d5b94be3f
child 231 741291bb4772
equal deleted inserted replaced
211:12f0761e6442 212:21d7dc38c0e4
     5 */
     5 */
     6 
     6 
     7 package madon
     7 package madon
     8 
     8 
     9 import (
     9 import (
       
    10 	"fmt"
    10 	"strconv"
    11 	"strconv"
    11 
    12 
    12 	"github.com/sendgrid/rest"
    13 	"github.com/sendgrid/rest"
    13 )
    14 )
    14 
    15 
    15 // GetNotifications returns the list of the user's notifications
    16 // GetNotifications returns the list of the user's notifications
       
    17 // excludeTypes is an array of notifications to exclude ("follow", "favourite",
       
    18 // "reblog", "mention").  It can be nil.
    16 // If lopt.All is true, several requests will be made until the API server
    19 // If lopt.All is true, several requests will be made until the API server
    17 // has nothing to return.
    20 // has nothing to return.
    18 // If lopt.Limit is set (and not All), several queries can be made until the
    21 // If lopt.Limit is set (and not All), several queries can be made until the
    19 // limit is reached.
    22 // limit is reached.
    20 func (mc *Client) GetNotifications(lopt *LimitParams) ([]Notification, error) {
    23 func (mc *Client) GetNotifications(excludeTypes []string, lopt *LimitParams) ([]Notification, error) {
    21 	var notifications []Notification
    24 	var notifications []Notification
    22 	var links apiLinks
    25 	var links apiLinks
    23 	if err := mc.apiCall("notifications", rest.Get, nil, lopt, &links, &notifications); err != nil {
    26 	var params apiCallParams
       
    27 
       
    28 	if len(excludeTypes) > 0 {
       
    29 		params = make(apiCallParams)
       
    30 		for i, eType := range excludeTypes {
       
    31 			qID := fmt.Sprintf("exclude_types[%d]", i+1)
       
    32 			params[qID] = eType
       
    33 		}
       
    34 	}
       
    35 
       
    36 	if err := mc.apiCall("notifications", rest.Get, params, lopt, &links, &notifications); err != nil {
    24 		return nil, err
    37 		return nil, err
    25 	}
    38 	}
    26 	if lopt != nil { // Fetch more pages to reach our limit
    39 	if lopt != nil { // Fetch more pages to reach our limit
    27 		var notifSlice []Notification
    40 		var notifSlice []Notification
    28 		for (lopt.All || lopt.Limit > len(notifications)) && links.next != nil {
    41 		for (lopt.All || lopt.Limit > len(notifications)) && links.next != nil {