golift.io/starr@v1.0.0/sonarr/seasonpass.go (about) 1 package sonarr 2 3 import ( 4 "bytes" 5 "context" 6 "encoding/json" 7 "fmt" 8 9 "golift.io/starr" 10 ) 11 12 /* seasonPass only seems to handle POSTs. */ 13 14 const bpSeasonPass = APIver + "/seasonPass" 15 16 // SeasonPass is the input payload for a seasonPass update. 17 type SeasonPass struct { 18 Series []*MonitoredSeries `json:"series"` 19 MonitoringOptions *MonitoringOptions `json:"monitoringOptions"` 20 } 21 22 // MonitoringOptions is part of the SeasonPass payload. 23 type MonitoringOptions struct { 24 // Valid values for Monitor are: all, future, missing, existing, firstSeason, latestSeason, and none. 25 Monitor string `json:"monitor"` 26 } 27 28 // MonitoredSeries is part of the SeasonPass payload. 29 type MonitoredSeries struct { 30 ID int `json:"id"` 31 Monitored bool `json:"monitored"` 32 } 33 34 // UpdateSeasonPass allows monitoring many Series and episodes at once. 35 func (s *Sonarr) UpdateSeasonPass(seasonPass *SeasonPass) error { 36 return s.UpdateSeasonPassContext(context.Background(), seasonPass) 37 } 38 39 // UpdateSeasonPassContext allows monitoring many series and episodes at once. 40 func (s *Sonarr) UpdateSeasonPassContext(ctx context.Context, seasonPass *SeasonPass) error { 41 var body bytes.Buffer 42 if err := json.NewEncoder(&body).Encode(seasonPass); err != nil { 43 return fmt.Errorf("json.Marshal(%s): %w", bpSeasonPass, err) 44 } 45 46 var output interface{} // any ok 47 48 req := starr.Request{URI: bpSeasonPass, Body: &body} 49 if err := s.PostInto(ctx, req, &output); err != nil { 50 return fmt.Errorf("api.Post(%s): %w", &req, err) 51 } 52 53 return nil 54 }