timelines.go
changeset 118 d9c798e09f0a
parent 98 5d803adfc57e
child 120 579912e9d0ef
equal deleted inserted replaced
117:7f8ac782cf5d 118:d9c798e09f0a
     7 
     7 
     8 	"github.com/sendgrid/rest"
     8 	"github.com/sendgrid/rest"
     9 )
     9 )
    10 
    10 
    11 // GetTimelines returns a timeline (a list of statuses
    11 // GetTimelines returns a timeline (a list of statuses
    12 // timeline can be "home", "public", or a hashtag (":hashtag")
    12 // timeline can be "home", "public", or a hashtag (use ":hashtag")
    13 func (g *Client) GetTimelines(timeline string) ([]Status, error) {
    13 // For the public timelines, you can set 'local' to true to get only the
       
    14 // local instance.
       
    15 func (g *Client) GetTimelines(timeline string, local bool) ([]Status, error) {
    14 	var endPoint string
    16 	var endPoint string
    15 	var tl []Status
    17 	var tl []Status
    16 
    18 
    17 	if timeline == "home" || timeline == "public" {
    19 	switch {
       
    20 	case timeline == "home", timeline == "public":
    18 		endPoint = "timelines/" + timeline
    21 		endPoint = "timelines/" + timeline
    19 	} else if strings.HasPrefix(timeline, ":") {
    22 	case strings.HasPrefix(timeline, ":"):
    20 		hashtag := timeline[1:]
    23 		hashtag := timeline[1:]
    21 		if hashtag == "" {
    24 		if hashtag == "" {
    22 			return tl, fmt.Errorf("timelines API: empty hashtag")
    25 			return tl, fmt.Errorf("timelines API: empty hashtag")
    23 		}
    26 		}
    24 		endPoint = "timelines/tag/" + hashtag
    27 		endPoint = "timelines/tag/" + hashtag
    25 	} else {
    28 	default:
    26 		return tl, fmt.Errorf("GetTimelines: bad timelines argument")
    29 		return tl, fmt.Errorf("GetTimelines: bad timelines argument")
    27 	}
    30 	}
    28 
    31 
    29 	req := g.prepareRequest(endPoint)
    32 	req := g.prepareRequest(endPoint)
       
    33 
       
    34 	if timeline == "public" && local {
       
    35 		req.QueryParams["local"] = "true"
       
    36 	}
       
    37 
    30 	r, err := rest.API(req)
    38 	r, err := rest.API(req)
    31 	if err != nil {
    39 	if err != nil {
    32 		return tl, fmt.Errorf("timelines API query: %s", err.Error())
    40 		return tl, fmt.Errorf("timelines API query: %s", err.Error())
    33 	}
    41 	}
    34 
    42