libcal

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package libcal reads Leavey Library room availability from USC Libraries' LibCal and books rooms. NewPublic is enough for availability; booking needs a client from Open.

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthenticationRequired = &Error{
	Code: "libcal_authentication_required", Message: "LibCal needs a USC sign-in",
	Cause: &auth.SiteError{Site: site.LibCal, Err: auth.ErrCredentialsRequired},
}

ErrAuthenticationRequired means LibCal's checkout needs a USC sign-in and no complete credentials were available.

View Source
var ErrBookingUnknown = &Error{Code: "libcal_booking_unknown", Message: "LibCal booking outcome is unknown; check the confirmation email, then release the checkout before booking again"}

ErrBookingUnknown means submission may have succeeded. Never retry blindly.

Functions

func CancelCode added in v0.1.1

func CancelCode(link string) (string, error)

CancelCode returns the code in a LibCal cancellation link, such as https://libcal.usc.edu/equipment/cancel?id=ab4448afc8ed from a confirmation email. The code alone is the only key to its bookings.

func ParseDate

func ParseDate(value string) (time.Time, error)

ParseDate reads a day on USC's calendar: "today", "tomorrow", or YYYY-MM-DD.

Types

type Availability added in v0.1.1

type Availability struct {
	Start     time.Time         `json:"start"`
	End       time.Time         `json:"end"`
	Timezone  string            `json:"timezone"`
	Matches   []Space           `json:"matches"`
	WindowEnd map[Category]bool `json:"window_end"`
}

Availability contains spaces whose returned intervals cover the exact requested span. It neither holds a space nor guarantees a later booking will succeed.

type AvailabilityOptions added in v0.1.1

type AvailabilityOptions struct {
	Start       time.Time
	End         time.Time
	Category    Category
	MinCapacity int
	MaxCapacity int
}

type Booking added in v0.1.1

type Booking struct {
	ID         int       `json:"id"`
	Space      string    `json:"space"`
	Category   string    `json:"category"`
	Start      time.Time `json:"start"`
	End        time.Time `json:"end"`
	Cancelable bool      `json:"cancelable"`
}

Booking is one reservation listed under a cancellation link.

type Cancellation added in v0.1.1

type Cancellation struct {
	BookingID     int  `json:"booking_id"`
	Canceled      bool `json:"canceled"`
	MoreRemaining bool `json:"more_remaining"`
}

Cancellation is LibCal's answer to a canceled booking.

type Category

type Category string

Category identifies a Leavey LibCal reservation category.

const (
	CategoryRooms  Category = "rooms"
	CategoryPods   Category = "pods"
	CategoryAll    Category = "all"
	CategoryFirst  Category = "lvl1"
	CategorySecond Category = "lvl2"
	CategoryThird  Category = "lvl3"
)

type CategoryInfo

type CategoryInfo struct {
	ID   int      `json:"id"`
	Name string   `json:"name"`
	Slug Category `json:"slug"`
	Kind string   `json:"kind"`
}

CategoryInfo describes one live Leavey reservation category.

func Categories

func Categories() []CategoryInfo

Categories returns USC's current Leavey LibCal categories in site order.

type CategorySchedule

type CategorySchedule struct {
	Category  CategoryInfo    `json:"category"`
	WindowEnd bool            `json:"window_end"`
	Spaces    []SpaceSchedule `json:"spaces"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client reads and books Leavey Library spaces through LibCal.

func New

func New(httpClient Doer) *Client

New creates a LibCal client using the supplied HTTP client.

func NewPublic

func NewPublic() *Client

NewPublic creates a client for unauthenticated availability and room reads.

func Open

func Open(options auth.Options) (*Client, error)

Open returns a booking client. LibCal only issues its SSO redirect once a booking is staged, so sign-in happens during Book, with the credentials in options. With a SessionFile, checkout recovery state is kept beside it and bookings from other processes using that file are serialized.

func (*Client) Availability added in v0.1.1

func (c *Client) Availability(ctx context.Context, options AvailabilityOptions) (Availability, error)

func (*Client) Book

func (c *Client) Book(ctx context.Context, selection Selection, details ReservationDetails) (reservation Reservation, resultErr error)

Book reserves exactly the selected space, start, and end; it never substitutes another room or time. A failed or interrupted booking releases its temporary hold. ErrBookingUnknown means the outcome must be checked by hand before booking again.

func (*Client) Bookings added in v0.1.1

func (c *Client) Bookings(ctx context.Context, code string) ([]Booking, error)

Bookings lists the reservations a cancellation code covers. Canceled and past bookings stay listed but are not cancelable.

func (*Client) Cancel added in v0.1.1

func (c *Client) Cancel(ctx context.Context, code string, bookingID int) (Cancellation, error)

Cancel cancels one booking listed under the cancellation code.

func (*Client) Release

func (c *Client) Release(ctx context.Context) error

Release ends only an unfinished CLI checkout; it never cancels a confirmed reservation. It also acknowledges a previously unknown submission outcome.

func (*Client) Schedule

func (c *Client) Schedule(ctx context.Context, options ScheduleOptions) (Schedule, error)

Schedule returns the live grid without synthesizing durations or choosing a slot. Callers select a continuous span of up to two hours for Book.

func (*Client) Space

func (c *Client) Space(ctx context.Context, id int) (Space, error)

Space returns one Leavey space by ID.

func (*Client) Spaces

func (c *Client) Spaces(ctx context.Context, selector Category) ([]Space, error)

Spaces lists reservable Leavey spaces. A blank selector or "all" includes group study rooms and pods; "rooms" excludes pods.

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is the HTTP surface the client needs. auth.Session satisfies it.

type Error

type Error struct {
	Code    string
	Message string
	Cause   error
}

Error provides a stable machine-readable code and a safe explanation.

func (*Error) Error

func (e *Error) Error() string

func (*Error) ErrorCode

func (e *Error) ErrorCode() string

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Interval

type Interval struct {
	Start     time.Time `json:"start"`
	End       time.Time `json:"end"`
	Available bool      `json:"available"`
	Status    string    `json:"status"`
	// contains filtered or unexported fields
}

type Reservation

type Reservation struct {
	Space       Space     `json:"space"`
	Start       time.Time `json:"start"`
	End         time.Time `json:"end"`
	State       string    `json:"state"`
	ConfirmedAt time.Time `json:"confirmed_at"`
}

Reservation is the confirmed LibCal booking returned after form submission.

type ReservationDetails

type ReservationDetails struct {
	Fields      map[string]string
	AcceptTerms bool
}

ReservationDetails are the caller's explicit answers to LibCal's checkout form, keyed by field name. Book refuses to submit unless AcceptTerms is set.

type ResponseError

type ResponseError struct {
	Operation string
	Status    int
	BodyBytes int
	Cause     error
}

ResponseError describes a rejected LibCal HTTP request without exposing the response body, which may contain user or session state.

func (*ResponseError) Error

func (e *ResponseError) Error() string

func (*ResponseError) ErrorCode

func (e *ResponseError) ErrorCode() string

func (*ResponseError) Unwrap

func (e *ResponseError) Unwrap() error

type Schedule

type Schedule struct {
	StartDate  string             `json:"start_date"`
	EndDate    string             `json:"end_date"`
	Timezone   string             `json:"timezone"`
	Categories []CategorySchedule `json:"categories"`
}

Schedule contains the server's intervals, including unavailable intervals. Missing intervals are not evidence of availability. WindowEnd is preserved per category. Callers choose continuous intervals of up to two hours.

func (Schedule) Availability added in v0.1.1

func (s Schedule) Availability(start, end time.Time) (Availability, error)

Availability also filters an already-fetched schedule without another request.

type ScheduleOptions

type ScheduleOptions struct {
	Date        time.Time
	EndDate     time.Time
	Category    Category
	MinCapacity int
	MaxCapacity int
}

ScheduleOptions selects a date range and optional inventory filters. EndDate is exclusive and defaults to the day after Date. No duration, ranking, or room-type preference is applied.

type Selection

type Selection struct {
	SpaceID int       `json:"space_id"`
	Start   time.Time `json:"start"`
	End     time.Time `json:"end"`
}

Selection identifies the exact space, start, and end to reserve.

func (Selection) Validate

func (s Selection) Validate() error

Validate rejects invalid inputs and durations over two hours without requests.

type Space

type Space struct {
	ID           int      `json:"id"`
	Name         string   `json:"name"`
	Capacity     int      `json:"capacity"`
	Category     string   `json:"category"`
	CategoryID   int      `json:"category_id"`
	CategorySlug Category `json:"category_slug"`
	Kind         string   `json:"kind"`
	URL          string   `json:"url"`
}

Space is a reservable room or pod in Leavey Library.

type SpaceSchedule

type SpaceSchedule struct {
	Space     Space      `json:"space"`
	Intervals []Interval `json:"intervals"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL