Documentation ¶
Overview ¶
Package togglapi provides access to Toggls' time tracking API. The togglapi package provides functions for creating and retrieving workspaces, clients, projects and time entries.
To learn more about the Toggl API visit: https://github.com/toggl/toggl_api_docs
Example ¶
This example shows how you can use the Toggl API to print all your workspaces names, client names, project names and the time entries of the last month.
baseURL := "https://www.toggl.com/api/v8" apiToken := "Toggl-API-Token" api := NewAPI(baseURL, apiToken) // print workspace names fmt.Println("Workspaces:") workspaces, workspacesError := api.GetWorkspaces() if workspacesError != nil { fmt.Fprintf(os.Stderr, "Failed to get workspaces: %s", workspacesError) return } for _, workspace := range workspaces { fmt.Println(workspace.Name) } fmt.Println("") // print client names fmt.Println("Clients:") clients, clientsError := api.GetClients() if clientsError != nil { fmt.Fprintf(os.Stderr, "Failed to get clients: %s", clientsError) return } for _, client := range clients { fmt.Println(client.Name) } fmt.Println("") // print project names fmt.Println("Projects:") for _, workspace := range workspaces { projects, projectsError := api.GetProjects(workspace.ID) if projectsError != nil { fmt.Fprintf(os.Stderr, "Failed to get projects: %s", projectsError) return } for _, project := range projects { fmt.Println(project.Name) } } fmt.Println("") // print time entries fmt.Println("Time Entries:") stop := time.Now() start := stop.AddDate(0, -1, 0) timeEntries, timeEntriesError := api.GetTimeEntries(start, stop) if timeEntriesError != nil { fmt.Fprintf(os.Stderr, "Failed to get timeEntries: %s", timeEntriesError) return } for _, timeEntry := range timeEntries { fmt.Printf("%s - %s: %s\n", timeEntry.Start, timeEntry.Stop, timeEntry.Description) } fmt.Println("")
Output:
Index ¶
- func NewAPI(baseURL, token string) model.TogglAPI
- func NewClientAPI(baseURL, token string) model.ClientAPI
- func NewProjectAPI(baseURL, token string) model.ProjectAPI
- func NewTimeEntryAPI(baseURL, token string) model.TimeEntryAPI
- func NewWorkspaceAPI(baseURL, token string) model.WorkspaceAPI
- type API
- type ClientAPI
- type ProjectAPI
- type RESTRequester
- type TimeEntryAPI
- type WorkspaceAPI
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAPI ¶
NewAPI create a new instance of the Toggl API.
Example ¶
To initialize a new Toggl API instance use the NewAPI function and pass Toggl API URL (e.g. "https://www.toggl.com/api/v8") and your personal API token (e.g. "12jkhjh2j3jkj23").
baseURL := "https://www.toggl.com/api/v8" apiToken := "Your-API-Token" api := NewAPI(baseURL, apiToken) stop := time.Now() start := stop.AddDate(0, -1, 0) timeEntries, timeEntriesError := api.GetTimeEntries(start, stop) if timeEntriesError != nil { fmt.Fprintf(os.Stderr, "Failed to get timeEntries: %s", timeEntriesError) return } for _, timeEntry := range timeEntries { fmt.Printf("%s - %s: %s\n", timeEntry.Start, timeEntry.Stop, timeEntry.Description) }
Output:
func NewClientAPI ¶ added in v0.2.0
NewClientAPI create a new client for the Toggl client API.
func NewProjectAPI ¶ added in v0.2.0
func NewProjectAPI(baseURL, token string) model.ProjectAPI
NewProjectAPI create a new client for the Toggl project API.
Example ¶
If you are only interested in the Project API you can instantiate a ProjectAPI using the NewProjectAPI function.
apiToken := "Your-Toggl-API-Token" baseURL := "https://www.toggl.com/api/v8" workspaceAPI := NewWorkspaceAPI(baseURL, apiToken) workspaces, workspacesError := workspaceAPI.GetWorkspaces() if workspacesError != nil { fmt.Fprintf(os.Stderr, "Failed to get workspaces: %s", workspacesError) return } projectRepository := NewProjectAPI(baseURL, apiToken) for _, workspace := range workspaces { projects, projectsError := projectRepository.GetProjects(workspace.ID) if projectsError != nil { fmt.Fprintf(os.Stderr, "Failed to get projects: %s", projectsError) return } for _, project := range projects { fmt.Println(project.Name) } }
Output:
func NewTimeEntryAPI ¶ added in v0.2.0
func NewTimeEntryAPI(baseURL, token string) model.TimeEntryAPI
NewTimeEntryAPI create a new client for the Toggl time entry API.
Example ¶
If you are only interested in the Time Entry API you can instantiate a TimeEntryAPI using the NewTimeEntryAPI function.
apiToken := "Your-Toggl-API-Token" baseURL := "https://www.toggl.com/api/v8" timeEntryRepository := NewTimeEntryAPI(baseURL, apiToken) stop := time.Now() start := stop.AddDate(0, -1, 0) timeEntries, timeEntriesError := timeEntryRepository.GetTimeEntries(start, stop) if timeEntriesError != nil { fmt.Fprintf(os.Stderr, "Failed to get timeEntries: %s", timeEntriesError) return } for _, timeEntry := range timeEntries { fmt.Printf("%s - %s: %s\n", timeEntry.Start, timeEntry.Stop, timeEntry.Description) }
Output:
func NewWorkspaceAPI ¶ added in v0.2.0
func NewWorkspaceAPI(baseURL, token string) model.WorkspaceAPI
NewWorkspaceAPI create a new client for the Toggl workspace API.
Example ¶
If you are only interested in the Workspace API you can instantiate a WorkspaceAPI using the NewWorkspaceAPI function.
apiToken := "Your-Toggl-API-Token" baseURL := "https://www.toggl.com/api/v8" workspaceRepository := NewWorkspaceAPI(baseURL, apiToken) workspaces, workspacesError := workspaceRepository.GetWorkspaces() if workspacesError != nil { fmt.Fprintf(os.Stderr, "Failed to get workspaces: %s", workspacesError) return } for _, workspace := range workspaces { fmt.Println(workspace.Name) }
Output:
Types ¶
type API ¶
type API struct { model.WorkspaceAPI model.ProjectAPI model.TimeEntryAPI model.ClientAPI }
API provides functions for interacting with the Toggl API.
type ClientAPI ¶ added in v0.2.0
type ClientAPI struct {
// contains filtered or unexported fields
}
ClientAPI provides functions for interacting with Toggls' client API.
func (*ClientAPI) CreateClient ¶ added in v0.2.0
CreateClient creates a new client.
type ProjectAPI ¶ added in v0.2.0
type ProjectAPI struct {
// contains filtered or unexported fields
}
ProjectAPI provides functions for interacting with Toggls' project API.
func (*ProjectAPI) CreateProject ¶ added in v0.2.0
CreateProject creates a new project.
func (*ProjectAPI) GetProjects ¶ added in v0.2.0
func (repository *ProjectAPI) GetProjects(workspaceID int) ([]model.Project, error)
GetProjects returns all projects for the given workspace.
type RESTRequester ¶
type RESTRequester interface { // Request sends an HTTP request with the given parameters (method, route, payload) // to an REST API and returns the APIs' response or an error if the request failed. Request(method, route string, payload io.Reader) ([]byte, error) }
The RESTRequester interface provides a function for sending HTTP requests to REST APIs.
type TimeEntryAPI ¶ added in v0.2.0
type TimeEntryAPI struct {
// contains filtered or unexported fields
}
TimeEntryAPI provides functions for interacting with Toggls' time entry API.
func (*TimeEntryAPI) CreateTimeEntry ¶ added in v0.2.0
CreateTimeEntry creates a new time entry.
func (*TimeEntryAPI) GetTimeEntries ¶ added in v0.2.0
GetTimeEntries returns all time entries created between the given start and end date. Returns nil and an error if the time entries could not be retrieved.
type WorkspaceAPI ¶ added in v0.2.0
type WorkspaceAPI struct {
// contains filtered or unexported fields
}
WorkspaceAPI provides functions for interacting with Toggls' workspace API.
func (*WorkspaceAPI) GetWorkspaces ¶ added in v0.2.0
func (repository *WorkspaceAPI) GetWorkspaces() ([]model.Workspace, error)
GetWorkspaces returns all workspaces for the current user.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package date provides functions for parsing and formatting dates according the requirements of Toggl (ISO 8601).
|
Package date provides functions for parsing and formatting dates according the requirements of Toggl (ISO 8601). |
Package main implements a simple sample implementation of the Toggl API for go (github.com/andreaskoch/togglapi).
|
Package main implements a simple sample implementation of the Toggl API for go (github.com/andreaskoch/togglapi). |
Package model contains the models and interface for the Toggl API
|
Package model contains the models and interface for the Toggl API |