golift.io/starr@v1.0.0/lidarr/indexerconfig.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 const bpIndexerConfig = APIver + "/config/indexer" 14 15 // IndexerConfig represents the /config/indexer endpoint. 16 type IndexerConfig struct { 17 ID int64 `json:"id"` 18 MaximumSize int64 `json:"maximumSize"` 19 MinimumAge int64 `json:"minimumAge"` 20 Retention int64 `json:"retention"` 21 RssSyncInterval int64 `json:"rssSyncInterval"` 22 } 23 24 // GetIndexerConfig returns an Indexer Config. 25 func (l *Lidarr) GetIndexerConfig() (*IndexerConfig, error) { 26 return l.GetIndexerConfigContext(context.Background()) 27 } 28 29 // GetIndexerConfigContext returns the indexer Config. 30 func (l *Lidarr) GetIndexerConfigContext(ctx context.Context) (*IndexerConfig, error) { 31 var output IndexerConfig 32 33 req := starr.Request{URI: bpIndexerConfig} 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 // UpdateIndexerConfig update the single indexerConfig. 42 func (l *Lidarr) UpdateIndexerConfig(indexerConfig *IndexerConfig) (*IndexerConfig, error) { 43 return l.UpdateIndexerConfigContext(context.Background(), indexerConfig) 44 } 45 46 // UpdateIndexerConfigContext update the single indexerConfig. 47 func (l *Lidarr) UpdateIndexerConfigContext(ctx context.Context, indexerConfig *IndexerConfig) (*IndexerConfig, error) { 48 var body bytes.Buffer 49 if err := json.NewEncoder(&body).Encode(indexerConfig); err != nil { 50 return nil, fmt.Errorf("json.Marshal(%s): %w", bpIndexerConfig, err) 51 } 52 53 var output IndexerConfig 54 55 req := starr.Request{URI: path.Join(bpIndexerConfig, fmt.Sprint(indexerConfig.ID)), Body: &body} 56 if err := l.PutInto(ctx, req, &output); err != nil { 57 return nil, fmt.Errorf("api.Put(%s): %w", &req, err) 58 } 59 60 return &output, nil 61 }