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 ¶
- Variables
- func ParseDate(value string) (time.Time, error)
- type Category
- type CategoryInfo
- type CategorySchedule
- type Client
- func (c *Client) Book(ctx context.Context, selection Selection, details ReservationDetails) (reservation Reservation, resultErr error)
- func (c *Client) Release(ctx context.Context) error
- func (c *Client) Schedule(ctx context.Context, options ScheduleOptions) (Schedule, error)
- func (c *Client) Space(ctx context.Context, id int) (Space, error)
- func (c *Client) Spaces(ctx context.Context, selector Category) ([]Space, error)
- type Doer
- type Error
- type Interval
- type Reservation
- type ReservationDetails
- type ResponseError
- type Schedule
- type ScheduleOptions
- type Selection
- type Space
- type SpaceSchedule
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
Types ¶
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 NewPublic ¶
func NewPublic() *Client
NewPublic creates a client for unauthenticated availability and room reads.
func Open ¶
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) 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) Release ¶
Release ends only an unfinished CLI checkout; it never cancels a confirmed reservation. It also acknowledges a previously unknown submission outcome.
func (*Client) Schedule ¶
Schedule returns the live grid without synthesizing durations or choosing a slot. Callers select a continuous span of up to two hours for Book.
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 ¶
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 ¶
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.
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.
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.