golift.io/starr@v1.0.0/radarr/calendar.go (about)

     1  package radarr
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/url"
     7  	"time"
     8  
     9  	"golift.io/starr"
    10  )
    11  
    12  // Define Base Path for Calendar queries.
    13  const bpCalendar = APIver + "/calendar"
    14  
    15  // Calendar defines the filters for fetching calendar items.
    16  // Start and End are required. Use starr.True() and starr.False() to fill in the booleans.
    17  type Calendar struct {
    18  	Start       time.Time
    19  	End         time.Time
    20  	Unmonitored bool
    21  }
    22  
    23  // GetCalendar returns calendars based on filters.
    24  func (r *Radarr) GetCalendar(filter Calendar) ([]*Movie, error) {
    25  	return r.GetCalendarContext(context.Background(), filter)
    26  }
    27  
    28  // GetCalendarContext returns calendars based on filters.
    29  func (r *Radarr) GetCalendarContext(ctx context.Context, filter Calendar) ([]*Movie, error) {
    30  	var output []*Movie
    31  
    32  	req := starr.Request{URI: bpCalendar, Query: make(url.Values)}
    33  	req.Query.Add("unmonitored", fmt.Sprint(filter.Unmonitored))
    34  
    35  	if !filter.Start.IsZero() {
    36  		req.Query.Add("start", filter.Start.UTC().Format(starr.CalendarTimeFilterFormat))
    37  	}
    38  
    39  	if !filter.End.IsZero() {
    40  		req.Query.Add("end", filter.End.UTC().Format(starr.CalendarTimeFilterFormat))
    41  	}
    42  
    43  	if err := r.GetInto(ctx, req, &output); err != nil {
    44  		return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
    45  	}
    46  
    47  	return output, nil
    48  }
    49  
    50  /*
    51  // I could not get this method to work in Radar..
    52  // https://discord.com/channels/264387956343570434/264387994302021632/1058509574107312168
    53  
    54  // GetCalendarID returns a single calendar by ID.
    55  func (r *Radarr) GetCalendarID(calendarID int64) (*Movie, error) {
    56  	return r.GetCalendarIDContext(context.Background(), calendarID)
    57  }
    58  
    59  // GetCalendarIDContext returns a single calendar by ID.
    60  func (r *Radarr) GetCalendarIDContext(ctx context.Context, calendarID int64) (*Movie, error) {
    61  	var output *Movie
    62  
    63  	req := starr.Request{URI: path.Join(bpCalendar, fmt.Sprint(calendarID))}
    64  	if err := r.GetInto(ctx, req, &output); err != nil {
    65  		return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
    66  	}
    67  
    68  	return output, nil
    69  } /**/