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
- Variables
- func DisableLog()
- func EnableLog()
- type Account
- type Client
- type DetailedReport
- type DetailedTimeEntry
- type Project
- type Session
- func (session *Session) AddRemoveTag(entryID int, tag string, add bool) (TimeEntry, error)
- func (session *Session) ContinueTimeEntry(timer TimeEntry, duronly bool) (TimeEntry, error)
- func (session *Session) CreateClient(name string, wid int) (client Client, err error)
- func (session *Session) CreateProject(name string, wid int) (proj Project, err error)
- func (session *Session) CreateTag(name string, wid int) (proj Tag, err error)
- func (session *Session) DeleteProject(project Project) ([]byte, error)
- func (session *Session) DeleteTag(tag Tag) ([]byte, error)
- func (session *Session) DeleteTimeEntry(timer TimeEntry) ([]byte, error)
- func (session *Session) GetAccount() (Account, error)
- func (session *Session) GetClients() (clients []Client, err error)
- func (session *Session) GetCurrentTimeEntry() (TimeEntry, error)
- func (session *Session) GetDetailedReport(workspace int, since, until string, page int) (DetailedReport, error)
- func (session *Session) GetProject(id int) (project *Project, err error)
- func (session *Session) GetProjects(wid int) (projects []Project, err error)
- func (session *Session) GetSummaryReport(workspace int, since, until string) (SummaryReport, error)
- func (session *Session) GetTimeEntries(startDate, endDate time.Time) ([]TimeEntry, error)
- func (session *Session) StartTimeEntry(description string) (TimeEntry, error)
- func (session *Session) StartTimeEntryForProject(description string, projectID int, billable bool) (TimeEntry, error)
- func (session *Session) StopTimeEntry(timer TimeEntry) (TimeEntry, error)
- func (session *Session) UnstopTimeEntry(timer TimeEntry) (newEntry TimeEntry, err error)
- func (session *Session) UpdateProject(project Project) (Project, error)
- func (session *Session) UpdateTag(tag Tag) (Tag, error)
- func (session *Session) UpdateTimeEntry(timer TimeEntry) (TimeEntry, error)
- type SummaryReport
- type Tag
- type Task
- type TimeEntry
- func (e *TimeEntry) AddTag(tag string)
- func (e *TimeEntry) Copy() TimeEntry
- func (e *TimeEntry) HasTag(tag string) bool
- func (e *TimeEntry) IsRunning() bool
- func (e *TimeEntry) RemoveTag(tag string)
- func (e *TimeEntry) SetDuration(duration int64) error
- func (e *TimeEntry) SetStartTime(start time.Time, updateEnd bool)
- func (e *TimeEntry) SetStopTime(stop time.Time) (err error)
- func (e *TimeEntry) StartTime() time.Time
- func (e *TimeEntry) StopTime() time.Time
- func (e *TimeEntry) UnmarshalJSON(b []byte) error
- type Workspace
Constants ¶
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 ¶
var ( // AppName is the application name used when creating timers. AppName = DefaultAppName )
Functions ¶
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.
type Session ¶
type Session struct { APIToken string // contains filtered or unexported fields }
Session represents an active connection to the Toggl REST API.
func NewSession ¶
NewSession creates a new session by retrieving a user's API token.
func OpenSession ¶
OpenSession opens a session using an existing API token.
func (*Session) AddRemoveTag ¶
AddRemoveTag adds or removes a tag from the time entry corresponding to a given ID.
func (*Session) ContinueTimeEntry ¶
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 ¶
CreateClient adds a new client
func (*Session) CreateProject ¶
CreateProject creates a new project.
func (*Session) DeleteProject ¶
DeleteProject deletes a project.
func (*Session) DeleteTimeEntry ¶
DeleteTimeEntry deletes a time entry.
func (*Session) GetAccount ¶
GetAccount returns a user's account information, including a list of active projects and timers.
func (*Session) GetClients ¶
GetClients returns a list of clients for the current account
func (*Session) GetCurrentTimeEntry ¶
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 ¶
GetProjects allows to query for all projects in a workspace
func (*Session) GetProjects ¶
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 ¶
GetTimeEntries returns a list of time entries
func (*Session) StartTimeEntry ¶
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 ¶
StopTimeEntry stops a running time entry.
func (*Session) UnstopTimeEntry ¶
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 ¶
UpdateProject changes information about an existing project.
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 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 ¶
AddTag adds a tag to a time entry if the entry doesn't already contain the tag.
func (*TimeEntry) SetDuration ¶
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 ¶
SetStartTime sets a time entry's start time. If the time entry is stopped, the stop time will also be updated.
func (*TimeEntry) SetStopTime ¶
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) UnmarshalJSON ¶
UnmarshalJSON unmarshals a TimeEntry from JSON data, converting timestamp fields to Go Time values.