calsync

package module
v0.0.0-...-e181699 Latest Latest
Warning

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

Go to latest
Published: May 23, 2017 License: MIT Imports: 7 Imported by: 0

README

A Go library To Help Sync events To a Google Calendar

Build Status GoDoc

calsync makes no backwards compatibility promises. If you want to use calsync, vendor it. And next time you update your vendor tree, update to the latest API if things in calsync changed.

Installation

go get -u github.com/ginabythebay/calsync

Documentation

See GoDoc

Documentation

Overview

Package calsync helps sync events into a Google Calendar.

Syncing the same set of events into a google calendar a second time will have no effect if the events have not been modified in google calendar. If the events have been modified in google calendar and then are imported again, they will be overwritten, in general.

After you sync events into a google calendar, if you do another sync with the same scope, and you don't include the same events as you did the first time, the missing events will be removed from the google calendar.

All synced events will start with a delimiter string in the description:

====================

Users of google calendar may put any text they like before the delimiter string and this package will maintain that text of the event during any subsequent imports.

We use google calendar private extended properties to store data that lets us re-sync safely. Each created event will have a private extended property of the form <scope>=True and another one of the form <scope>ID=<srcID>. The first private property allows us to query for all matching events in subsequent syncs. The second private propery lets us match up srcEvents with google calendar events in subsequent syncs so we can properly add/update/delete as appropriate.

Index

Constants

View Source
const (

	// MaxScopeLen is the maximum length we allow for a scope
	MaxScopeLen = maxPropLen - maxAppendLen
)

Scope is the scope we need to read and write calendars.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changes

type Changes struct {
	Deletes, Updates, Adds []*Event
}

Changes represents a set of changes that were made as the result of an Sync call.

func Sync

func Sync(
	ctx context.Context,
	client *http.Client,
	scope string,
	srcEvents []*Event,
	opts ...Opt) (*Changes, error)

Sync synchronizes srcEvents into a google calendar. See the package comments for more details.

client is an http client ready to be passed to calendar.New(). An introduction to getting started is here: https://developers.google.com/google-apps/calendar/quickstart/go

scope is described in the package comments. It should be short and unique.

func (*Changes) String

func (c *Changes) String() string

type Event

type Event struct {
	// Title will be used as the summary in google calendar
	Title       string    `json:"title"`
	Start       time.Time `json:"start"`
	End         time.Time `json:"end"`
	Where       string    `json:"where"`
	Description string    `json:"description"`
	// SrcID will be stored in the google calendar event as a private
	// property and will be used to recognize the same event if you attempt to
	// sync it again later.  It should be unique across all events that you
	// sync into a single calendar.
	SrcID string `json:"src_id"`
	// contains filtered or unexported fields
}

Event represents a single synchronizable event.

func Fetch

func Fetch(ctx context.Context, client *http.Client, scope string, opts ...Opt) (
	[]*Event, error)

Fetch fetches all upcoming events for a given scope

func (*Event) MarshalJSON

func (ev *Event) MarshalJSON() ([]byte, error)

MarshalJSON marshals to json, using RFC 3339 for the start and end fields.

func (*Event) String

func (ev *Event) String() string

func (*Event) UnmarshalJSON

func (ev *Event) UnmarshalJSON(data []byte) error

UnmarshalJSON marshals from json, using RFC 3339 for the start and end fields.

type Opt

type Opt func(c *cal)

Opt is an optional way to configure the Sync command.

func CalendarID

func CalendarID(calID string) Opt

CalendarID will override the default of accessing the users primary calendar, instead accessing the calendar identified by calID.

func Nop

func Nop() Opt

Nop makes the Sync call operate in readonly mode, reporting what it would have done without modifying anything.

Jump to

Keyboard shortcuts

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