googleworkspace

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package googleworkspace contains logic for working with Google Workspace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLinkURLs

func GetLinkURLs(b *docs.Body) []string

GetLinkURLs returns all link URLs in a Google Doc Body.

func GetTables

func GetTables(b *docs.Body) []*docs.Table

GetTables returns all tables in a Google Doc Body.

func VisitAllTableParagraphs

func VisitAllTableParagraphs(t *docs.Table, fn func(p *docs.Paragraph))

VisitAllTableParagraphs visits all paragraphs in a Google Doc table, calling fn for each.

Types

type Config

type Config struct {
	ClientEmail string `hcl:"client_email,optional"`
	PrivateKey  string `hcl:"private_key,optional"`
	Subject     string `hcl:"subject,optional"`
	TokenURL    string `hcl:"token_url,optional"`

	// CreateDocsAsUser creates Google Docs as the logged-in Hermes user, if true.
	CreateDocsAsUser bool `hcl:"create_docs_as_user,optional"`
}

Config is the configuration for interacting with Google Workspace using a service account.

type Service

type Service struct {
	Admin  *admin.Service
	Docs   *docs.Service
	Drive  *drive.Service
	Gmail  *gmail.Service
	OAuth2 *oauth2api.Service
	People *people.PeopleService
}

Service provides access to the Google Workspace API.

func New

func New() *Service

New reads Google API credentials and returns a service with the required access for Hermes.

func NewFromConfig

func NewFromConfig(cfg *Config) *Service

New returns a service with the required Google Workspace access for Hermes.

func (*Service) CopyFile

func (s *Service) CopyFile(
	fileID, name, destFolder string) (*drive.File, error)

CopyFile copies a Google Drive file.

func (*Service) CreateFolder

func (s *Service) CreateFolder(
	folderName, destFolder string) (*drive.File, error)

CreateFolder creates a Google Drive folder.

func (*Service) CreateShortcut

func (s *Service) CreateShortcut(
	targetFileID, destFolder string) (*drive.File, error)

CreateShortcut creates a Google Drive shortcut.

func (*Service) DeleteFile

func (s *Service) DeleteFile(fileID string) error

DeleteFile deletes a Google Drive file

func (*Service) DeletePermission

func (s *Service) DeletePermission(
	fileID, permissionID string) error

DeletePermission deletes a permission for a Google Drive file.

func (*Service) GetDoc

func (s *Service) GetDoc(id string) (*docs.Document, error)

GetDoc gets a Google Doc.

func (*Service) GetDocs

func (s *Service) GetDocs(folderID string) ([]*drive.File, error)

GetDocs returns all docs in a Google Drive folder.

func (*Service) GetFile

func (s *Service) GetFile(fileID string) (*drive.File, error)

GetFile returns a Google Drive file.

func (*Service) GetFiles

func (s *Service) GetFiles(folderID, mimeType string) ([]*drive.File, error)

GetFiles returns all files in a Google Drive folder.

func (*Service) GetFolders

func (s *Service) GetFolders(folderID string) ([]*drive.File, error)

GetDocs returns all folders in a Google Drive folder.

func (*Service) GetFoldersRecursive

func (s *Service) GetFoldersRecursive(folderID string) ([]*drive.File, error)

GetDocs returns all folders and recursively all subfolders in a Google Drive folder.

func (*Service) GetLatestRevision

func (s *Service) GetLatestRevision(fileID string) (*drive.Revision, error)

GetLatestRevision returns the latest revision for a Google Drive file.

func (*Service) GetSubfolder

func (s *Service) GetSubfolder(
	folderID, subfolderName string) (*drive.File, error)

GetSubfolder returns the subfolder file if the specified folder contains a subfolder with the specified name, and nil if not found.

func (*Service) GetUpdatedDocs

func (s *Service) GetUpdatedDocs(
	folderID, timestamp string) ([]*drive.File, error)

GetUpdatedDocs returns all docs in a Google Drive folder that have been modified after a provided timestamp.

func (*Service) GetUpdatedDocsBetween

func (s *Service) GetUpdatedDocsBetween(
	folderID, afterTime, beforeTime string) ([]*drive.File, error)

GetUpdatedDocsBetween returns all docs in a Google Drive folder that have been modified after a provided timestamp string (in RFC 3339 date-time) "afterTime" and before (or equal to) the timestamp string "beforeTime".

func (*Service) GetUpdatedFiles

func (s *Service) GetUpdatedFiles(
	folderID, mimeType, timestamp string) ([]*drive.File, error)

GetUpdatedFiles returns all files in a Google Drive folder that have been modified after a provided timestamp.

func (*Service) GetUser added in v0.1.0

func (s *Service) GetUser(userKey string) (*admin.User, error)

GetUser gets a user.

func (*Service) KeepRevisionForever

func (s *Service) KeepRevisionForever(
	fileID, revisionID string) (*drive.Revision, error)

KeepRevisionForever keeps a Google Drive file revision forever.

func (*Service) ListFiles

func (s *Service) ListFiles(folderID, query string) ([]*drive.File, error)

ListFiles lists files in a Google Drive folder using the provided query.

func (*Service) ListPermissions

func (s *Service) ListPermissions(fileID string) ([]*drive.Permission, error)

ListPermissions lists permissions for a Google Drive file.

func (*Service) ListRevisions

func (s *Service) ListRevisions(fileID string) ([]*drive.Revision, error)

ListRevisions lists revisions for a Google Drive file.

func (*Service) MoveFile

func (s *Service) MoveFile(fileID, destFolder string) (*drive.File, error)

MoveFile moves a Google Drive file to a different folder.

func (*Service) RenameFile

func (s *Service) RenameFile(fileID, newName string) error

RenameFile renames a Google Drive file.

func (*Service) ReplaceText

func (s *Service) ReplaceText(id string, r map[string]string) error

ReplaceText replaces text in a Google Doc. Provide a map of replacement tags (denoted as "{{tag}}" in the doc) to replacement text as the second parameter.

func (*Service) SearchPeople

func (s *Service) SearchPeople(
	query, readMask string) ([]*people.Person, error)

SearchPeople searches the Google People API.

func (*Service) SendEmail

func (s *Service) SendEmail(to []string, from, subject, body string) (*gmail.Message, error)

SendEmail sends an email.

func (*Service) ShareFile

func (s *Service) ShareFile(
	fileID, email, role string) error

ShareFile shares a Google Drive file with a user.

func (*Service) ShareFileWithDomain added in v0.3.0

func (s *Service) ShareFileWithDomain(
	fileID, domain, role string) error

ShareFileWithDomain shares a Google Drive file with a domain.

func (*Service) UpdateKeepRevisionForever added in v0.4.0

func (s *Service) UpdateKeepRevisionForever(
	fileID, revisionID string, keepForever bool) error

KeepRevisionForever keeps a Google Drive file revision forever.

func (*Service) ValidateAccessToken

func (s *Service) ValidateAccessToken(
	accessToken string) (*oauth2.Tokeninfo, error)

ValidateAccessToken validates a Google access token and returns the token info.

Jump to

Keyboard shortcuts

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