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 CancelCode(link string) (string, error)
- func ParseDate(value string) (time.Time, error)
- type Availability
- type AvailabilityOptions
- type Booking
- type Cancellation
- type Category
- type CategoryInfo
- type CategorySchedule
- type Client
- func (c *Client) Availability(ctx context.Context, options AvailabilityOptions) (Availability, error)
- func (c *Client) Book(ctx context.Context, selection Selection, details ReservationDetails) (reservation Reservation, resultErr error)
- func (c *Client) Bookings(ctx context.Context, code string) ([]Booking, error)
- func (c *Client) Cancel(ctx context.Context, code string, bookingID int) (Cancellation, 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 ¶
func CancelCode ¶ added in v0.1.1
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.
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 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 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) 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
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
Cancel cancels one booking listed under the cancellation code.
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.
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.
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.