harvest

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2019 License: MIT Imports: 13 Imported by: 0

README

harvest

harvest is a Go client library for accessing the Harvest API.

Usage

import "github.com/PeterVerschuure/harvest"

Construct a new Harvest client, then use the client to access the Harvest API.

apiClient := harvest.NewAPIClientWithBasicAuth(
	"YOUR_USERNAME", "YOUR_PASSWORD", "YOUR_SUBDOMAIN")

clients := apiClient.Client.List()
client := apiClient.Client.Find(123123)

people := apiClient.People.List()
person := apiClient.People.Find(123123)

License

This library is distributed under the MIT-style license found in the LICENSE file.

Documentation

Overview

Package harvest provides data structures and a wrapper for the Harvest API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient struct {

	// Data interface accessors
	Client          *ClientService
	People          *PersonService
	Project         *ProjectService
	Invoice         *InvoiceService
	Account         *AccountService
	Task            *TaskService
	TaskAssignment  *TaskAssignmentService
	Contact         *ContactService
	Expense         *ExpenseService
	ExpenseCategory *ExpenseCategoryService
	Entry           *EntryService
	Payment         *PaymentService
	// contains filtered or unexported fields
}

APIClient contains credentials & data interfaces

func NewAPIClientWithBasicAuth

func NewAPIClientWithBasicAuth(username, password, subdomain string) (c *APIClient)

NewAPIClientWithBasicAuth instantiates a new http.Client and returns a new APIClient using HTTP basic auth credentials

func NewCachingAPIClientWithBasicAuth

func NewCachingAPIClientWithBasicAuth(username, password, subdomain string, cacheInterval time.Duration) (c *APIClient)

NewCachingAPIClientWithBasicAuth instantiates a new http.Client and returns a new APIClient using HTTP basic auth credentials. Responses are cached and reused for up to cacheInterval.

func (*APIClient) GetJSON

func (c *APIClient) GetJSON(path string) (jsonResponse []byte, err error)

GetJSON makes an HTTP GET request to the specified path and returns the body of the HTTP response

func (*APIClient) PostJSON

func (c *APIClient) PostJSON(path string, v interface{}) error

func (*APIClient) PutJSON

func (c *APIClient) PutJSON(path string, v interface{}) error

type Account

type Account struct {
	Company Company `json:"company"`
	Person  Person  `json:"user"`
}

type AccountService

type AccountService struct {
	Service
}

func (*AccountService) Find

func (a *AccountService) Find() (Account, error)

Find requests user information for specified user and returns response

type CategoryResponse

type CategoryResponse struct {
	ExpenseCategory `json:"expense_category"`
}

type Client

type Client struct {
	Name                    string    `json:"name"`
	Currency                string    `json:"currency"`
	CurrencySymbol          string    `json:"currency_symbol"`
	Active                  bool      `json:"active"`
	ID                      int       `json:"id"`
	HighriseID              int       `json:"highrise_id"`
	CreatedAt               time.Time `json:"created_at"`
	UpdatedAt               time.Time `json:"updated_at"`
	Details                 string    `json:"details"`
	DefaultInvoiceTimeframe string    `json:"default_invoice_timeframe"`
	LastInvoiceKind         string    `json:"last_invoice_kind"`
}

type ClientResponse

type ClientResponse struct {
	Client `json:"client"`
}

type ClientService

type ClientService struct {
	Service
}

func (*ClientService) Find

func (c *ClientService) Find(clientID int) (ClientResponse, error)

Find requests client information for specified client and returns response

func (*ClientService) List

func (c *ClientService) List() ([]ClientResponse, error)

List requests list of clients and returns response

type Company

type Company struct {
	BaseURI            string  `json:"base_uri"`
	FullDomain         string  `json:"full_domain"`
	Name               string  `json:"name"`
	Active             bool    `json:"active"`
	WeekStartDay       string  `json:"week_start_day"`
	TimeFormat         string  `json:"time_format"`
	Clock              string  `json:"clock"`
	DecimalSymbol      string  `json:"decimal_symbol"`
	ColorScheme        string  `json:"color_scheme"`
	Modules            Modules `json:"modules"`
	ThousandsSeperator string  `json:"thousands_separator"`
}

type Contact

type Contact struct {
	ID          int    `json:"id"`
	ClientID    int    `json:"client_id"`
	FirstName   string `json:"first_name"`
	LastName    string `json:"last_name"`
	Title       string `json:"title"`
	Email       string `json:"email"`
	MobilePhone string `json:"phone_mobile"`
	OfficePhone string `json:"phone_office"`
	Fax         string `json:"fax"`
	CreatedAt   Date   `json:"created_at"`
	UpdatedAt   Date   `json:"updated_at"`
}

type ContactResponse

type ContactResponse struct {
	Contact `json:"contact"`
}

type ContactService

type ContactService struct {
	Service
}

func (*ContactService) Find

func (c *ContactService) Find(contactID int) (ContactResponse, error)

Find requests contact information for specified contact and returns repsonse

func (*ContactService) List

func (c *ContactService) List() ([]ContactResponse, error)

List requests list of contacts and returns response

type Date

type Date struct {
	time.Time
}

func (Date) MarshalJSON

func (harvestDate Date) MarshalJSON() ([]byte, error)

func (*Date) UnmarshalJSON

func (harvestDate *Date) UnmarshalJSON(input []byte) (err error)

type Entry

type Entry struct {
	ID        int       `json:"id"`
	UserID    int       `json:"user_id"`
	TaskID    int       `json:"task_id"`
	InvoiceID int       `json:"invoice_id"`
	ProjectID int       `json:"project_id"`
	Hours     float64   `json:"hours"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	SpentAt   Date      `json:"spent_at"`
	// `timer_started_at` is in Harvest's JSON response, but in entries examined
	// always set to null, and is creating JSON marshalling problems, so we're
	// ignoring it for now.
	//TimerStartedAt time.Time   `json:"timer_started_at"`
	IsBilled bool   `json:"is_billed"`
	IsClosed bool   `json:"is_closed"`
	Notes    string `json:"notes"`
}

type EntryResponse

type EntryResponse struct {
	Entry `json:"day_entry"`
}

type EntryService

type EntryService struct {
	Service
}

func (*EntryService) ListPerson

func (c *EntryService) ListPerson(personID int, from time.Time, to time.Time) ([]EntryResponse, error)

Returns all entries associated with a person

func (*EntryService) ListProject

func (c *EntryService) ListProject(projectID int, from time.Time, to time.Time) ([]EntryResponse, error)

Returns all entries associated with a project

type Expense

type Expense struct {
	ID                int     `json:"id,omitempty"`
	Notes             string  `json:"notes"`
	TotalCost         float64 `json:"total_cost,omitempty"`
	Units             float64 `json:"units,omitempty"`
	ProjectID         int     `json:"project_id"`
	ExpenseCategoryID int     `json:"expense_category_id"`
	Billable          bool    `json:"billable"`
	SpentAt           Date    `json:"spent_at"`
	IsLocked          bool    `json:"is_locked"`
}

type ExpenseCategory

type ExpenseCategory struct {
	ID          int       `json:"id"`
	Name        string    `json:"name"`
	UnitName    string    `json:"unit_name"`
	UnitPrice   float64   `json:"unit_price"`
	Deactivated bool      `json:"deactivated"`
	UpdatedAt   time.Time `json:"updated_at"`
	CreatedAt   time.Time `json:"created_at"`
}

type ExpenseCategoryService

type ExpenseCategoryService struct {
	Service
}

func (*ExpenseCategoryService) Find

Find requests expense category information for specified expense category and returns response

func (*ExpenseCategoryService) List

List requests list of expense categories and returns response

type ExpenseResponse

type ExpenseResponse struct {
	Expense `json:"expense"`
}

type ExpenseService

type ExpenseService struct {
	Service
}

func (*ExpenseService) Add

func (c *ExpenseService) Add(e Expense) error

func (*ExpenseService) Find

func (c *ExpenseService) Find(expID int) (ExpenseResponse, error)

Find requests expense information for specified expense and returns response

func (*ExpenseService) ForProject

func (c *ExpenseService) ForProject(projID int, from, to time.Time) ([]ExpenseResponse, error)

func (*ExpenseService) List

func (c *ExpenseService) List() ([]ExpenseResponse, error)

List requests list of expenses and returns response

func (*ExpenseService) Update

func (c *ExpenseService) Update(e Expense) error

type Invoice

type Invoice struct {
	ID                 int       `json:"id"`
	Amount             float64   `json:"amount"`
	DueAmount          float64   `json:"due_amount"`
	DueAt              Date      `json:"due_at"`
	DueAtHumanFormat   string    `json:"due_at_human_format"`
	PeriodEnd          Date      `json:"period_end"`
	PeriodStart        Date      `json:"period_start"`
	ClientID           int       `json:"client_id"`
	Subject            string    `json:"subject"`
	Currency           string    `json:"currency"`
	IssuedAt           Date      `json:"issued_at"`
	CreatedByID        int       `json:"created_by_id"`
	Notes              string    `json:"notes"`
	Number             string    `json:"number"`
	PurchaseOrder      string    `json:"purchase_order"`
	ClientKey          string    `json:"client_key"`
	State              string    `json:"state"`
	Tax                float64   `json:"tax"`
	Tax2               float64   `json:"tax2"`
	TaxAmount          float64   `json:"tax_amount"`
	TaxAmount2         float64   `json:"tax2_amount"`
	DiscountAmount     float64   `json:"discount_amount"`
	Discount           float64   `json:"discount"`
	RecurringInvoiceID int       `json:"recurring_invoice_id"`
	EstimateID         int       `json:"estimate_id"`
	RetainerID         int       `json:"retainer_id"`
	UpdatedAt          time.Time `json:"updated_at"`
	CreatedAt          time.Time `json:"created_at"`
	CSVLineItems       string    `json:"csv_line_items"`
}

func (*Invoice) LineItems

func (i *Invoice) LineItems() []map[string]string

type InvoiceResponse

type InvoiceResponse struct {
	Invoice `json:"invoices"`
}

type InvoiceService

type InvoiceService struct {
	Service
}

func (*InvoiceService) Find

func (i *InvoiceService) Find(invoiceID int) (InvoiceResponse, error)

Find requests invoice information for specified invoice and returns response

func (*InvoiceService) List

func (i *InvoiceService) List() ([]InvoiceResponse, error)

List requests list of invoices and returns response

type Modules

type Modules struct {
	Expenses  bool `json:"expenses"`
	Invoices  bool `json:"invoices"`
	Estimates bool `json:"estimates"`
	Approval  bool `json:"approval"`
}

Specifies what Harvest modules a company is configured to use

type Payment

type Payment struct {
	ID                  int     `json:"id"`
	InvoiceID           int     `json:"invoice_id"`
	Amount              float64 `json:"amount"`
	PaidAt              Date    `json:"paid_at"`
	CreatedAt           Date    `json:"created_at"`
	Notes               string  `json:"notes"`
	RecordedBy          string  `json:"recorded_by"`
	RecordedByEmail     string  `json:"recorded_by_email"`
	PayPalTransactionID *int    `json:"pay_pal_transaction_id"`
	Authorization       *int    `json:"authorization"`
	PaymentGatewayID    *int    `json:"payment_gateway_id"`
}

type PaymentResponse

type PaymentResponse struct {
	Payment `json:"payment"`
}

type PaymentService

type PaymentService struct {
	Service
}

func (*PaymentService) ListInvoice

func (p *PaymentService) ListInvoice(invoiceID int) ([]PaymentResponse, error)

List requests list of payments and for an invoice

type Person

type Person struct {
	ID                           int `json:"id"`
	DefaultExpenseCategoryID     int
	DefaultExpenseProjectID      int
	DefaultTaskID                int
	DefaultTimeProjectID         int
	DefaultHourlyRate            float64 `json:"default_hourly_rate"`
	FirstName                    string  `json:"first_name"`
	LastName                     string  `json:"last_name"`
	Email                        string  `json:"email"`
	IdentityURL                  string
	OpensocialIdentifier         string
	Telephone                    string  `json:"telephone"`
	Timezone                     string  `json:"timezone"`
	CostRate                     float64 `json:"cost_rate"`
	WeeklyDigestSentOn           string
	Department                   string `json:"department"`
	IsContractor                 bool   `json:"is_contractor"`
	IsAdmin                      bool   `json:"is_admin"`
	IsActive                     bool   `json:"is_active"`
	HasAccessToAllFutureProjects bool   `json:"has_access_to_all_future_projects"`
	WantsNewsletter              bool   `json:"wants_newsletter"`
	WantsWeeklyDigest            bool
	CreatedAt                    time.Time `json:"created_at"`
	UpdatedAt                    time.Time `json:"updated_at"`
}

type PersonResponse

type PersonResponse struct {
	Person `json:"user"`
}

type PersonService

type PersonService struct {
	Service
}

func (*PersonService) Find

func (c *PersonService) Find(personID int) (PersonResponse, error)

Find requests people information for specified person and returns response

func (*PersonService) List

func (c *PersonService) List() ([]PersonResponse, error)

List requests list of people and returns response

type Project

type Project struct {
	ID                               int     `json:"id"`
	ClientID                         int     `json:"client_id"`
	Name                             string  `json:"name"`
	Code                             string  `json:"code"`
	Notes                            string  `json:"notes"`
	BillBy                           string  `json:"bill_by"`
	BudgetBy                         string  `json:"budget_by"`
	Active                           bool    `json:"active"`
	CostBudgetIncludeExpenses        bool    `json:"cost_budget_include_expenses"`
	Billable                         bool    `json:"billable"`
	ShowBudgetToAll                  bool    `json:"show_budget_to_all"`
	CostBudget                       float64 `json:"cost_budget"`
	HourlyRate                       float64 `json:"hourly_rate"`
	Budget                           float64 `json:"budget"`
	NotifyWhenOverBudget             float64 `json:"notify_when_overbudget"`
	OverBudgetNotificationPercentage float64 `json:"over_budget_notification_percentage"`
	OverBudgetNotifiedAt             Date    `json:"over_budget_notified_at"`
	CreatedAt                        Date    `json:"created_at"`
	UpdatedAt                        Date    `json:"updated_at"`
	HintEarliestRecordAt             Date    `json:"hint_earliest_record_at"`
	HintLatestRecordAt               Date    `json:"hint_latest_record_at"`
	StartsOn                         Date    `json:"starts_on"`
	EndsOn                           Date    `json:"ends_on"`
	Estimate                         float64 `json:"estimate"`
	EstimateBy                       string  `json:"estimate_by"`
	IsFixedFee                       bool    `json:"is_fixed_fee"`
	Fee                              float64 `json:"fee"`
}

type ProjectResponse

type ProjectResponse struct {
	Project `json:"project"`
}

Wrapper for simple unmarshalling of JSON data

type ProjectService

type ProjectService struct {
	Service
}

func (*ProjectService) Find

func (c *ProjectService) Find(projectID int) (ProjectResponse, error)

Find requests project information for specified project

func (*ProjectService) List

func (c *ProjectService) List() ([]ProjectResponse, error)

List requests list of projects and returns response

type Service

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

type Task

type Task struct {
	ID                int     `json:"id"`
	Name              string  `json:"name"`
	BillableByDefault bool    `json:"billable_by_default"`
	Deactivated       bool    `json:"deactivated"`
	CreatedAt         Date    `json:"created_at"`
	UpdateAt          Date    `json:"updated_at"`
	DefaultHourlyRate float64 `json:"default_hourly_rate"`
	IsDefault         bool    `json:"is_default"`
}

type TaskAssignment

type TaskAssignment struct {
	ID         int       `json:"id"`
	Billable   bool      `json:"billable"`
	IsActive   bool      `json:"is_active"`
	CreatedAt  time.Time `json:"created_at"`
	UpdateAt   time.Time `json:"updated_at"`
	HourlyRate float64   `json:"hourly_rate"`
	Project    struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Code string `json:"code"`
	} `json:"project"`
	Task struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
	} `json:"task"`
}

type TaskAssignmentResponse

type TaskAssignmentResponse struct {
	TaskAssignment `json:"task_assignment"`
}

type TaskAssignmentService

type TaskAssignmentService struct {
	Service
}

func (*TaskAssignmentService) ListByProject

func (c *TaskAssignmentService) ListByProject(projectID int) ([]TaskAssignmentResponse, error)

type TaskResponse

type TaskResponse struct {
	Task `json:"task"`
}

type TaskService

type TaskService struct {
	Service
}

func (*TaskService) Find

func (c *TaskService) Find(taskID int) (TaskResponse, error)

Find requests task information for specified task and returns response

func (*TaskService) List

func (c *TaskService) List() ([]TaskResponse, error)

List requests list of tasks and returns response

Jump to

Keyboard shortcuts

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