| 249 | } |
| 250 | |
| 251 | func (c *Client) TemplateInsights(ctx context.Context, req TemplateInsightsRequest) (TemplateInsightsResponse, error) { |
| 252 | qp := url.Values{} |
| 253 | qp.Add("start_time", req.StartTime.Format(insightsTimeLayout)) |
| 254 | qp.Add("end_time", req.EndTime.Format(insightsTimeLayout)) |
| 255 | if len(req.TemplateIDs) > 0 { |
| 256 | var templateIDs []string |
| 257 | for _, id := range req.TemplateIDs { |
| 258 | templateIDs = append(templateIDs, id.String()) |
| 259 | } |
| 260 | qp.Add("template_ids", strings.Join(templateIDs, ",")) |
| 261 | } |
| 262 | if req.Interval != "" { |
| 263 | qp.Add("interval", string(req.Interval)) |
| 264 | } |
| 265 | if len(req.Sections) > 0 { |
| 266 | var sections []string |
| 267 | for _, sec := range req.Sections { |
| 268 | sections = append(sections, string(sec)) |
| 269 | } |
| 270 | qp.Add("sections", strings.Join(sections, ",")) |
| 271 | } |
| 272 | |
| 273 | reqURL := fmt.Sprintf("/api/v2/insights/templates?%s", qp.Encode()) |
| 274 | resp, err := c.Request(ctx, http.MethodGet, reqURL, nil) |
| 275 | if err != nil { |
| 276 | return TemplateInsightsResponse{}, xerrors.Errorf("make request: %w", err) |
| 277 | } |
| 278 | defer resp.Body.Close() |
| 279 | |
| 280 | if resp.StatusCode != http.StatusOK { |
| 281 | return TemplateInsightsResponse{}, ReadBodyAsError(resp) |
| 282 | } |
| 283 | var result TemplateInsightsResponse |
| 284 | return result, json.NewDecoder(resp.Body).Decode(&result) |
| 285 | } |
| 286 | |
| 287 | type GetUserStatusCountsResponse struct { |
| 288 | StatusCounts map[UserStatus][]UserStatusChangeCount `json:"status_counts"` |