Mercurial > code > home > repos > gcalendarwatch
view calsync/gcalclient/gcalclient.go @ 91:62caecb41dfd default tip
fix tag
author | drewp@bigasterisk.com |
---|---|
date | Fri, 03 Jan 2025 18:06:13 -0800 |
parents | 79320eff10f2 |
children |
line wrap: on
line source
package gcalclient /* Note: this module keeps gcal *paging* private (we fetch all the pages), but *sync* is public. At least, callers may receive a syncToken and have to pass it back in. */ import ( "context" "crypto/md5" "fmt" "net/url" "time" "bigasterisk.com/go/gcalendarwatch/mongoclienttypes" "google.golang.org/api/calendar/v3" ) const calUrlBase = "http://bigasterisk.com/calendar/" const eventUrlBase = "http://bigasterisk.com/calendarEvent/" type GCalClient struct { ctx context.Context srv *calendar.Service } // Same as calendar.Event, but includes our urls type CalendarEvent struct { *calendar.Event CalendarUrl string EventUrl string } func MakeCalUrl(calId string) string { return calUrlBase + url.QueryEscape(calId) } func MakeEventUrl(calUrl string, evId string) string { return eventUrlBase + url.QueryEscape(evId) } func New(ctx context.Context) (*GCalClient, error) { srv, err := newService(ctx) if err != nil { return nil, err } return &GCalClient{ctx, srv}, nil } func (gc *GCalClient) Close() { } func (gc *GCalClient) AllCalendars() ([]*calendar.CalendarListEntry, error) { // todo: pagination list, err := gc.srv.CalendarList.List().MaxResults( /*maxResults*/ 100).Do() if err != nil { return nil, err } return list.Items, nil } func shortDebugHash(pageToken string) string { if pageToken == "" { return "(empty)" } return fmt.Sprintf("%x", md5.Sum([]byte(pageToken))) } func (gc *GCalClient) WatchEvents(cal *mongoclienttypes.MongoCal, watchId string, expire time.Duration) error { _, err := watchEventsCall(gc.srv, cal.GoogleId, expire, watchId).Do() return err }