harvest

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2021 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range or equal to 202 Accepted. API error responses are expected to have response body, and a JSON response body that maps to ErrorResponse.

Types

type AuthError

type AuthError ErrorResponse

func (*AuthError) Error

func (a *AuthError) Error() string

type Client

type Client struct {

	// Base URL for API requests. Defaults to the public API.
	// BaseURL should always be specified with a trailing slash.
	BaseURL *url.URL

	AccessToken string // https://help.getharvest.com/api-v2/authentication-api/authentication/authentication/
	AccountId   string // https://help.getharvest.com/api-v2/authentication-api/authentication/authentication/

	// User agent used when communicating with the Harvest API.
	UserAgent string // https://help.getharvest.com/api-v2/authentication-api/authentication/authentication/

	// Services used for talking to different parts of the Harvest API.
	TimeEntries *TimeEntriesService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(accessToken string, accountId string) *Client

func (*Client) Do

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

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) NewRequest

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

type ErrorResponse

type ErrorResponse struct {
	Response         *http.Response // HTTP response that caused this error
	ErrorCode        string         `json:"error"`             // error code
	ErrorDescription string         `json:"error_description"` // error message
}

An ErrorResponse reports one or more errors caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ListOptions

type ListOptions struct {
	// For paginated result sets, page of results to retrieve.
	Page int `url:"page,omitempty"`

	// For paginated result sets, the number of results to include per page.
	PerPage int `url:"per_page,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support offset pagination.

type Pagination

type Pagination struct {
	PerPage      int `json:"per_page"`
	TotalPages   int `json:"total_pages"`
	TotalEntries int `json:"total_entries"`
	NextPage     int `json:"next_page"`
	PreviousPage int `json:"previous_page"`
	Page         int `json:"page"`
}

type Project

type Project struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

type Response

type Response struct {
	*http.Response
	NextPage     int
	PreviousPage int
	FirstPage    int
	LastPage     int
}

Response is a API response. This wraps the standard http.Response returned from API and provides convenient access to things like pagination links.

type Task

type Task struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

type TimeEntriesListOptions

type TimeEntriesListOptions struct {
	From string `url:"from,omitempty"`
	To   string `url:"to,omitempty"`

	ListOptions
}

TimeEntriesListOptions specifies the optional parameters to the TimeEntriesService.List method.

type TimeEntriesService

type TimeEntriesService service

type TimeEntry

type TimeEntry struct {
	Id        int     `json:"id"`
	Hours     float64 `json:"hours"`
	Notes     string  `json:"notes"`
	Project   Project `json:"project"`
	User      User    `json:"user"`
	Task      Task    `json:"task"`
	SpentDate string  `json:"spent_date"`
}

type User

type User struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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