toggl

package module
v0.0.0-...-9af0e37 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 10 Imported by: 13

README

go-toggl

A Go library for accessing the Toggl API

Installation

Include github.com/jason0x43/go-toggl as a dependency in your code. The library imports as toggl.

Documentation

See the godocs.

History

1.0.0 Update to use go modules 1.1.0 GetTimeEntries

Documentation

Overview

Package toggl provides an API for interacting with the Toggl time tracking service.

See https://github.com/toggl/toggl_api_docs for more information on Toggl's REST API.

Index

Constants

View Source
const (
	TogglAPI       = "https://api.track.toggl.com/api/v8"
	ReportsAPI     = "https://api.track.toggl.com/reports/api/v2"
	DefaultAppName = "go-toggl"
)

Toggl service constants

Variables

View Source
var (

	// AppName is the application name used when creating timers.
	AppName = DefaultAppName
)

Functions

func DisableLog

func DisableLog()

DisableLog disables output to stderr

func EnableLog

func EnableLog()

EnableLog enables output to stderr

Types

type Account

type Account struct {
	Data struct {
		APIToken        string      `json:"api_token"`
		Timezone        string      `json:"timezone"`
		ID              int         `json:"id"`
		Workspaces      []Workspace `json:"workspaces"`
		Clients         []Client    `json:"clients"`
		Projects        []Project   `json:"projects"`
		Tasks           []Task      `json:"tasks"`
		Tags            []Tag       `json:"tags"`
		TimeEntries     []TimeEntry `json:"time_entries"`
		BeginningOfWeek int         `json:"beginning_of_week"`
	} `json:"data"`
	Since int `json:"since"`
}

Account represents a user account.

type Client

type Client struct {
	Wid   int    `json:"wid"`
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Notes string `json:"notes"`
}

Client represents a client.

type DetailedReport

type DetailedReport struct {
	TotalGrand int                 `json:"total_grand"`
	TotalCount int                 `json:"total_count"`
	PerPage    int                 `json:"per_page"`
	Data       []DetailedTimeEntry `json:"data"`
}

DetailedReport represents a summary report generated by Toggl's reporting API.

type DetailedTimeEntry

type DetailedTimeEntry struct {
	ID              int        `json:"id"`
	Pid             int        `json:"pid"`
	Tid             int        `json:"tid"`
	Uid             int        `json:"uid"`
	User            string     `json:"user,omitempty"`
	Description     string     `json:"description"`
	Project         string     `json:"project"`
	ProjectColor    string     `json:"project_color"`
	ProjectHexColor string     `json:"project_hex_color"`
	Client          string     `json:"client"`
	Start           *time.Time `json:"start"`
	End             *time.Time `json:"end"`
	Updated         *time.Time `json:"updated"`
	Duration        int64      `json:"dur"`
	Billable        bool       `json:"billable"`
	Tags            []string   `json:"tags"`
}

type Project

type Project struct {
	Wid             int        `json:"wid"`
	ID              int        `json:"id"`
	Cid             int        `json:"cid"`
	Name            string     `json:"name"`
	Active          bool       `json:"active"`
	Billable        bool       `json:"billable"`
	ServerDeletedAt *time.Time `json:"server_deleted_at,omitempty"`
}

Project represents a project.

func (*Project) IsActive

func (p *Project) IsActive() bool

IsActive indicates whether a project exists and is active

type Session

type Session struct {
	APIToken string
	// contains filtered or unexported fields
}

Session represents an active connection to the Toggl REST API.

func NewSession

func NewSession(username, password string) (session Session, err error)

NewSession creates a new session by retrieving a user's API token.

func OpenSession

func OpenSession(apiToken string) Session

OpenSession opens a session using an existing API token.

func (*Session) AddRemoveTag

func (session *Session) AddRemoveTag(entryID int, tag string, add bool) (TimeEntry, error)

AddRemoveTag adds or removes a tag from the time entry corresponding to a given ID.

func (*Session) ContinueTimeEntry

func (session *Session) ContinueTimeEntry(timer TimeEntry, duronly bool) (TimeEntry, error)

ContinueTimeEntry continues a time entry, either by creating a new entry with the same description or by extending the duration of an existing entry. In both cases the new entry will have the same description and project ID as the existing one.

func (*Session) CreateClient

func (session *Session) CreateClient(name string, wid int) (client Client, err error)

CreateClient adds a new client

func (*Session) CreateProject

func (session *Session) CreateProject(name string, wid int) (proj Project, err error)

CreateProject creates a new project.

func (*Session) CreateTag

func (session *Session) CreateTag(name string, wid int) (proj Tag, err error)

CreateTag creates a new tag.

func (*Session) DeleteProject

func (session *Session) DeleteProject(project Project) ([]byte, error)

DeleteProject deletes a project.

func (*Session) DeleteTag

func (session *Session) DeleteTag(tag Tag) ([]byte, error)

DeleteTag deletes a tag.

func (*Session) DeleteTimeEntry

func (session *Session) DeleteTimeEntry(timer TimeEntry) ([]byte, error)

DeleteTimeEntry deletes a time entry.

func (*Session) GetAccount

func (session *Session) GetAccount() (Account, error)

GetAccount returns a user's account information, including a list of active projects and timers.

func (*Session) GetClients

func (session *Session) GetClients() (clients []Client, err error)

GetClients returns a list of clients for the current account

func (*Session) GetCurrentTimeEntry

func (session *Session) GetCurrentTimeEntry() (TimeEntry, error)

GetCurrentTimeEntry returns the current time entry, that's running

func (*Session) GetDetailedReport

func (session *Session) GetDetailedReport(workspace int, since, until string, page int) (DetailedReport, error)

GetDetailedReport retrieves a detailed report using Toggle's reporting API.

func (*Session) GetProject

func (session *Session) GetProject(id int) (project *Project, err error)

GetProjects allows to query for all projects in a workspace

func (*Session) GetProjects

func (session *Session) GetProjects(wid int) (projects []Project, err error)

GetProjects allows to query for all projects in a workspace

func (*Session) GetSummaryReport

func (session *Session) GetSummaryReport(workspace int, since, until string) (SummaryReport, error)

GetSummaryReport retrieves a summary report using Toggle's reporting API.

func (*Session) GetTimeEntries

func (session *Session) GetTimeEntries(startDate, endDate time.Time) ([]TimeEntry, error)

GetTimeEntries returns a list of time entries

func (*Session) StartTimeEntry

func (session *Session) StartTimeEntry(description string) (TimeEntry, error)

StartTimeEntry creates a new time entry.

func (*Session) StartTimeEntryForProject

func (session *Session) StartTimeEntryForProject(description string, projectID int, billable bool) (TimeEntry, error)

StartTimeEntryForProject creates a new time entry for a specific project. Note that the 'billable' option is only meaningful for Toggl Pro accounts; it will be ignored for free accounts.

func (*Session) StopTimeEntry

func (session *Session) StopTimeEntry(timer TimeEntry) (TimeEntry, error)

StopTimeEntry stops a running time entry.

func (*Session) UnstopTimeEntry

func (session *Session) UnstopTimeEntry(timer TimeEntry) (newEntry TimeEntry, err error)

UnstopTimeEntry starts a new entry that is a copy of the given one, including the given timer's start time. The given time entry is then deleted.

func (*Session) UpdateProject

func (session *Session) UpdateProject(project Project) (Project, error)

UpdateProject changes information about an existing project.

func (*Session) UpdateTag

func (session *Session) UpdateTag(tag Tag) (Tag, error)

UpdateTag changes information about an existing tag.

func (*Session) UpdateTimeEntry

func (session *Session) UpdateTimeEntry(timer TimeEntry) (TimeEntry, error)

UpdateTimeEntry changes information about an existing time entry.

type SummaryReport

type SummaryReport struct {
	TotalGrand int `json:"total_grand"`
	Data       []struct {
		ID    int `json:"id"`
		Time  int `json:"time"`
		Title struct {
			Project  string `json:"project"`
			Client   string `json:"client"`
			Color    string `json:"color"`
			HexColor string `json:"hex_color"`
		} `json:"title"`
		Items []struct {
			Title map[string]string `json:"title"`
			Time  int               `json:"time"`
		} `json:"items"`
	} `json:"data"`
}

SummaryReport represents a summary report generated by Toggl's reporting API.

type Tag

type Tag struct {
	Wid  int    `json:"wid"`
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Tag represents a tag.

type Task

type Task struct {
	Wid  int    `json:"wid"`
	Pid  int    `json:"pid"`
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Task represents a task.

type TimeEntry

type TimeEntry struct {
	Wid         int        `json:"wid,omitempty"`
	ID          int        `json:"id,omitempty"`
	Pid         int        `json:"pid"`
	Tid         int        `json:"tid"`
	Description string     `json:"description,omitempty"`
	Stop        *time.Time `json:"stop,omitempty"`
	Start       *time.Time `json:"start,omitempty"`
	Tags        []string   `json:"tags"`
	Duration    int64      `json:"duration,omitempty"`
	DurOnly     bool       `json:"duronly"`
	Billable    bool       `json:"billable"`
}

TimeEntry represents a single time entry.

func (*TimeEntry) AddTag

func (e *TimeEntry) AddTag(tag string)

AddTag adds a tag to a time entry if the entry doesn't already contain the tag.

func (*TimeEntry) Copy

func (e *TimeEntry) Copy() TimeEntry

Copy returns a copy of a TimeEntry.

func (*TimeEntry) HasTag

func (e *TimeEntry) HasTag(tag string) bool

HasTag returns true if a time entry contains a given tag.

func (*TimeEntry) IsRunning

func (e *TimeEntry) IsRunning() bool

IsRunning returns true if the receiver is currently running.

func (*TimeEntry) RemoveTag

func (e *TimeEntry) RemoveTag(tag string)

RemoveTag removes a tag from a time entry.

func (*TimeEntry) SetDuration

func (e *TimeEntry) SetDuration(duration int64) error

SetDuration sets a time entry's duration. The duration should be a value in seconds. The stop time will also be updated. Note that the time entry must not be running.

func (*TimeEntry) SetStartTime

func (e *TimeEntry) SetStartTime(start time.Time, updateEnd bool)

SetStartTime sets a time entry's start time. If the time entry is stopped, the stop time will also be updated.

func (*TimeEntry) SetStopTime

func (e *TimeEntry) SetStopTime(stop time.Time) (err error)

SetStopTime sets a time entry's stop time. The duration will also be updated. Note that the time entry must not be running.

func (*TimeEntry) StartTime

func (e *TimeEntry) StartTime() time.Time

StartTime returns the start time of a time entry as a time.Time.

func (*TimeEntry) StopTime

func (e *TimeEntry) StopTime() time.Time

StopTime returns the stop time of a time entry as a time.Time.

func (*TimeEntry) UnmarshalJSON

func (e *TimeEntry) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a TimeEntry from JSON data, converting timestamp fields to Go Time values.

type Workspace

type Workspace struct {
	ID              int    `json:"id"`
	RoundingMinutes int    `json:"rounding_minutes"`
	Rounding        int    `json:"rounding"`
	Name            string `json:"name"`
	Premium         bool   `json:"premium"`
}

Workspace represents a user workspace.

Directories

Path Synopsis
The toggl command will display a user's Toggl account information.
The toggl command will display a user's Toggl account information.

Jump to

Keyboard shortcuts

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