Skip to content

Latest commit

 

History

History
227 lines (155 loc) · 6.33 KB

README.md

File metadata and controls

227 lines (155 loc) · 6.33 KB

CircleCI Coverage Status Go Reference Go Report Card

Go client for EmploymentHero REST API

The official EmploymentHero Go client library.

Requirements

  • Go 1.16 or later

Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference stripe-go in a Go program with import:

import (
	"github.com/Thinkei/employmenthero-go"
)

Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the stripe-go module automatically.

Alternatively, you can also explicitly go get the package into a project:

go get -u github.com/Thinkei/employmenthero-go

Documentation

For a conprehensive list of examples, check out the API documentation

For details on all funtionality in this library, check out the Go documentation

Below are a few of simple examples:

Auth

import "github.com/Thinkei/employmenthero-go"

// Create a client instance
c, err := employmenthero.NewClient("clientID", "secretID", "redirectUri", "OAuthHost", "apiHost")
c.SetLog(os.Stdout) // Set log to terminal stdout

// Get Authorization code and then use it to get the EH OAuth2 Access tokens
authroizationCode = "<authorizationCode>"
responseToken, err := client.GetOAuth2Access(ctx, authorizationCode)

// Save the refresh_token to anywhere you want,
// but use it when you call other APIs to get our resources
refreshToken := responseToken.RefreshToken
c.SetRefreshToken(responseToken.RefreshToken)

// call other APIs
organisationsResp, err := client.ListOrganisations(ctx, employmenthero.ListParams{})

if err != nil {
	fmt.Printf("Get Organisation failed - %s", err)
}

fmt.Println(organisationsResp.Data.Items)

List Organisations

response, err := c.ListOrganisations(context.TODO(), ListParams{})
organisations := response.Data.Items

Get Organisation details

response, err := c.GetOrganisation(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx")
organisation := response.Data

List Employees

response, err := c.ListEmployees(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", ListParams{})
employees := response.Data.Items

Get Employee details

response, err := c.GetEmployee(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "90a34ef1-50e4-4930-a9d6-yyyy")
employee := response.Data

List Leave Requests

response, err := c.ListLeaveRequests(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", ListParams{})
leaveRequests := response.Data.Items

Get Leave Request details

response, err := c.GetLeaveRequest(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "90a34ef1-50e4-4930-a9d6-yyyy")
leaveRequest := response.Data

List Timesheet Entries

response, err := c.ListTimesheetEntries(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "-", ListParams{})
timesheetEntries := response.Data.Items

List Employemnt Histories

response, err := c.ListEmploymentHistories(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "xxxxxx-yyyy", ListParams{})
employmentHistories := response.Data.Items

List Emergency Contacts

response, err := c.ListEmergencyContacts(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "xxxx-yyy", ListParams{})
contacts := response.Data.Items

List Teams

response, err := c.ListTeams(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", ListParams{})
teams := response.Data.Items

List Employees by Team

response, err := c.ListEmployeesByTeam(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXXX-YYYY-ZZZZ", ListParams{})
employees := response.Data.Items

List Bank Accounts

response, err := c.ListBankAccounts(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXX-YY-ZZZ", ListParams{})
bankAccounts := response.Data.Items

Get Tax Declaration of 1 Employee

response, err := c.GetTaxDeclaration(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXX-YY-ZZZ", ListParams{})
taxDeclaration := response.Data

Get Superannuation Detail of 1 Employee

response, err := c.GetSuperannuationDetail(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXX-YY-ZZZ", ListParams{})
superannuationDetail := response.Data

List Pay Details

response, err := c.ListPayDetails(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXX-YY-ZZZ", ListParams{})
payDetails := response.Data.Items

List Certification

response, err := c.ListCertifications(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", ListParams{})
certifications := response.Data.Items

List Policies

response, err := c.ListPolicies(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", ListParams{})
policies := response.Data.Items

List Employee Certifications

response, err := c.ListEmployeeCertifications(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXX-YY-ZZZ", ListParams{})
employeeCertifications := response.Data.Items

List Payslips

response, err := c.ListPayslips(context.TODO(), "90a34ef1-50e4-4930-a9d6-xxxx", "XXX-YY-ZZZ", ListParams{})
payslips := response.Data.Items

Development

Pull requests from the community are welcome. If you submit one, please keep the following guidelines in mind:

  1. Code must be go fmt compliant.
  2. Ensure that go test succeeds.

Test

The test suite needs testify's require package to run:

github.com/stretchr/testify/require

Before running the tests, make sure to grab all of the package's dependencies:

go get -t -v

Run all tests:

make test

For any requests, bug or comments, please [open an issue][issues] or [submit a pull request][pulls].