toggl

package
v0.0.0-...-7f9a728 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2013 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LibraryVersion represents this library version
	LibraryVersion = "0.1"

	// BaseURL represents Toggl API base URL
	BaseURL = "https://toggl.com/api/v8/"

	// UserAgent represents this client User-Agent
	UserAgent = "go-toggl/" + LibraryVersion
)

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for error, and returns the error if present. A response is considered an error if it has a status code outside the 200 range.

Types

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// UserAgent agent used when communicating with Toggl API.
	UserAgent string

	// Services used for talking to differents parts of the API.
	Clients        *ClientsService
	Projects       *ProjectsService
	ProjectUsers   *ProjectUsersService
	Tags           *TagsService
	Tasks          *TasksService
	TimeEntries    *TimeEntriesService
	Users          *UsersService
	Workspaces     *WorkspacesService
	WorkspaceUsers *WorkspaceUsersService
	// contains filtered or unexported fields
}

Client manages communication with the Toggl API.

func NewClient

func NewClient(apiToken string) *Client

NewClient returns a new Toggl API client. Expects user's api token to be provided. Api token can be found in https://www.toggl.com/user/edit

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is decoded and stored in the value pointed by v, or returned as an error if and API error has occurred.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type ClientsService

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

ClientsService handles communication with the client related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md

func (*ClientsService) Create

Create a new client in specified workspace.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md#create-a-client

func (*ClientsService) Delete

func (s *ClientsService) Delete(id int) error

Delete a client.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md#delete-a-client

func (*ClientsService) Get

func (s *ClientsService) Get(id int) (*WorkspaceClient, error)

Get client details by client_id.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md#get-client-details

func (*ClientsService) List

func (s *ClientsService) List() ([]WorkspaceClient, error)

List visible clients to the user.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md#get-clients-visible-to-user

func (*ClientsService) ListClientProjects

func (s *ClientsService) ListClientProjects(id int) ([]Project, error)

ListClientProjects lists client projects.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md#get-client-projects

type Project

type Project struct {
	ID          int        `json:"id,omitempty"`
	Name        string     `json:"name,omitempty"`
	WorkspaceID int        `json:"wid,omitempty"`
	ClientID    int        `json:"cid,omitempty"`
	Active      bool       `json:"active,omitempty"`
	IsPrivate   bool       `json:"is_private,omitempty"`
	Template    bool       `json:"template,omitempty"`
	TemplateID  int        `json:"template_id,omitempty"`
	Billable    bool       `json:"billable,omitempty"`
	At          *time.Time `json:"at,omitempty"`
}

Project represents project on a workspace.

type ProjectCreate

type ProjectCreate struct {
	Project *Project `json:"project,omitempty"`
}

ProjectCreate represents posted data to be sent to projects endpoint.

type ProjectResponse

type ProjectResponse struct {
	Data *Project `json:"data,omitempty"`
}

ProjectResponse acts as a response wrapper where response returns in format of "data": Project's object.

type ProjectUser

type ProjectUser struct {
	ID          int        `json:"id,omitempty"`
	ProjectID   int        `json:"pid,omitempty"`
	UserID      int        `json:"uid,omitempty"`
	WorkspaceID int        `json:"wid,omitempty"`
	Manager     bool       `json:"manager,omitempty"`
	Rate        float64    `json:"rate,omitempty"`
	At          *time.Time `json:"at,omitempty"`
}

ProjectUser represents association between project and user.

type ProjectUserCreate

type ProjectUserCreate struct {
	ProjectUser *ProjectUser `json:"project_user,omitempty"`
}

ProjectUserCreate represents posted data to be sent to project users endpoint.

type ProjectUserMassCreate

type ProjectUserMassCreate struct {
	ProjectUser *ProjectUserMultipleUserID `json:"project_user,omitempty"`
}

ProjectUserMassCreate represents posted data to create multipe project users for single project.

type ProjectUserMassResponse

type ProjectUserMassResponse struct {
	Data []ProjectUser `json:"data,omitempty"`
}

ProjectUserMassResponse acts as a response wrapper where response returns in format of "data": [ ... ].

type ProjectUserMultipleUserID

type ProjectUserMultipleUserID struct {
	ID          int        `json:"id,omitempty"`
	ProjectID   int        `json:"pid,omitempty"`
	UserID      string     `json:"uid,omitempty"`
	WorkspaceID int        `json:"wid,omitempty"`
	Manager     bool       `json:"manager,omitempty"`
	Rate        float64    `json:"rate,omitempty"`
	At          *time.Time `json:"at,omitempty"`
}

ProjectUserMultipleUserID represents a project user where UID is a string which can hold multiple IDs separated by comma.

type ProjectUserResponse

type ProjectUserResponse struct {
	Data *ProjectUser `json:"data,omitempty"`
}

ProjectUserResponse acts as a response wrapper where response returns in format of "data": ProjectUser's object.

type ProjectUsersService

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

ProjectUsersService handles communication with the project_users related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md

func (*ProjectUsersService) Delete

func (s *ProjectUsersService) Delete(id int) error

Delete a project user.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md#delete-a-project-user

func (*ProjectUsersService) MassCreate

MassCreate creates multiple project users for single project.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md#create-multiple-project-users-for-single-project

func (*ProjectUsersService) MassDelete

func (s *ProjectUsersService) MassDelete(pids string) error

MassDelete a project user.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md#delete-multiple-project-users

func (*ProjectUsersService) MassUpdate

func (s *ProjectUsersService) MassUpdate(pids string, pu *ProjectUser) ([]ProjectUser, error)

MassUpdate mass update project users.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md#mass-update-for-project-users

type ProjectsService

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

ProjectsService handles communication with the projects related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/projects.md

func (*ProjectsService) Create

func (s *ProjectsService) Create(p *Project) (*Project, error)

Create a project.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/projects.md#create-project

func (*ProjectsService) Get

func (s *ProjectsService) Get(id int) (*Project, error)

Get project data.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/projects.md#get-project-data

func (*ProjectsService) ProjectUsers

func (s *ProjectsService) ProjectUsers(id int) ([]ProjectUser, error)

ProjectUsers gets project users.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/projects.md#get-project-users

func (*ProjectsService) Update

func (s *ProjectsService) Update(p *Project) (*Project, error)

Update project data.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md#update-a-client

type Tag

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

Tag represents a tag.

type TagCreate

type TagCreate struct {
	Tag *Tag `json:"tag,omitempty"`
}

TagCreate represents posted data to be sent to clients endpoint.

type TagResponse

type TagResponse struct {
	Data *Tag `json:"data,omitempty"`
}

TagResponse acts as a response wrapper where response returns in format of "data": Tag's object.

type TagsService

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

TagsService handles communication with the tags related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md

func (*TagsService) Create

func (s *TagsService) Create(t *Tag) (*Tag, error)

Create a new tag.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md#create-tag

func (*TagsService) Delete

func (s *TagsService) Delete(id int) error

Delete a tag.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md#delete-a-tag

func (*TagsService) Update

func (s *TagsService) Update(t *Tag) (*Tag, error)

Update a tag.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md#update-a-tag

type Task

type Task struct {
	ID               int        `json:"id,omitempty"`
	Name             string     `json:"name,omitempty"`
	ProjectID        int        `json:"pid,omitempty"`
	UserID           int        `json:"uid,omitempty"`
	WorkspaceID      int        `json:"wid,omitempty"`
	EstimatedSeconds int        `json:"estimated_seconds,omitempty"`
	Active           bool       `json:"active,omitempty"`
	At               *time.Time `json:"at,omitempty"`
}

Task represents a task.

type TaskCreate

type TaskCreate struct {
	Task *Task `json:"task,omitempty"`
}

TaskCreate represents posted data to be sent to task endpoint.

type TaskMassResponse

type TaskMassResponse struct {
	Data []Task `json:"data,omitempty"`
}

TaskMassResponse acts as a response wrapper where response returns in format of "data": [ ... ].

type TaskResponse

type TaskResponse struct {
	Data *Task `json:"data,omitempty"`
}

TaskResponse acts as a response wrapper where response returns in format of "data": Tasks's object.

type TasksService

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

TasksService handles communication with the tasks related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md

func (*TasksService) Delete

func (s *TasksService) Delete(id int) error

Delete a task.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md#delete-a-task

func (*TasksService) Get

func (s *TasksService) Get(id int) (*Task, error)

Get task details by task_id.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md#get-task-details

func (*TasksService) MassDelete

func (s *TasksService) MassDelete(ids string) error

MassDelete mass delete tasks.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md#delete-multiple-tasks

func (*TasksService) MassUpdate

func (s *TasksService) MassUpdate(ids string, t *Task) ([]Task, error)

MassUpdate mass update tasks.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md#update-multiple-tasks

func (*TasksService) Update

func (s *TasksService) Update(t *Task) (*Task, error)

Update a task.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md#update-a-task

type TimeEntriesService

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

TimeEntriesService handles communication with the time entries related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md

func (*TimeEntriesService) Create

func (s *TimeEntriesService) Create(te *TimeEntry) (*TimeEntry, error)

Create a time entry.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#create-a-time-entry

func (*TimeEntriesService) Delete

func (s *TimeEntriesService) Delete(id int) error

Delete a time entry.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#delete-a-time-entry

func (*TimeEntriesService) Get

func (s *TimeEntriesService) Get(id int) (*TimeEntry, error)

Get time entry details.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#get-time-entry-details

func (*TimeEntriesService) List

func (s *TimeEntriesService) List(start, end *time.Time) ([]TimeEntry, error)

List time entries. With start and end parameters you can specify the date range of the time entries returned. If start and end are not specified, time entries started during the last 9 days are returned. start and end must be ISO 8601 date and time strings.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#get-time-entries-started-in-a-specific-time-range

func (*TimeEntriesService) Start

func (s *TimeEntriesService) Start(te *TimeEntry) (*TimeEntry, error)

Start a time entry.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#start-a-time-entry

func (*TimeEntriesService) Stop

func (s *TimeEntriesService) Stop(id int) (*TimeEntry, error)

Stop a time entry.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#stop-a-time-entry

func (*TimeEntriesService) Update

func (s *TimeEntriesService) Update(te *TimeEntry) (*TimeEntry, error)

Update a time entry.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#update-a-time-entry

type TimeEntry

type TimeEntry struct {
	ID          int        `json:"id,omitempty"`
	WorkspaceID int        `json:"wid,omitempty"`
	ProjectID   int        `json:"pid,omitempty"`
	TaskID      int        `json:"tid,omitempty"`
	Billable    bool       `json:"billable,omitempty"`
	Start       *time.Time `json:"start,omitempty"`
	Stop        *time.Time `json:"stop,omitempty"`
	Duration    int        `json:"duration,omitempty"`
	CreatedWith string     `json:"created_with,omitempty"`
	Tags        []string   `json:"tags,omitempty"`
	Duronly     bool       `json:"duronly,omitempty"`
	At          int        `json:"at,omitempty"`
}

TimeEntry represents a time entry

type TimeEntryCreate

type TimeEntryCreate struct {
	TimeEntry *TimeEntry `json:"time_entry,omitempty"`
}

TimeEntryCreate represents posted data to be sent to time entries endpoint.

type TimeEntryResponse

type TimeEntryResponse struct {
	Data *TimeEntry `json:"data,omitempty"`
}

TimeEntryResponse acts as a response wrapper where response returns in format of "data": TimeEntry's object.

type User

type User struct {
	// User's ID
	ID int `json:"id,omitempty"`

	// User's fullname
	Fullname string `json:"fullname,omitempty"`

	// User API token in https://www.toggl.com/user/edit
	APIToken string `json:"api_token,omitempty"`

	// Default workspace ID
	DefautWID int `json:"default_wid,omitempty"`

	// User's email
	Email string `json:"email,omitempty"`

	// Time format like "h:mm A"
	TimeOfDayFormat string `json:"timeofday_format,omitempty"`

	// Date format like "MM/DD/YYYY"
	DateFormat string `json:"date_format,omitempty"`

	// Whether start and stop time are saved on time entry
	StoreStartAndStopTime bool `json:"store_start_and_stop_time,omitempty"`

	// Sunday=0
	BeginningOfWeek int `json:"beginning_of_week,omitempty"`

	// User's language such as "en_US"
	Language string `json:"language,omitempty"`

	// URL with the user's profile picture
	ImageURL string `json:"image_url,omitempty"`

	// Should a piechart be shown on the sidebar
	SidebarPiechart bool `json:"sidebar_piechart,omitempty"`

	// Timestamp of last changes, e.g. "2013-03-06T12:18:42+00:00"
	At *time.Time `json:"at,omitempty"`

	TimeEntries []TimeEntry `json:"time_entries,omitempty"`
	Projects    []Project   `json:"projects,omitempty"`
	Tags        []Tag       `json:"tags,omitempty"`
}

User represents Toggl's user.

type UserCredential

type UserCredential struct {
	Email    string `json:"email,omitempty"`
	Password string `json:"password,omitempty"`
}

UserCredential represents user credential to signup a new user.

type UserResponse

type UserResponse struct {
	Since int   `json:"since,omitempty"`
	Data  *User `json:"data,omitempty"`
}

UserResponse acts as a response wrapper where response returns in format of "data": User's object.

type UserSignup

type UserSignup struct {
	User *UserCredential `json:"user,omitempty"`
}

UserSignup represents posted data to be sent to Signup endpoint.

type UsersService

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

UsersService handles communication with the user related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/users.md

func (*UsersService) Me

func (s *UsersService) Me(withRelatedData bool) (*User, error)

Me returns current user data. If related data is set to true, a more complete response will be returned.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/users.md#get-current-user-data

func (*UsersService) Signup

func (s *UsersService) Signup(uc *UserCredential) (*User, error)

Signup new user.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/users.md#sign-up-new-user

type Workspace

type Workspace struct {
	ID      int        `json:"id,omitempty"`
	Name    string     `json:"name,omitempty"`
	Premium bool       `json:"premium,omitempty"`
	At      *time.Time `json:"at,omitempty"`
}

Workspace represents workspace of Toggl's user.

type WorkspaceClient

type WorkspaceClient struct {
	ID          int        `json:"id,omitempty"`
	WorkspaceID int        `json:"wid,omitempty"`
	Name        string     `json:"name,omitempty"`
	Notes       string     `json:"notes,omitempty"`
	HourlyRate  float64    `json:"hrate,omitempty"`
	Currency    string     `json:"cur,omitempty"`
	At          *time.Time `json:"at,omitempty"` // indicates the time client was last updated
}

WorkspaceClient represents client of user's workspace.

type WorkspaceClientCreate

type WorkspaceClientCreate struct {
	Client *WorkspaceClient `json:"client,omitempty"`
}

WorkspaceClientCreate represents posted data to be sent to clients endpoint.

type WorkspaceClientResponse

type WorkspaceClientResponse struct {
	Data *WorkspaceClient `json:"data,omitempty"`
}

WorkspaceClientResponse acts as a response wrapper where response returns in format of "data": Client's object.

type WorkspaceUser

type WorkspaceUser struct {
	ID          int  `json:"id,omitempty"`
	UserID      int  `json:"uid,omitempty"`
	WorkspaceID int  `json:"wid,omitempty"`
	Admin       bool `json:"admin,omitempty"`
	Active      bool `json:"active,omitempty"`
}

WorkspaceUsers represents workspace user.

type WorkspaceUserCreate

type WorkspaceUserCreate struct {
	WorkspaceUser *WorkspaceUser `json:"workspace_user,omitempty"`
}

WorkspaceUserCreate represents posted data to be sent to workspace users endpoint.

type WorkspaceUserResponse

type WorkspaceUserResponse struct {
	Data *WorkspaceUser `json:"data,omitempty"`
}

WorkspaceUserResponse acts as a response wrapper where response returns in format of "data": WorkspaceUser's object.

type WorkspaceUsersService

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

WorkspacesUsersService handles communication with the workspace users related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspace_users.md

func (*WorkspaceUsersService) Delete

func (s *WorkspaceUsersService) Delete(id int) error

Delete workspace user.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspace_users.md#delete-workspace-user

func (*WorkspaceUsersService) Update

Update workspace user. Only flag admin can be changed.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspace_users.md#update-workspace-user

type WorkspacesService

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

WorkspacesService handles communication with the workspace related methods of the Toggl API.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md

func (*WorkspacesService) List

func (s *WorkspacesService) List() ([]Workspace, error)

List user's workspace.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md#get-workspaces

func (*WorkspacesService) ListClients

func (s *WorkspacesService) ListClients(id int) ([]WorkspaceClient, error)

ListClients returns list of clients on specified workspace id.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md#get-workspace-clients

func (*WorkspacesService) ListProjects

func (s *WorkspacesService) ListProjects(id int, filter string) ([]Project, error)

ListProjects returns list of projects on specified workspace id.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md#get-workspace-projects

func (*WorkspacesService) ListTasks

func (s *WorkspacesService) ListTasks(id int, filter string) ([]Task, error)

ListTasks returns list of tasks on specified workspace id.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md#get-workspace-tasks

func (*WorkspacesService) ListUsers

func (s *WorkspacesService) ListUsers(id int) ([]User, error)

ListUsers returns list of users on specified workspace id.

Toggl API docs: https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md#get-workspace-users

Jump to

Keyboard shortcuts

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