golift.io/starr@v1.0.0/lidarr/downloadclientconfig.go (about) 1 package lidarr 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 } 23 24 // GetDownloadClientConfig returns the download client config. 25 func (l *Lidarr) GetDownloadClientConfig() (*DownloadClientConfig, error) { 26 return l.GetDownloadClientConfigContext(context.Background()) 27 } 28 29 // GetDownloadClientConfig returns the download client config. 30 func (l *Lidarr) GetDownloadClientConfigContext(ctx context.Context) (*DownloadClientConfig, error) { 31 var output DownloadClientConfig 32 33 req := starr.Request{URI: bpDownloadClientConfig} 34 if err := l.GetInto(ctx, req, &output); err != nil { 35 return nil, fmt.Errorf("api.Get(%s): %w", &req, err) 36 } 37 38 return &output, nil 39 } 40 41 // UpdateDownloadClientConfig update the single download client config. 42 func (l *Lidarr) UpdateDownloadClientConfig(downloadClientConfig *DownloadClientConfig) (*DownloadClientConfig, error) { 43 return l.UpdateDownloadClientConfigContext(context.Background(), downloadClientConfig) 44 } 45 46 // UpdateDownloadClientConfig update the single download client config. 47 func (l *Lidarr) UpdateDownloadClientConfigContext(ctx context.Context, 48 config *DownloadClientConfig, 49 ) (*DownloadClientConfig, error) { 50 var output DownloadClientConfig 51 52 var body bytes.Buffer 53 if err := json.NewEncoder(&body).Encode(config); err != nil { 54 return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClientConfig, err) 55 } 56 57 req := starr.Request{URI: path.Join(bpDownloadClientConfig, fmt.Sprint(config.ID)), Body: &body} 58 if err := l.PutInto(ctx, req, &output); err != nil { 59 return nil, fmt.Errorf("api.Put(%s): %w", &req, err) 60 } 61 62 return &output, nil 63 }