togglapi

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2016 License: Apache-2.0 Imports: 11 Imported by: 3

README

Toggl API for go

A go wrapper for the Toggl API

github.com/andreaskoch/togglapi is a simple wrapper for the Toggl API (https://github.com/toggl/toggl_api_docs).

Build Status

Installation

Download github.com/andreaskoch/togglapi:

go get github.com/andreaskoch/togglapi

Supported API methods

github.com/andreaskoch/togglapi currently only supports the following methods of the Toggl API:

  • Clients
    • CreateClient(client Client) (Client, error)
    • GetClients() ([]Client, error)
  • Workspaces
    • GetWorkspaces() ([]Workspace, error)
  • Projects
    • CreateProject(project Project) (Project, error)
    • GetProjects(workspaceID int) ([]Project, error)
  • Time Entries
    • CreateTimeEntry(timeEntry TimeEntry) (TimeEntry, error)
    • GetTimeEntries(start, end time.Time) ([]TimeEntry, error)

I might add the missing methods in the future, but if you need them now please add them and send me a pull-request.

Usage

package main

import (
	"time"

	"github.com/andreaskoch/togglapi"
)

func main() {
	apiToken := "Your-API-Token"
	baseURL := "https://www.toggl.com/api/v8"
	api := togglapi.NewAPI(baseURL, apiToken)

  // workspaces
	workspaces, workspacesError := api.GetWorkspaces()
	...

  // clients
	clients, clientsError := api.GetClients()
  ...

  // projects by workspace
  for _, workspace := range workspaces {
		projects, projectsError := api.GetProjects(workspace.ID)
		...
	}

	// time entries
	stop := time.Now()
	start := stop.AddDate(0, -1, 0)
	timeEntries, timeEntriesError := api.GetTimeEntries(start, stop)
  ...
}

You can also have a look at the example command line utility: example/main.go

cd $GOPATH/src/github.com/andreaskoch/togglapi/example
go run main.go Your-Toggl-API-Token

Development

Run the unit tests:

cd $GOPATH/src/github.com/andreaskoch/togglapi
make test

Create code coverage reports:

cd $GOPATH/src/github.com/andreaskoch/togglapi
make coverage

Licensing

TogglCSV is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Documentation

Overview

Package togglapi provides repsitorties for accessing Toggl objects such as Workspaces, Projects and Time Entries via the Toggl REST API.

Package togglapi provides repsitorties for accessing Toggl objects such as Workspaces, Projects and Time Entries via the Toggl REST API.

Package togglapi provides repsitorties for accessing Toggl objects such as Workspaces, Projects and Time Entries via the Toggl REST API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAPI

func NewAPI(baseURL, token string) model.TogglAPI

NewAPI create a new instance of the Toggl API.

func NewClientRepository

func NewClientRepository(baseURL, token string) model.ClientRepository

NewClientRepository create a new client for the Toggl client API.

func NewProjectRepository

func NewProjectRepository(baseURL, token string) model.ProjectRepository

NewProjectRepository create a new client for the Toggl project API.

func NewTimeEntryRepository

func NewTimeEntryRepository(baseURL, token string) model.TimeEntryRepository

NewTimeEntryRepository create a new client for the Toggl time entry API.

func NewWorkspaceRepository

func NewWorkspaceRepository(baseURL, token string) model.WorkspaceRepository

NewWorkspaceRepository create a new client for the Toggl workspace API.

Types

type API

API provides functions for interacting with the Toggl API.

type RESTClientRepository

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

RESTClientRepository provides functions for interacting with Toggls' client API.

func (*RESTClientRepository) CreateClient

func (repository *RESTClientRepository) CreateClient(client model.Client) (model.Client, error)

CreateClient creates a new client.

func (*RESTClientRepository) GetClients

func (repository *RESTClientRepository) GetClients() ([]model.Client, error)

GetClients returns all clients for the given workspace.

type RESTProjectRepository

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

RESTProjectRepository provides functions for interacting with Toggls' project API.

func (*RESTProjectRepository) CreateProject

func (repository *RESTProjectRepository) CreateProject(project model.Project) (model.Project, error)

CreateProject creates a new project.

func (*RESTProjectRepository) GetProjects

func (repository *RESTProjectRepository) 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 RESTTimeEntryRepository

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

RESTTimeEntryRepository provides functions for interacting with Toggls' time entry API.

func (*RESTTimeEntryRepository) CreateTimeEntry

func (repository *RESTTimeEntryRepository) CreateTimeEntry(timeEntry model.TimeEntry) (model.TimeEntry, error)

CreateTimeEntry creates a new time entry.

func (*RESTTimeEntryRepository) GetTimeEntries

func (repository *RESTTimeEntryRepository) GetTimeEntries(start, end time.Time) ([]model.TimeEntry, error)

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 RESTWorkspaceRepository

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

RESTWorkspaceRepository provides functions for interacting with Toggls' workspace API.

func (*RESTWorkspaceRepository) GetWorkspaces

func (repository *RESTWorkspaceRepository) GetWorkspaces() ([]model.Workspace, error)

GetWorkspaces returns all workspaces for the current user.

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

Jump to

Keyboard shortcuts

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