tasq

package module
v0.0.0-...-5bcb5b6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2019 License: MIT Imports: 9 Imported by: 0

README

tasQ

Built on top of google.golang.org/api/tasks/v1 adding extra functionality making it easier to get started with the Google Tasks API in Golang.

Getting Started

  1. Enable Google Tasks API from API Console
  2. Create a new OAuth Client ID credential and download it as JSON
  3. Configure your OAuth consent screen
  4. Understand the concepts developers.google.com/tasks/concepts
  5. Get tasq go get -u github.com/jtsalva/tasq
  6. Import tasq import "github.com/jtsalva/tasq"
tasq.Init(&tasq.QConfig{
  // Either QTasksReadWriteScope or QTasksReadOnlyScope
  Scope:       tasq.QTasksReadWriteScope,
  Credentials: "/path/to/credentials.json",
})

// Direct users here to grant access to your
// application from their Google accounts
authURL := tasq.Auth.GetAuthCodeURL()

// Once the user grants access and is
// redirected to your specified URL, grab
// the code from the query string
authCode := "4/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXX"

// The auth code can only be used once
// to generate a token, the token is
// reusable, store it somewhere safe
token, err := tasq.Auth.GetToken(authCode)


// Create new service using token
svc, err := tasq.NewService(token)

// List all Tasklists
tasklists, err := svc.Tasklists.List().Do()

// List Tasks from Tasklist
tasks, err := svc.Tasks.List(tasklistId).Do()

Listing Tasklists

// tasklists is of type QTaskLists
tasklists, err := svc.Tasklists.List().Do()

// tasklists.Items is of type []*QTaskList
for _, tasklist := range tasklists.Items {
  fmt.Println(tasklist.Id, tasklist.Name)
}

Listing Tasks

// tasks is of type QTasks
tasks, err := svc.Tasks.List().Do()

// tasks.Items is of type []*QTask
for _, task := range tasks.Items {
  fmt.Println(task.Id, task.Title, task.Notes)

  // List sub-tasks of task
  // task.Children is of type []*QTask
  for _, child := range task.Children {
    fmt.Println("\t", child.Id, child.Title, child.Notes)
  }
}

Filter and Sort Tasks

Fllter by either

  • QCompletedFilter - show only completed tasks
  • QNeedsActionFilter - show only tasks needing action
  • QOverdueFilter - show only tasks needing action where the datetime now is more than the due datetime
filteredTasks, err := svc.Tasks.List().Filter(tasq.QOverdueFilter).Do()

Additionally, you can sort your items either by

  • QPositionSort - sort in the way the user positioned the tasks
  • QLatestFirstSort - newly updated tasks first
  • QOldestFirstSort - oldest updated tasks first
sortedTasks, err := svc.Tasks.List().Sort(tasq.QPositionSort).Do()

You can combine filter and sort

filterdAndSortedTasks, err := svc.Tasks.List().Filter(filter).Sort(sort).Do()

Interacting with Tasks

You can directly manipulate and perform actions on a QTaskList and QTask.

// tasklist is of type QTaskList
tasklist, err := svc.Tasklists.Get(tasklistid).Do()

// task is of type QTask
task, err := svc.Tasks.Get(tasklistid, taskid).Do()
  1. Deleting
  2. Inserting
  3. Updating
  4. Refreshing
  5. Move to Parent
  6. Move to Previous
  7. Move to Beginning
  8. Get Time of Last Update
Deleting
// Delete a list, including the tasks and subtasks within it
err := tasklist.Delete()

// Delete a single task
err := task.Delete()
Inserting

Insert a task into another list

insertedTask, err := task.Insert(anotherTasklistid)
Updating
tasklist.Title = "change tasklist title"
updatedTasklist, err := tasklist.Update()

task.Title = "change task title"
updatedTask, err := task.Update()
Refreshing

If there have been remote changes, update the data currently stored in memory

err := tasklist.Refresh()
err := task.Refresh()
Move to Parent

Make task a subtask to the given parent task id

movedTask, err := task.MoveToParent(parentTaskid)
Move to Previous

Move task after given previous task id

movedTask, err := task.MoveToPrevious(previousTaskid)
Move to Beginning

Moves task to beginning of list

movedTask, err := task.MoveToBeginning()
Get Time of Last Update

Returns time of last update as type time.Time

tasklistUpdatedTime, err := tasklist.Time()
taskUpdatedTime, err := task.Time()

Documentation

Index

Constants

View Source
const (
	QCompletedFilter   = "filter.completed"
	QNeedsActionFilter = "filter.needs_action"
	QOverdueFilter     = "filter.overdue"

	QPositionSort    = "sort.position"
	QLatestFirstSort = "sort.latest_first"
	QOldestFirstSort = "sort.oldest_first"
)
View Source
const (
	QTasksReadOnlyScope  = tasks.TasksReadonlyScope
	QTasksReadWriteScope = tasks.TasksScope
)

Variables

This section is empty.

Functions

func Init

func Init(cfg *QConfig) error

func Time

func Time(timeString string) (time.Time, error)

Types

type QAuth

type QAuth struct {
	// contains filtered or unexported fields
}
var Auth QAuth

func (*QAuth) GetAuthCodeURL

func (auth *QAuth) GetAuthCodeURL() string

func (*QAuth) GetToken

func (auth *QAuth) GetToken(authCode string) ([]byte, error)

type QConfig

type QConfig struct {
	Credentials string
	Scope       string
}

type QService

type QService struct {
	*tasks.Service

	Tasklists *QTasklistsService
	Tasks     *QTasksService
}

func NewService

func NewService(tokenString []byte) (*QService, error)

type QTask

type QTask struct {
	*tasks.Task

	Children []*QTask
	// contains filtered or unexported fields
}

func (*QTask) Delete

func (task *QTask) Delete() error

func (*QTask) InitNewService

func (task *QTask) InitNewService(tokenString []byte) error

func (*QTask) Insert

func (task *QTask) Insert(tasklistid string) (*QTask, error)

func (*QTask) MoveToBeginning

func (task *QTask) MoveToBeginning() (*QTask, error)

func (*QTask) MoveToParent

func (task *QTask) MoveToParent(parent string) (*QTask, error)

func (*QTask) MoveToPrevious

func (task *QTask) MoveToPrevious(previous string) (*QTask, error)

func (*QTask) Patch

func (task *QTask) Patch() (*QTask, error)

func (*QTask) Refresh

func (task *QTask) Refresh() error

func (*QTask) Time

func (task *QTask) Time() (time.Time, error)

func (*QTask) Update

func (task *QTask) Update() (*QTask, error)

type QTaskCallContext

type QTaskCallContext struct {
	// contains filtered or unexported fields
}

type QTaskList

type QTaskList struct {
	*tasks.TaskList
	// contains filtered or unexported fields
}

func (*QTaskList) Delete

func (taskList *QTaskList) Delete() error

func (*QTaskList) InitNewService

func (taskList *QTaskList) InitNewService(tokenString []byte) error

func (*QTaskList) Patch

func (taskList *QTaskList) Patch() (*QTaskList, error)

func (*QTaskList) Refresh

func (taskList *QTaskList) Refresh() error

func (*QTaskList) Time

func (taskList *QTaskList) Time() (time.Time, error)

func (*QTaskList) Update

func (taskList *QTaskList) Update() (*QTaskList, error)

type QTaskLists

type QTaskLists struct {
	*tasks.TaskLists

	Items []*QTaskList
	// contains filtered or unexported fields
}

func (*QTaskLists) InitNewService

func (taskLists *QTaskLists) InitNewService(tokenString []byte) error

func (*QTaskLists) Refresh

func (taskLists *QTaskLists) Refresh() error

func (*QTaskLists) Time

func (taskLists *QTaskLists) Time() (time.Time, error)

type QTasklistsDeleteCall

type QTasklistsDeleteCall struct {
	*tasks.TasklistsDeleteCall
	// contains filtered or unexported fields
}

func (*QTasklistsDeleteCall) Context

func (*QTasklistsDeleteCall) Do

func (call *QTasklistsDeleteCall) Do(opts ...googleapi.CallOption) error

func (*QTasklistsDeleteCall) Fields

type QTasklistsGetCall

type QTasklistsGetCall struct {
	*tasks.TasklistsGetCall
	// contains filtered or unexported fields
}

func (*QTasklistsGetCall) Context

func (call *QTasklistsGetCall) Context(ctx context.Context) *QTasklistsGetCall

func (*QTasklistsGetCall) Do

func (call *QTasklistsGetCall) Do(opts ...googleapi.CallOption) (*QTaskList, error)

func (*QTasklistsGetCall) Fields

func (call *QTasklistsGetCall) Fields(s ...googleapi.Field) *QTasklistsGetCall

func (*QTasklistsGetCall) IfNoneMatch

func (call *QTasklistsGetCall) IfNoneMatch(entityTag string) *QTasklistsGetCall

type QTasklistsInsertCall

type QTasklistsInsertCall struct {
	*tasks.TasklistsInsertCall
	// contains filtered or unexported fields
}

func (*QTasklistsInsertCall) Context

func (*QTasklistsInsertCall) Do

func (*QTasklistsInsertCall) Fields

type QTasklistsListCall

type QTasklistsListCall struct {
	*tasks.TasklistsListCall
	// contains filtered or unexported fields
}

func (*QTasklistsListCall) Context

func (*QTasklistsListCall) Do

func (call *QTasklistsListCall) Do(opts ...googleapi.CallOption) (*QTaskLists, error)

func (*QTasklistsListCall) Fields

func (*QTasklistsListCall) IfNoneMatch

func (call *QTasklistsListCall) IfNoneMatch(entityTag string) *QTasklistsListCall

func (*QTasklistsListCall) MaxResults

func (call *QTasklistsListCall) MaxResults(maxResults int64) *QTasklistsListCall

func (*QTasklistsListCall) PageToken

func (call *QTasklistsListCall) PageToken(pageToken string) *QTasklistsListCall

type QTasklistsPatchCall

type QTasklistsPatchCall struct {
	*tasks.TasklistsPatchCall
	// contains filtered or unexported fields
}

func (*QTasklistsPatchCall) Context

func (*QTasklistsPatchCall) Do

func (call *QTasklistsPatchCall) Do(opts ...googleapi.CallOption) (*QTaskList, error)

func (*QTasklistsPatchCall) Fields

type QTasklistsService

type QTasklistsService struct{ *tasks.TasklistsService }

func (*QTasklistsService) Delete

func (lists *QTasklistsService) Delete(tasklistid string) *QTasklistsDeleteCall

func (*QTasklistsService) Get

func (lists *QTasklistsService) Get(tasklistid string) *QTasklistsGetCall

func (*QTasklistsService) Insert

func (lists *QTasklistsService) Insert(tasklist *QTaskList) *QTasklistsInsertCall

func (*QTasklistsService) List

func (lists *QTasklistsService) List() *QTasklistsListCall

func (*QTasklistsService) Patch

func (lists *QTasklistsService) Patch(tasklistid string, tasklist *QTaskList) *QTasklistsPatchCall

func (*QTasklistsService) Update

func (lists *QTasklistsService) Update(taskslistid string, tasklist *QTaskList) *QTasklistsUpdateCall

type QTasklistsUpdateCall

type QTasklistsUpdateCall struct {
	*tasks.TasklistsUpdateCall
	// contains filtered or unexported fields
}

func (*QTasklistsUpdateCall) Context

func (*QTasklistsUpdateCall) Do

func (*QTasklistsUpdateCall) Fields

type QTasks

type QTasks struct {
	*tasks.Tasks

	Items []*QTask
	// contains filtered or unexported fields
}

func (*QTasks) InitNewService

func (tasks *QTasks) InitNewService(tokenString []byte) error

func (*QTasks) Refresh

func (tasks *QTasks) Refresh() error

func (*QTasks) Time

func (tasks *QTasks) Time() (time.Time, error)

type QTasksClearCall

type QTasksClearCall struct {
	*tasks.TasksClearCall
	// contains filtered or unexported fields
}

func (*QTasksClearCall) Context

func (call *QTasksClearCall) Context(ctx context.Context) *QTasksClearCall

func (*QTasksClearCall) Do

func (call *QTasksClearCall) Do(opts ...googleapi.CallOption) error

func (*QTasksClearCall) Fields

func (call *QTasksClearCall) Fields(s ...googleapi.Field) *QTasksClearCall

type QTasksDeleteCall

type QTasksDeleteCall struct {
	*tasks.TasksDeleteCall
	// contains filtered or unexported fields
}

func (*QTasksDeleteCall) Context

func (call *QTasksDeleteCall) Context(ctx context.Context) *QTasksDeleteCall

func (*QTasksDeleteCall) Do

func (call *QTasksDeleteCall) Do(opts ...googleapi.CallOption) error

func (*QTasksDeleteCall) Fields

func (call *QTasksDeleteCall) Fields(s ...googleapi.Field) *QTasksDeleteCall

type QTasksGetCall

type QTasksGetCall struct {
	*tasks.TasksGetCall
	// contains filtered or unexported fields
}

func (*QTasksGetCall) Context

func (call *QTasksGetCall) Context(ctx context.Context) *QTasksGetCall

func (*QTasksGetCall) Do

func (call *QTasksGetCall) Do(opts ...googleapi.CallOption) (*QTask, error)

func (*QTasksGetCall) Fields

func (call *QTasksGetCall) Fields(s ...googleapi.Field) *QTasksGetCall

func (*QTasksGetCall) IfNoneMatch

func (call *QTasksGetCall) IfNoneMatch(entityTag string) *QTasksGetCall

type QTasksInsertCall

type QTasksInsertCall struct {
	*tasks.TasksInsertCall
	// contains filtered or unexported fields
}

func (*QTasksInsertCall) Context

func (call *QTasksInsertCall) Context(ctx context.Context) *QTasksInsertCall

func (*QTasksInsertCall) Do

func (call *QTasksInsertCall) Do(opts ...googleapi.CallOption) (*QTask, error)

func (*QTasksInsertCall) Fields

func (call *QTasksInsertCall) Fields(s ...googleapi.Field) *QTasksInsertCall

func (*QTasksInsertCall) Parent

func (call *QTasksInsertCall) Parent(parent string) *QTasksInsertCall

func (*QTasksInsertCall) Previous

func (call *QTasksInsertCall) Previous(previous string) *QTasksInsertCall

type QTasksListCall

type QTasksListCall struct {
	*tasks.TasksListCall
	// contains filtered or unexported fields
}

func (*QTasksListCall) CompletedMax

func (call *QTasksListCall) CompletedMax(completedMax string) *QTasksListCall

func (*QTasksListCall) CompletedMin

func (call *QTasksListCall) CompletedMin(completedMin string) *QTasksListCall

func (*QTasksListCall) Context

func (call *QTasksListCall) Context(ctx context.Context) *QTasksListCall

func (*QTasksListCall) Do

func (call *QTasksListCall) Do(opts ...googleapi.CallOption) (*QTasks, error)

TODO: Filter for deleted tasks

func (*QTasksListCall) DueMax

func (call *QTasksListCall) DueMax(dueMax string) *QTasksListCall

func (*QTasksListCall) DueMin

func (call *QTasksListCall) DueMin(dueMin string) *QTasksListCall

func (*QTasksListCall) Fields

func (call *QTasksListCall) Fields(s ...googleapi.Field) *QTasksListCall

func (*QTasksListCall) Filter

func (call *QTasksListCall) Filter(filter string) *QTasksListCall

func (*QTasksListCall) IfNoneMatch

func (call *QTasksListCall) IfNoneMatch(entityTag string) *QTasksListCall

func (*QTasksListCall) MaxResults

func (call *QTasksListCall) MaxResults(maxResults int64) *QTasksListCall

func (*QTasksListCall) PageToken

func (call *QTasksListCall) PageToken(pageToken string) *QTasksListCall

func (*QTasksListCall) ShowCompleted

func (call *QTasksListCall) ShowCompleted(showCompleted bool) *QTasksListCall

func (*QTasksListCall) ShowDeleted

func (call *QTasksListCall) ShowDeleted(showDeleted bool) *QTasksListCall

func (*QTasksListCall) ShowHidden

func (call *QTasksListCall) ShowHidden(showHidden bool) *QTasksListCall

func (*QTasksListCall) Sort

func (call *QTasksListCall) Sort(sort string) *QTasksListCall

func (*QTasksListCall) UpdateMin

func (call *QTasksListCall) UpdateMin(updatedMin string) *QTasksListCall

type QTasksMoveCall

type QTasksMoveCall struct {
	*tasks.TasksMoveCall
	// contains filtered or unexported fields
}

func (*QTasksMoveCall) Context

func (call *QTasksMoveCall) Context(ctx context.Context) *QTasksMoveCall

func (*QTasksMoveCall) Do

func (call *QTasksMoveCall) Do(opts ...googleapi.CallOption) (*QTask, error)

func (*QTasksMoveCall) Fields

func (call *QTasksMoveCall) Fields(s ...googleapi.Field) *QTasksMoveCall

func (*QTasksMoveCall) Parent

func (call *QTasksMoveCall) Parent(parent string) *QTasksMoveCall

func (*QTasksMoveCall) Previous

func (call *QTasksMoveCall) Previous(previous string) *QTasksMoveCall

type QTasksPatchCall

type QTasksPatchCall struct {
	*tasks.TasksPatchCall
	// contains filtered or unexported fields
}

func (*QTasksPatchCall) Context

func (call *QTasksPatchCall) Context(ctx context.Context) *QTasksPatchCall

func (*QTasksPatchCall) Do

func (call *QTasksPatchCall) Do(opts ...googleapi.CallOption) (*QTask, error)

func (*QTasksPatchCall) Fields

func (call *QTasksPatchCall) Fields(s ...googleapi.Field) *QTasksPatchCall

type QTasksService

type QTasksService struct{ *tasks.TasksService }

func (*QTasksService) Clear

func (tasks *QTasksService) Clear(tasklistid string) *QTasksClearCall

func (*QTasksService) Delete

func (tasks *QTasksService) Delete(tasklistid string, taskid string) *QTasksDeleteCall

func (*QTasksService) Get

func (tasks *QTasksService) Get(tasklistid string, taskid string) *QTasksGetCall

func (*QTasksService) Insert

func (tasks *QTasksService) Insert(tasklistid string, task *QTask) *QTasksInsertCall

func (*QTasksService) List

func (tasks *QTasksService) List(tasklistid string) *QTasksListCall

func (*QTasksService) Move

func (tasks *QTasksService) Move(tasklistid string, taskid string) *QTasksMoveCall

func (*QTasksService) Patch

func (tasks *QTasksService) Patch(tasklistid string, taskid string, task *QTask) *QTasksPatchCall

func (*QTasksService) Update

func (tasks *QTasksService) Update(tasklistid string, taskid string, task *QTask) *QTasksUpdateCall

type QTasksUpdateCall

type QTasksUpdateCall struct {
	*tasks.TasksUpdateCall
	// contains filtered or unexported fields
}

func (*QTasksUpdateCall) Context

func (call *QTasksUpdateCall) Context(ctx context.Context) *QTasksUpdateCall

func (*QTasksUpdateCall) Do

func (call *QTasksUpdateCall) Do(opts ...googleapi.CallOption) (*QTask, error)

func (*QTasksUpdateCall) Fields

func (call *QTasksUpdateCall) Fields(s ...googleapi.Field) *QTasksUpdateCall

Jump to

Keyboard shortcuts

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