MCPcopy Index your code
hub / github.com/coder/coder / UserActivityInsights

Method UserActivityInsights

codersdk/insights.go:143–167  ·  view source on GitHub ↗
(ctx context.Context, req UserActivityInsightsRequest)

Source from the content-addressed store, hash-verified

141}
142
143func (c *Client) UserActivityInsights(ctx context.Context, req UserActivityInsightsRequest) (UserActivityInsightsResponse, error) {
144 qp := url.Values{}
145 qp.Add("start_time", req.StartTime.Format(insightsTimeLayout))
146 qp.Add("end_time", req.EndTime.Format(insightsTimeLayout))
147 if len(req.TemplateIDs) > 0 {
148 var templateIDs []string
149 for _, id := range req.TemplateIDs {
150 templateIDs = append(templateIDs, id.String())
151 }
152 qp.Add("template_ids", strings.Join(templateIDs, ","))
153 }
154
155 reqURL := fmt.Sprintf("/api/v2/insights/user-activity?%s", qp.Encode())
156 resp, err := c.Request(ctx, http.MethodGet, reqURL, nil)
157 if err != nil {
158 return UserActivityInsightsResponse{}, xerrors.Errorf("make request: %w", err)
159 }
160 defer resp.Body.Close()
161
162 if resp.StatusCode != http.StatusOK {
163 return UserActivityInsightsResponse{}, ReadBodyAsError(resp)
164 }
165 var result UserActivityInsightsResponse
166 return result, json.NewDecoder(resp.Body).Decode(&result)
167}
168
169// TemplateInsightsResponse is the response from the template insights endpoint.
170type TemplateInsightsResponse struct {

Calls 8

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
EncodeMethod · 0.80
AddMethod · 0.65
FormatMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45