(ctx context.Context, limit int)
| 141 | const maxPerPage = 100 |
| 142 | |
| 143 | func (c *eventClient) ListSubscriptions(ctx context.Context, limit int) ([]Subscription, error) { |
| 144 | if !SupportedHost(c.host) { |
| 145 | return nil, ErrUnsupportedHost |
| 146 | } |
| 147 | |
| 148 | path, err := safeurl.JoinPath("event-subscriptions") |
| 149 | if err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | path.SetQuery("per_page", strconv.Itoa(min(limit, maxPerPage))) |
| 153 | |
| 154 | subs := []Subscription{} |
| 155 | for next := path.String(); next != "" && len(subs) < limit; { |
| 156 | var page struct { |
| 157 | Subscriptions []Subscription `json:"subscriptions"` |
| 158 | } |
| 159 | next, err = c.api.RESTWithNext(c.host, http.MethodGet, next, nil, &page) |
| 160 | if err != nil { |
| 161 | if httpErr, ok := errors.AsType[api.HTTPError](err); ok && httpErr.StatusCode == http.StatusForbidden { |
| 162 | return nil, forbiddenError(httpErr, err) |
| 163 | } |
| 164 | return nil, err |
| 165 | } |
| 166 | // Pages past the last one are empty, so stop there even if a link points further. |
| 167 | if len(page.Subscriptions) == 0 { |
| 168 | break |
| 169 | } |
| 170 | subs = append(subs, page.Subscriptions...) |
| 171 | } |
| 172 | return subs[:min(len(subs), limit)], nil |
| 173 | } |
| 174 | |
| 175 | // decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a |
| 176 | // 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