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