harvest

package module
v0.0.0-...-53a1ea2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2016 License: MIT Imports: 11 Imported by: 0

README

#go-harvest

Go client library for Harvest.

Features

  • Authentication (HTTP Basic)

Some actions require an authenticated user.

Here is an example with HTTP Basic authentification.

package main


import (
	"github.com/EvgenKostenko/go-harvest"
	"fmt"
)

func main() {
	harvestClient, err := harvest.NewClient(nil, "https://test.harvestapp.com/")
	if err != nil {
		panic(err)
	}

	res, err := harvestClient.Authentication.Acquire("test@test.com", "foobar")
	if err != nil || res == false {
		fmt.Printf("Result: %v\n", res)
		panic(err)
	}

	if harvestClient.Authentication.Authenticated() {
		fmt.Printf("Done")
	}

}

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. The caller is responsible to analyze the response body. The body can contain JSON (if the error is intended) or xml (sometimes Harvest just failes).

Types

type AuthenticationService

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

func (*AuthenticationService) Acquire

func (s *AuthenticationService) Acquire(username, password string) (bool, error)

func (*AuthenticationService) Authenticated

func (s *AuthenticationService) Authenticated() bool

Authenticated reports if the current Client has an authenticated session with Harvest

type Client

type Client struct {

	// Services used for talking to different parts of the Harvest API.
	Authentication *AuthenticationService
	User           *UserService
	Project        *ProjectService
	Report         *ReportService
	// contains filtered or unexported fields
}

A Client manages communication with the Harvest API.

func NewClient

func NewClient(httpClient *http.Client, baseURL string) (*Client, error)

NewClient returns a new Harvest API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication: http://help.getharvest.com/api/authentication/authentication/http-basic/ baseURL is the HTTP endpoint of your Harvest instance and should always be specified with a trailing slash.

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 JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() url.URL

GetBaseURL will return you the Base URL. This is the same URL as in the NewClient constructor

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 DayEntries

type DayEntries []struct {
	DayEntry models.DayEntry `json:"day_entry"`
}

Type for day entry list

type DayEntryDetail

type DayEntryDetail struct {
	DayEntry models.DayEntry `json:"day_entry"`
}

type People

type People []struct {
	User models.User `json:"user"`
}

Type for users list

type PeopleOptions

type PeopleOptions struct {
	// You can also filter by updated_since to only show people that have been updated since the date you pass
	// UpdatedSince=2015-04-25+18%3A30
	UpdatedSince string `url:"updated_since,omitempty"`
}

type ProjectDetail

type ProjectDetail struct {
	Project models.Project `json:"project"`
}

type ProjectOptions

type ProjectOptions struct {
	// Requests can be filtered by client_id and updated_since
	// UpdatedSince=2015-04-25+18%3A30
	Client       string `url:"client,omitempty"`
	UpdatedSince string `url:"updated_since,omitempty"`
}

type ProjectService

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

func (*ProjectService) CreateProject

func (s *ProjectService) CreateProject(project *models.Project) (*http.Response, error)

Create A New Project HTTP Response: 201 Created The method by which the project is budgeted or estimated. Parameter: BudgetBy or EstimateBy Options: Project (Hours Per Project),

         Project_Cost (Total Project Fees),
			Task (Hours Per Task),
			Person (Hours Per Person),
			None (No Budget).\

func (*ProjectService) DeleteProject

func (s *ProjectService) DeleteProject(projectId int) (*http.Response, error)

func (*ProjectService) GetProject

func (s *ProjectService) GetProject(projectId int) (*models.Project, *http.Response, error)

func (*ProjectService) Projects

func (s *ProjectService) Projects(opt *ProjectOptions) (*Projects, *http.Response, error)

func (*ProjectService) UpdateProject

func (s *ProjectService) UpdateProject(project *models.Project) (*http.Response, error)

The method by which the project is budgeted or estimated. Parameter: BudgetBy or EstimateBy Options: Project (Hours Per Project),

         Project_Cost (Total Project Fees),
			Task (Hours Per Task),
			Person (Hours Per Person),
			None (No Budget).\

type Projects

type Projects []struct {
	Project models.Project `json:"project"`
}

Type for project list

type ReportOptions

type ReportOptions struct {
	// Requests can be filtered by From and To parameters
	// From=2015-04-25
	// To=2015-04-25
	// Acceptable values for the OnlyBilled, OnlyUnbilled, IsClosed  parameter are yes and no.
	// UpdatedSince=2015-04-25+18%3A30
	From         string `url:"from"`
	To           string `url:"to"`
	OnlyBilled   string `url:"only_billed,omitempty"`
	OnlyUnbilled string `url:"only_unbilled,omitempty"`
	IsClosed     string `url:"is_closed,omitempty"`
	UpdatedSince string `url:"updated_since,omitempty"`
	UserId       string `url:"user_id,omitempty"`
}

type ReportService

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

func (*ReportService) DayEntriesByProject

func (s *ReportService) DayEntriesByProject(projectId int, opt *ReportOptions) (*DayEntries, *http.Response, error)

func (*ReportService) DayEntriesByUser

func (s *ReportService) DayEntriesByUser(userId int, opt *ReportOptions) (*DayEntries, *http.Response, error)

type Session

type Session struct {
	Authorization string
}

type UserDetail

type UserDetail struct {
	User models.User `json:"user"`
}

type UserParameters

type UserParameters struct {
	User models.UserParameters `json:"user"`
}

type UserService

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

func (*UserService) CreateUser

func (s *UserService) CreateUser(user *models.UserParameters) (*http.Response, error)

Create new user POST https://YOURACCOUNT.harvestapp.com/people HTTP Response: 201 Created Upon creation, we’ll send an email to the user with instructions for setting a password. At minimum, you’ll need to include values for email, first-name, and last-name

func (*UserService) GetUser

func (s *UserService) GetUser(userId int) (*models.User, *http.Response, error)

func (*UserService) People

func (s *UserService) People(opt *PeopleOptions) (*People, *http.Response, error)

func (*UserService) UpdateUser

func (s *UserService) UpdateUser(user *models.UserParameters) (*http.Response, error)

Update user by ID PUT https://YOURACCOUNT.harvestapp.com/people/{USERID} HTTP Response: 200 OK You can update selected attributes for a user with this request. Note, updates to password are disregarded.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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