golift.io/starr@v1.0.0/radarr/downloadclientconfig.go (about)

     1  package radarr
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"encoding/json"
     7  	"fmt"
     8  	"path"
     9  
    10  	"golift.io/starr"
    11  )
    12  
    13  // Define Base Path for download client config calls.
    14  const bpDownloadClientConfig = APIver + "/config/downloadClient"
    15  
    16  // DownloadClientConfig is the /api/v3/config/downloadClientConfig endpoint.
    17  type DownloadClientConfig struct {
    18  	EnableCompletedDownloadHandling  bool   `json:"enableCompletedDownloadHandling"`
    19  	AutoRedownloadFailed             bool   `json:"autoRedownloadFailed"`
    20  	CheckForFinishedDownloadInterval int64  `json:"checkForFinishedDownloadInterval"`
    21  	ID                               int64  `json:"id"`
    22  	DownloadClientWorkingFolders     string `json:"downloadClientWorkingFolders"`
    23  }
    24  
    25  // GetDownloadClientConfig returns the download client config.
    26  func (r *Radarr) GetDownloadClientConfig() (*DownloadClientConfig, error) {
    27  	return r.GetDownloadClientConfigContext(context.Background())
    28  }
    29  
    30  // GetDownloadClientConfig returns the download client config.
    31  func (r *Radarr) GetDownloadClientConfigContext(ctx context.Context) (*DownloadClientConfig, error) {
    32  	var output DownloadClientConfig
    33  
    34  	req := starr.Request{URI: bpDownloadClientConfig}
    35  	if err := r.GetInto(ctx, req, &output); err != nil {
    36  		return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
    37  	}
    38  
    39  	return &output, nil
    40  }
    41  
    42  // UpdateDownloadClientConfig update the single download client config.
    43  func (r *Radarr) UpdateDownloadClientConfig(downloadClientConfig *DownloadClientConfig) (*DownloadClientConfig, error) {
    44  	return r.UpdateDownloadClientConfigContext(context.Background(), downloadClientConfig)
    45  }
    46  
    47  // UpdateDownloadClientConfig update the single download client config.
    48  func (r *Radarr) UpdateDownloadClientConfigContext(ctx context.Context,
    49  	config *DownloadClientConfig,
    50  ) (*DownloadClientConfig, error) {
    51  	var output DownloadClientConfig
    52  
    53  	var body bytes.Buffer
    54  	if err := json.NewEncoder(&body).Encode(config); err != nil {
    55  		return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClientConfig, err)
    56  	}
    57  
    58  	req := starr.Request{URI: path.Join(bpDownloadClientConfig, fmt.Sprint(config.ID)), Body: &body}
    59  	if err := r.PutInto(ctx, req, &output); err != nil {
    60  		return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
    61  	}
    62  
    63  	return &output, nil
    64  }