package main import ( "encoding/json" "fmt" "net/http" ) type RadarrClient struct { *Client } func NewRadarrClient(baseURL, apiKey string) *RadarrClient { return &RadarrClient{ Client: NewClient(baseURL, apiKey), } } func (r *RadarrClient) GetHealth() ([]HealthCheck, error) { // Create the URL for the health endpoint. url := fmt.Sprintf("%s/api/v3/health", r.BaseURL) // Create a new GET request to the health endpoint. req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } // Set the API key and content type headers. req.Header.Set("X-Api-Key", r.APIKey) req.Header.Set("Content-Type", "application/json") // Send the request and get the response. resp, err := r.HTTPClient.Do(req) if err != nil { return nil, fmt.Errorf("failed to send request: %w", err) } defer resp.Body.Close() // Check if the response is successful. if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to get health: %s", resp.Status) } // Decode the response body into a slice of HealthCheck structs. var health []HealthCheck if err := json.NewDecoder(resp.Body).Decode(&health); err != nil { return nil, fmt.Errorf("failed to decode response body: %w", err) } return health, nil } func (r *RadarrClient) GetMovies() ([]Movie, error) { // Create the URL for the movies endpoint. url := fmt.Sprintf("%s/api/v3/movie", r.BaseURL) // Create a new GET request to the movies endpoint. req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } // Set the API key and content type headers. req.Header.Set("X-Api-Key", r.APIKey) req.Header.Set("Content-Type", "application/json") // Send the request and get the response. resp, err := r.HTTPClient.Do(req) if err != nil { return nil, fmt.Errorf("failed to send request: %w", err) } defer resp.Body.Close() // Check if the response is successful. if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to get movies: %s", resp.Status) } // Decode the response body into a slice of Movie structs. var movies []Movie if err := json.NewDecoder(resp.Body).Decode(&movies); err != nil { return nil, fmt.Errorf("failed to decode response body: %w", err) } return movies, nil } // GetMovie retrieves a specific movie by ID. func (r *RadarrClient) GetMovie(id int) (*Movie, error) { // Create the URL for the movie endpoint. url := fmt.Sprintf("%s/api/v3/movie/%d", r.BaseURL, id) // Create a new GET request to the movie endpoint. req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } // Set the API key and content type headers. req.Header.Set("X-Api-Key", r.APIKey) req.Header.Set("Content-Type", "application/json") // Send the request and get the response. resp, err := r.HTTPClient.Do(req) if err != nil { return nil, fmt.Errorf("failed to send request: %w", err) } defer resp.Body.Close() // Check if the response is successful. if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to get movie: %s", resp.Status) } // Decode the response body into a Movie struct. var movie Movie if err := json.NewDecoder(resp.Body).Decode(&movie); err != nil { return nil, fmt.Errorf("failed to decode response body: %w", err) } return &movie, nil }