go-toggl: github.com/jason0x43/go-toggl Index | Files | Directories

package toggl

import "github.com/jason0x43/go-toggl"

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.


Package Files



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

Toggl service constants


var (

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

func DisableLog Uses

func DisableLog()

DisableLog disables output to stderr

func EnableLog Uses

func EnableLog()

EnableLog enables output to stderr

type Account Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (p *Project) IsActive() bool

IsActive indicates whether a project exists and is active

type Session Uses

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

Session represents an active connection to the Toggl REST API.

func NewSession Uses

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

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

func OpenSession Uses

func OpenSession(apiToken string) Session

OpenSession opens a session using an existing API token.

func (*Session) AddRemoveTag Uses

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 Uses

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 Uses

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

CreateClient adds a new client

func (*Session) CreateProject Uses

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

CreateProject creates a new project.

func (*Session) CreateTag Uses

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

CreateTag creates a new tag.

func (*Session) DeleteProject Uses

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

DeleteProject deletes a project.

func (*Session) DeleteTag Uses

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

DeleteTag deletes a tag.

func (*Session) DeleteTimeEntry Uses

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

DeleteTimeEntry deletes a time entry.

func (*Session) GetAccount Uses

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

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

func (*Session) GetClients Uses

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

GetClients returns a list of clients for the current account

func (*Session) GetCurrentTimeEntry Uses

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

GetCurrentTimeEntry returns the current time entry, that's running

func (*Session) GetDetailedReport Uses

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) GetSummaryReport Uses

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

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

func (*Session) StartTimeEntry Uses

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

StartTimeEntry creates a new time entry.

func (*Session) StartTimeEntryForProject Uses

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 Uses

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

StopTimeEntry stops a running time entry.

func (*Session) UnstopTimeEntry Uses

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 Uses

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

UpdateProject changes information about an existing project.

func (*Session) UpdateTag Uses

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

UpdateTag changes information about an existing tag.

func (*Session) UpdateTimeEntry Uses

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

UpdateTimeEntry changes information about an existing time entry.

type SummaryReport Uses

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 Uses

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

Tag represents a tag.

type Task Uses

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 Uses

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 Uses

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 Uses

func (e *TimeEntry) Copy() TimeEntry

Copy returns a copy of a TimeEntry.

func (*TimeEntry) HasTag Uses

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

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

func (*TimeEntry) IsRunning Uses

func (e *TimeEntry) IsRunning() bool

IsRunning returns true if the receiver is currently running.

func (*TimeEntry) RemoveTag Uses

func (e *TimeEntry) RemoveTag(tag string)

RemoveTag removes a tag from a time entry.

func (*TimeEntry) SetDuration Uses

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 Uses

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 Uses

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 Uses

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

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

func (*TimeEntry) StopTime Uses

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

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

func (*TimeEntry) UnmarshalJSON Uses

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

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

type Workspace Uses

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.


togglThe toggl command will display a user's Toggl account information.

Package toggl imports 10 packages (graph) and is imported by 6 packages. Updated 2019-09-13. Refresh now. Tools for package owners.