(ctx context.Context, limit int)
| 152 | const maxPerPage = 100 |
| 153 | |
| 154 | func (c *eventClient) ListSubscriptions(ctx context.Context, limit int) ([]Subscription, error) { |
| 155 | if !SupportedHost(c.host) { |
| 156 | return nil, ErrUnsupportedHost |
| 157 | } |
| 158 | |
| 159 | path, err := safeurl.JoinPath("event-subscriptions") |
| 160 | if err != nil { |
| 161 | return nil, err |
| 162 | } |
| 163 | path.SetQuery("per_page", strconv.Itoa(min(limit, maxPerPage))) |
| 164 | |
| 165 | subs := []Subscription{} |
| 166 | for next := path.String(); next != "" && len(subs) < limit; { |
| 167 | var page struct { |
| 168 | Subscriptions []Subscription `json:"subscriptions"` |
| 169 | } |
| 170 | next, err = c.api.RESTWithNext(c.host, http.MethodGet, next, nil, &page) |
| 171 | if err != nil { |
| 172 | if httpErr, ok := errors.AsType[api.HTTPError](err); ok && httpErr.StatusCode == http.StatusForbidden { |
| 173 | return nil, forbiddenError(httpErr, err) |
| 174 | } |
| 175 | return nil, err |
| 176 | } |
| 177 | // Pages past the last one are empty, so stop there even if a link points further. |
| 178 | if len(page.Subscriptions) == 0 { |
| 179 | break |
| 180 | } |
| 181 | subs = append(subs, page.Subscriptions...) |
| 182 | } |
| 183 | return subs[:min(len(subs), limit)], nil |
| 184 | } |
| 185 | |
| 186 | // decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a |
| 187 | // request that failed in transit, so callers can tell it apart from a response of an unexpected shape. |
nothing calls this directly
no test coverage detected