GetIndexers retrieves all configured indexers from the Prowlarr instance.
(ctx context.Context)
| 191 | |
| 192 | // GetIndexers retrieves all configured indexers from the Prowlarr instance. |
| 193 | func (c *Client) GetIndexers(ctx context.Context) ([]Indexer, error) { |
| 194 | if c.httpClient == nil { |
| 195 | return nil, fmt.Errorf("prowlarr HTTP client is not configured") |
| 196 | } |
| 197 | if ctx == nil { |
| 198 | ctx = context.Background() |
| 199 | } |
| 200 | |
| 201 | endpoint, err := url.JoinPath(c.host, "api", "v1", "indexer") |
| 202 | if err != nil { |
| 203 | return nil, fmt.Errorf("failed to build prowlarr endpoint: %w", err) |
| 204 | } |
| 205 | |
| 206 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil) |
| 207 | if err != nil { |
| 208 | return nil, fmt.Errorf("failed to build prowlarr request: %w", err) |
| 209 | } |
| 210 | if c.apiKey != "" { |
| 211 | req.Header.Set("X-Api-Key", c.apiKey) |
| 212 | } |
| 213 | if c.basicUser != "" { |
| 214 | req.SetBasicAuth(c.basicUser, c.basicPass) |
| 215 | } |
| 216 | req.Header.Set("User-Agent", c.userAgent) |
| 217 | |
| 218 | resp, err := c.httpClient.Do(req) |
| 219 | if err != nil { |
| 220 | return nil, fmt.Errorf("failed to query prowlarr: %w", err) |
| 221 | } |
| 222 | defer resp.Body.Close() |
| 223 | |
| 224 | switch resp.StatusCode { |
| 225 | case http.StatusOK: |
| 226 | // continue |
| 227 | case http.StatusNotFound: |
| 228 | return nil, fmt.Errorf("prowlarr endpoint not found (404)") |
| 229 | case http.StatusUnauthorized, http.StatusForbidden: |
| 230 | return nil, fmt.Errorf("prowlarr returned %d (unauthorized)", resp.StatusCode) |
| 231 | default: |
| 232 | return nil, fmt.Errorf("prowlarr unexpected status %d", resp.StatusCode) |
| 233 | } |
| 234 | |
| 235 | var payload []Indexer |
| 236 | if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil { |
| 237 | return nil, fmt.Errorf("failed to decode prowlarr response: %w", err) |
| 238 | } |
| 239 | |
| 240 | return payload, nil |
| 241 | } |
| 242 | |
| 243 | // GetIndexer retrieves detailed information about a specific indexer from Prowlarr |
| 244 | func (c *Client) GetIndexer(ctx context.Context, indexerID int) (*IndexerDetail, error) { |
no test coverage detected