golift.io/starr@v1.0.0/readarr/downloadclientconfig.go (about) 1 package readarr 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/v1/config/downloadClientConfig endpoint. 17 type DownloadClientConfig struct { 18 EnableCompletedDownloadHandling bool `json:"enableCompletedDownloadHandling"` 19 AutoRedownloadFailed bool `json:"autoRedownloadFailed"` 20 ID int64 `json:"id"` 21 DownloadClientWorkingFolders string `json:"downloadClientWorkingFolders"` 22 RemoveCompletedDownloads bool `json:"removeCompletedDownloads"` 23 RemoveFailedDownloads bool `json:"removeFailedDownloads"` 24 } 25 26 // GetDownloadClientConfig returns the download client config. 27 func (r *Readarr) GetDownloadClientConfig() (*DownloadClientConfig, error) { 28 return r.GetDownloadClientConfigContext(context.Background()) 29 } 30 31 // GetDownloadClientConfig returns the download client config. 32 func (r *Readarr) GetDownloadClientConfigContext(ctx context.Context) (*DownloadClientConfig, error) { 33 var output DownloadClientConfig 34 35 req := starr.Request{URI: bpDownloadClientConfig} 36 if err := r.GetInto(ctx, req, &output); err != nil { 37 return nil, fmt.Errorf("api.Get(%s): %w", &req, err) 38 } 39 40 return &output, nil 41 } 42 43 // UpdateDownloadClientConfig update the single download client config. 44 func (r *Readarr) UpdateDownloadClientConfig(downloadConfig *DownloadClientConfig) (*DownloadClientConfig, error) { 45 return r.UpdateDownloadClientConfigContext(context.Background(), downloadConfig) 46 } 47 48 // UpdateDownloadClientConfig update the single download client config. 49 func (r *Readarr) UpdateDownloadClientConfigContext(ctx context.Context, 50 config *DownloadClientConfig, 51 ) (*DownloadClientConfig, error) { 52 var output DownloadClientConfig 53 54 var body bytes.Buffer 55 if err := json.NewEncoder(&body).Encode(config); err != nil { 56 return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClientConfig, err) 57 } 58 59 req := starr.Request{URI: path.Join(bpDownloadClientConfig, fmt.Sprint(config.ID)), Body: &body} 60 if err := r.PutInto(ctx, req, &output); err != nil { 61 return nil, fmt.Errorf("api.Put(%s): %w", &req, err) 62 } 63 64 return &output, nil 65 }