harvest

package module
v0.0.0-...-cfaf43f Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 9 Imported by: 3

README

Go Harvest API

Harvest Logo

GoDoc Build Status Coverage Status

A #golang package to access the Harvest API.

Installation

The Go Harvest API has been tested compatible with Go 1.8 on up. Its only dependency is the github.com/pkg/errors package. It otherwise relies only on the Go standard library.

go get github.com/adlio/harvest

Basic Usage

All interaction starts with a harvest.API. Create one with your account ID and token:

client := harvest.NewTokenAPI("ACCOUNTID", "TOKEN")

Documentation

Index

Constants

View Source
const CLIENT_VERSION = "1.0"
View Source
const HARVEST_API_VERSION = "v2"
View Source
const HARVEST_DOMAIN = "api.harvestapp.com"

Variables

This section is empty.

Functions

func ContainsTaskID

func ContainsTaskID(taskID int64, tas []*TaskAssignment) bool

func ContainsUserID

func ContainsUserID(userID int64, uas []*UserAssignment) bool

func HaveSameFloat64Value

func HaveSameFloat64Value(a, b *float64) bool

func TaskAssignmentAttributesDiffer

func TaskAssignmentAttributesDiffer(ta1, ta2 *TaskAssignment) bool

func UserAssignmentAttributesDiffer

func UserAssignmentAttributesDiffer(ua1, ua2 *UserAssignment) bool

Types

type API

type API struct {
	Logger       logger
	BaseURL      string
	AccountID    string
	AccessToken  string
	RefreshToken string
	UserAgent    string
	// contains filtered or unexported fields
}

func NewTokenAPI

func NewTokenAPI(accountID string, accessToken string) *API

func (*API) AddHeaders

func (a *API) AddHeaders(req *http.Request)

Applies relevant User-Agent, Accept, Authorization headers

func (*API) CopyTaskAssignments

func (a *API) CopyTaskAssignments(destProjectID int64, sourceProjectID int64) error

func (*API) CopyUserAssignments

func (a *API) CopyUserAssignments(destProjectID int64, sourceProjectID int64) error

func (*API) CreateProject

func (a *API) CreateProject(p *Project, args Arguments) error

func (*API) CreateTaskAssignment

func (a *API) CreateTaskAssignment(projectID int64, ta *TaskAssignment, args Arguments) error

func (*API) CreateUserAssignment

func (a *API) CreateUserAssignment(ua *UserAssignment, args Arguments) error

func (*API) Delete

func (a *API) Delete(path string, args Arguments) error

func (*API) DeleteProject

func (a *API) DeleteProject(p *Project, args Arguments) error

func (*API) DeleteTaskAssignment

func (a *API) DeleteTaskAssignment(projectID int64, ta *TaskAssignment, args Arguments) error

func (*API) DeleteUserAssignment

func (a *API) DeleteUserAssignment(ua *UserAssignment, args Arguments) error

func (*API) DuplicateProject

func (a *API) DuplicateProject(sourceProjectID int64, newName string) (*Project, error)

func (*API) Get

func (a *API) Get(path string, args Arguments, target interface{}) error

func (*API) GetClient

func (a *API) GetClient(clientID int64, args Arguments) (client *Client, err error)

func (*API) GetClientContacts

func (a *API) GetClientContacts(clientID int64, args Arguments) (contacts []*Contact, err error)

func (*API) GetClients

func (a *API) GetClients(args Arguments) (clients []*Client, err error)

func (*API) GetContact

func (a *API) GetContact(contactID int64, args Arguments) (contact *Contact, err error)

func (*API) GetContacts

func (a *API) GetContacts(args Arguments) (contacts []*Contact, err error)

func (*API) GetEstimate

func (a *API) GetEstimate(estimateID int64, args Arguments) (estimate *Estimate, err error)

func (*API) GetEstimates

func (a *API) GetEstimates(args Arguments) (estimates []*Estimate, err error)

func (*API) GetExpense

func (a *API) GetExpense(expenseID int64, args Arguments) (expense *Expense, err error)

func (*API) GetExpenseCategories

func (a *API) GetExpenseCategories(args Arguments) (expenseCategories []*ExpenseCategory, err error)

func (*API) GetExpenseCategory

func (a *API) GetExpenseCategory(expenseCategoryID int64, args Arguments) (expenseCategory *ExpenseCategory, err error)

func (*API) GetExpenses

func (a *API) GetExpenses(args Arguments) (expenses []*Expense, err error)

func (*API) GetInvoice

func (a *API) GetInvoice(invoiceID int64, args Arguments) (invoice *Invoice, err error)

func (*API) GetInvoiceMessage

func (a *API) GetInvoiceMessage(invoiceID int64, messageID int64, args Arguments) (invoiceMessage *InvoiceMessage, err error)

func (*API) GetInvoiceMessages

func (a *API) GetInvoiceMessages(invoiceID int64, args Arguments) (invoiceMessages []*InvoiceMessage, err error)

func (*API) GetInvoices

func (a *API) GetInvoices(args Arguments) (invoices []*Invoice, err error)

func (*API) GetPaginated

func (a *API) GetPaginated(path string, args Arguments, target Pageable, afterFetch func()) error

func (*API) GetProject

func (a *API) GetProject(projectID int64, args Arguments) (project *Project, err error)

func (*API) GetProjects

func (a *API) GetProjects(args Arguments) (projects []*Project, err error)

func (*API) GetTask

func (a *API) GetTask(taskID int64, args Arguments) (task *Task, err error)

func (*API) GetTaskAssignment

func (a *API) GetTaskAssignment(projectID int64, taskAssignmentID int64, args Arguments) (taskAssignment *TaskAssignment, err error)

func (*API) GetTaskAssignments

func (a *API) GetTaskAssignments(projectID int64, args Arguments) (taskAssignments []*TaskAssignment, err error)

func (*API) GetTasks

func (a *API) GetTasks(args Arguments) (tasks []*Task, err error)

func (*API) GetTimeEntries

func (a *API) GetTimeEntries(args Arguments) ([]*TimeEntry, error)

func (*API) GetTimeEntriesBetween

func (a *API) GetTimeEntriesBetween(fromDate time.Time, toDate time.Time, args Arguments) ([]*TimeEntry, error)

func (*API) GetTimeEntriesForProjectBetween

func (a *API) GetTimeEntriesForProjectBetween(projectID int64, fromDate time.Time, toDate time.Time, args Arguments) ([]*TimeEntry, error)

func (*API) GetTimeEntriesForUserBetween

func (a *API) GetTimeEntriesForUserBetween(userID int64, fromDate time.Time, toDate time.Time, args Arguments) ([]*TimeEntry, error)

func (*API) GetTimeEntriesUpdatedSince

func (a *API) GetTimeEntriesUpdatedSince(sinceDate time.Time, args Arguments) ([]*TimeEntry, error)

func (*API) GetUser

func (a *API) GetUser(userID int64, args Arguments) (user *User, err error)

func (*API) GetUserAssignment

func (a *API) GetUserAssignment(projectID int64, userAssignmentID int64, args Arguments) (userAssignment *UserAssignment, err error)

func (*API) GetUserAssignments

func (a *API) GetUserAssignments(projectID int64, args Arguments) (userAssignments []*UserAssignment, err error)

func (*API) GetUsers

func (a *API) GetUsers(args Arguments) (users []*User, err error)

func (*API) Post

func (a *API) Post(path string, args Arguments, postData interface{}, target interface{}) error

func (*API) Put

func (a *API) Put(path string, args Arguments, postData interface{}, target interface{}) error

func (*API) SaveProject

func (a *API) SaveProject(p *Project, args Arguments) error

func (*API) UpdateProject

func (a *API) UpdateProject(p *Project, args Arguments) error

func (*API) UpdateTaskAssignment

func (a *API) UpdateTaskAssignment(projectID int64, ta *TaskAssignment, args Arguments) error

func (*API) UpdateUserAssignment

func (a *API) UpdateUserAssignment(ua *UserAssignment, args Arguments) error

type Arguments

type Arguments map[string]string

func Defaults

func Defaults() Arguments

func (Arguments) ToURLValues

func (args Arguments) ToURLValues() url.Values

type Client

type Client struct {
	ID        int64     `json:"id"`
	Name      string    `json:"name"`
	IsActive  bool      `json:"is_active"`
	Address   string    `json:"address"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Currency  string    `json:"currency"`
}

type ClientStub

type ClientStub struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type ClientsResponse

type ClientsResponse struct {
	PagedResponse
	Clients []*Client `json:"clients"`
}

type Contact

type Contact struct {
	ID          int64      `json:"id"`
	Title       string     `json:"title"`
	FirstName   string     `json:"first_name"`
	LastName    string     `json:"last_name"`
	Email       string     `json:"email"`
	PhoneOffice string     `json:"phone_office"`
	PhoneMobile string     `json:"phone_mobile"`
	Fax         string     `json:"fax"`
	Client      ClientStub `json:"client"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

type ContactsResponse

type ContactsResponse struct {
	PagedResponse
	Contacts []*Contact `json:"contacts"`
}

type Date

type Date struct {
	time.Time
}

func (*Date) MarshalJSON

func (d *Date) MarshalJSON() ([]byte, error)

func (*Date) Matches

func (d *Date) Matches(t time.Time) bool

func (*Date) ScanString

func (d *Date) ScanString(s string)

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(b []byte) (err error)

type Estimate

type Estimate struct {
	ID             int64               `json:"id"`
	Subject        string              `json:"subject"`
	Client         ClientStub          `json:"client,omitempty"`
	Creator        UserStub            `json:"creator,omitempty"`
	ClientKey      string              `json:"client_key"`
	Number         string              `json:"number"`
	PurchaseOrder  string              `json:"purchase_order"`
	Amount         float64             `json:"amount"`
	Tax            *float64            `json:"tax"`
	TaxAmount      float64             `json:"tax_amount"`
	Tax2           *float64            `json:"tax2"`
	Tax2Amount     float64             `json:"tax2_amount"`
	Discount       *float64            `json:"discount"`
	DiscountAmount float64             `json:"discount_amount"`
	Notes          string              `json:"notes"`
	Currency       string              `json:"currency"`
	IssueDate      *Date               `json:"issue_date,omitempty"`
	SentAt         *time.Time          `json:"sent_at,omitempty"`
	LineItems      []*EstimateLineItem `json:"line_items"`
	AcceptedAt     *time.Time          `json:"accepted_at,omitempty"`
	DeclinedAt     *time.Time          `json:"declined_at,omitempty"`
	CreatedAt      time.Time           `json:"created_at,omitempty"`
	UpdatedAt      time.Time           `json:"updated_at,omitempty"`
}

type EstimateLineItem

type EstimateLineItem struct {
	ID          int64   `json:"id"`
	Kind        string  `json:"kind"`
	Description string  `json:"description"`
	Quantity    float64 `json:"quantity"`
	UnitPrice   float64 `json:"unit_price"`
	Amount      float64 `json:"amount"`
	Taxed       bool    `json:"taxed"`
	Taxed2      bool    `json:"taxed2"`
}

type EstimatesResponse

type EstimatesResponse struct {
	PagedResponse
	Estimates []*Estimate `json:"estimates"`
}

type Expense

type Expense struct {
	ID                int64     `json:"id"`
	Notes             string    `json:"notes"`
	TotalCost         float64   `json:"total_cost"`
	Units             float64   `json:"units"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
	ProjectID         int64     `json:"project_id"`
	ExpenseCategoryID int64     `json:"expense_category_id"`
	UserID            int64     `json:"user_id"`
	SpentAt           string    `json:"spent_at"`
	IsClosed          bool      `json:"is_closed"`
	InvoiceID         int64     `json:"invoice_id"`
	Billable          bool      `json:"billable"`
	CompanyID         int64     `json:"company_id"`
	HasReceipt        bool      `json:"has_receipt"`
	ReceiptURL        string    `json:"receipt_url"`
	IsLocked          bool      `json:"is_locked"`
	LockedReason      string    `json:"locked_reason"`
}

type ExpenseCategoriesResponse

type ExpenseCategoriesResponse struct {
	PagedResponse
	ExpenseCategories []*ExpenseCategory `json:"expense_categories"`
}

type ExpenseCategory

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

type ExpensesResponse

type ExpensesResponse struct {
	PagedResponse
	Expenses []*Expense `json:"expenses"`
}

type Invoice

type Invoice struct {
	ID                 int64       `json:"id"`
	Client             *ClientStub `json:"client,omitempty"`
	PeriodStart        Date        `json:"period_start"`
	PeriodEnd          Date        `json:"period_end"`
	Number             string      `json:"number"`
	IssueDate          Date        `json:"issue_date"`
	DueDate            Date        `json:"due_date"`
	Amount             float64     `json:"amount"`
	Currency           string      `json:"currency"`
	State              string      `json:"state"`
	Notes              string      `json:"notes"`
	PurchaseOrder      string      `json:"purchase_order"`
	DueAmount          float64     `json:"due_amount"`
	DueAtHumanFormat   string      `json:"due_at_human_format"`
	CreatedAt          time.Time   `json:"created_at"`
	UpdatedAt          time.Time   `json:"updated_at"`
	SentAt             time.Time   `json:"sent_at"`
	PaidAt             time.Time   `json:"paid_at"`
	ClosedAt           time.Time   `json:"closed_at"`
	Tax                float64     `json:"tax"`
	TaxAmount          float64     `json:"tax_amount"`
	Subject            string      `json:"subject"`
	RecurringInvoiceID int64       `json:"recurring_invoice_id"`
	Tax2               float64     `json:"tax2"`
	Tax2Amount         float64     `json:"tax2_amount"`
	ClientKey          string      `json:"client_key"`
	EstimateID         int64       `json:"estimate_id"`
	Discount           float64     `json:"discount"`
	DiscountAmount     float64     `json:"discount_amount"`
	RetainerID         int64       `json:"retainer_id"`
	CreatedByID        int64       `json:"created_by_id"`
	LineItems          []*LineItem `json:"line_items"`
}

type InvoiceMessage

type InvoiceMessage struct {
	ID                int64     `json:"id"`
	InvoiceID         int64     `json:"invoice_id"`
	SendMeACopy       bool      `json:"send_me_a_copy"`
	Body              string    `json:"body"`
	CreatedAt         time.Time `json:"created_at"`
	SentBy            string    `json:"sent_by"`
	SentByEmail       string    `json:"sent_by_email"`
	ThankYou          bool      `json:"thank_you"`
	Subject           string    `json:"subject"`
	IncludePayPalLink bool      `json:"include_pay_pal_link"`
	UpdatedAt         time.Time `json:"updated_at"`
	SentFromEmail     string    `json:"sent_from_email"`
	SentFrom          string    `json:"sent_from"`
	SendReminderOn    Date      `json:"send_reminder_on"`
	FullRecipientList string    `json:"full_recipient_list"`
}

type InvoiceMessagesResponse

type InvoiceMessagesResponse struct {
	PagedResponse
	InvoiceMessages []*InvoiceMessage `json:"invoice_messages"`
}

type InvoicesResponse

type InvoicesResponse struct {
	PagedResponse
	Invoices []*Invoice `json:"invoices"`
}

type LineItem

type LineItem struct {
	ID          int64        `json:"id"`
	Kind        string       `json:"kind"`
	Description string       `json:"description"`
	Quantity    float64      `json:"quantity"`
	UnitPrice   float64      `json:"unit_price"`
	Amount      float64      `json:"amount"`
	Taxed       bool         `json:"taxed"`
	Taxed2      bool         `json:"taxed2"`
	Project     *ProjectStub `json:"project"`
}

type Pageable

type Pageable interface {
	HasNextPage() bool
}

type PagedResponse

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

func (*PagedResponse) HasNextPage

func (r *PagedResponse) HasNextPage() bool

type Project

type Project struct {
	ID                               int64       `json:"id,omitempty"`
	ClientID                         int64       `json:"client_id,omitempty"`
	Client                           *ClientStub `json:"client,omitempty"`
	Name                             string      `json:"name,omitempty"`
	Code                             string      `json:"code,omitempty"`
	IsActive                         bool        `json:"is_active"`
	IsBillable                       bool        `json:"is_billable"`
	BillBy                           string      `json:"bill_by,omitempty"`
	HourlyRate                       *float64    `json:"hourly_rate,omitempty"`
	BudgetBy                         string      `json:"budget_by,omitempty"`
	Budget                           *float64    `json:"budget,omitempty"`
	NotifyWhenOverBudget             bool        `json:"notify_when_over_budget"`
	OverBudgetNotificationPercentage float64     `json:"over_budget_notification_percentage,omitempty"`
	OverBudgetNotifiedAt             *Date       `json:"over_budget_notified_at,omitempty"`
	ShowBudgetToAll                  bool        `json:"show_budget_to_all"`
	CreatedAt                        time.Time   `json:"created_at,omitempty"`
	UpdatedAt                        time.Time   `json:"updated_at,omitempty"`
	StartsOn                         Date        `json:"starts_on,omitempty"`
	EndsOn                           Date        `json:"ends_on,omitempty"`
	Estimate                         *float64    `json:"estimate,omitempty"`
	EstimateBy                       string      `json:"estimate_by,omitempty"`
	HintEarliestRecordAt             Date        `json:"hint_earliest_record_at,omitempty"`
	HintLatestRecordAt               Date        `json:"hint_latest_record_at,omitempty"`
	Notes                            string      `json:"notes,omitempty"`
	CostBudget                       *float64    `json:"cost_budget,omitempty"`
	CostBudgetIncludeExpenses        bool        `json:"cost_budget_include_expenses"`
}

type ProjectStub

type ProjectStub struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Code string `json:"code"`
}

type ProjectsResponse

type ProjectsResponse struct {
	PagedResponse
	Projects []*Project `json:"projects"`
}

type Task

type Task struct {
	ID                int64     `json:"id"`
	Name              string    `json:"name"`
	BillableByDefault bool      `json:"billable_by_default"`
	Deactivated       bool      `json:"deactivated"`
	DefaultHourlyRate float64   `json:"default_hourly_rate"`
	IsDefault         bool      `json:"is_default"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
}

type TaskAssignment

type TaskAssignment struct {
	ID         int64     `json:"id,omitempty"`
	Task       TaskStub  `json:"task,omitempty"`
	Billable   bool      `json:"billable"`
	IsActive   bool      `json:"is_active"`
	Budget     *float64  `json:"budget"`
	HourlyRate *float64  `json:"hourly_rate"`
	UpdatedAt  time.Time `json:"updated_at"`
	CreatedAt  time.Time `json:"created_at"`
}

type TaskAssignmentsResponse

type TaskAssignmentsResponse struct {
	TaskAssignments []*TaskAssignment `json:"task_assignments"`

	PerPage      int64  `json:"per_page"`
	TotalPages   int64  `json:"total_pages"`
	TotalEntries int64  `json:"total_entries"`
	NextPage     *int64 `json:"next_page"`
	PreviousPage *int64 `json:"previous_page"`
	Page         int64  `json:"page"`
}

type TaskStub

type TaskStub struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type TasksResponse

type TasksResponse struct {
	PagedResponse
	Tasks []*Task `json:"tasks"`
}

type TimeEntriesResponse

type TimeEntriesResponse struct {
	PagedResponse
	TimeEntries []*TimeEntry `json:"time_entries"`
}

type TimeEntry

type TimeEntry struct {
	ID             int64        `json:"id"`
	SpentDate      Date         `json:"spent_date"`
	User           *UserStub    `json:"user,omitempty"`
	Client         *ClientStub  `json:"client,omitempty"`
	Project        *ProjectStub `json:"project,omitempty"`
	Task           *TaskStub    `json:"task,omitempty"`
	HoursWithTimer float64      `json:"hours_with_timer"`
	Hours          float64      `json:"hours"`
	Notes          string       `json:"notes"`
	CreatedAt      time.Time    `json:"created_at"`
	UpdatedAt      time.Time    `json:"updated_at"`
	IsLocked       bool         `json:"is_locked"`
	LockedReason   string       `json:"locked_reason"`
	IsClosed       bool         `json:"is_closed"`
	IsBilled       bool         `json:"is_billed"`
	TimerStartedAt *time.Time   `json:"timer_started_at"`
	StartedTime    string       `json:"started_time"`
	EndedTime      string       `json:"ended_time"`
	IsRunning      bool         `json:"is_running"`
	IsBillable     bool         `json:"billable"`
	IsBudgeted     bool         `json:"budgeted"`
	BillableRate   float64      `json:"billable_rate"`
	CostRate       float64      `json:"cost_rate"`
}

type User

type User struct {
	ID                           int64     `json:"id"`
	Email                        string    `json:"email"`
	CreatedAt                    time.Time `json:"created_at"`
	IsAdmin                      bool      `json:"is_admin"`
	FirstName                    string    `json:"first_name"`
	LastName                     string    `json:"last_name"`
	Timezone                     string    `json:"timezone"`
	IsContractor                 bool      `json:"is_contractor"`
	Telephone                    string    `json:"telephone"`
	IsActive                     bool      `json:"is_active"`
	HasAccessToAllFutureProjects bool      `json:"has_access_to_all_future_projects"`
	DefaultHourlyRate            float64   `json:"default_hourly_rate"`
	Department                   string    `json:"department"`
	WantsNewsletter              bool      `json:"wants_newsletter"`
	UpdatedAt                    time.Time `json:"updated_at"`
	CostRate                     float64   `json:"cost_rate"`
	WeeklyCapacity               int64     `json:"weekly_capacity"`
	IdentityAccountID            int64     `json:"identity_account_id"`
	IdentityUserID               int64     `json:"identity_user_id"`
}

type UserAssignment

type UserAssignment struct {
	ID               int64     `json:"id,omitempty"`
	UserID           int64     `json:"user_id"`
	ProjectID        int64     `json:"project_id"`
	Deactivated      bool      `json:"deactivated"`
	HourlyRate       *float64  `json:"hourly_rate"`
	IsProjectManager bool      `json:"is_project_manager"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
	Estimate         float64   `json:"estimate"`
}

type UserAssignmentsResponse

type UserAssignmentsResponse struct {
	UserAssignments []*UserAssignment `json:"user_assignments"`
	PerPage         int64             `json:"per_page"`
	TotalPages      int64             `json:"total_pages"`
	TotalEntries    int64             `json:"total_entries"`
	NextPage        *int64            `json:"next_page"`
	PreviousPage    *int64            `json:"previous_page"`
	Page            int64             `json:"page"`
}

type UserStub

type UserStub struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type UsersResponse

type UsersResponse struct {
	PagedResponse
	Users []*User `json:"users"`
}

Jump to

Keyboard shortcuts

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