Categorygithub.com/arexio/factorial-go
modulepackage
1.0.0
Repository: https://github.com/arexio/factorial-go.git
Documentation: pkg.go.dev

# README

Factorial API in Go

The aim of this project is to create a full SDK in Go for using the Factorial API. In order to know which services you can consume please refer to the factorial API documentation https://docs.factorialhr.com/reference.

Getting Started

We recomend to follow first of all the getting started guide from factorial https://docs.factorialhr.com/docs. After following this guide you will have created a new OAuth application with the information need to start using this SDK. The next fields are the ones you need in order to start using factorial.

CLIENT_ID="---- Your client ID ----"
CLIENT_SECRET="--- Your client secret ---"
SCOPES="read,write"
REDIRECT_URL="--- Your redirect url, sample (https://7cad0b374498.ngrok.io/auth/factorial/callback) ----"

We provide a Makefile that will allow you to start our different examples, we have three examples:

  • example/employee: this is a short example of how to use our factorial client for retrieve a list of employees
  • example/server: this example will setup and run a server from where you can see how we should handle the OAuth2 process, as well you will find there all the endpoints and you can try them.
  • example/persistence: this example will setup and run a server, in the same we had for the server example, but on this case we use a token repository for persist and refresh our token.

How to use

On the next snippet you can see how we build our client

    // Build the Oauth provider
    provider = factorial.NewOAuthProvider(
		factorial.WithClientID(clientID),
		factorial.WithClientSecret(clientSecret),
		factorial.WithScopes(scopes),
		factorial.WithRedirectURL(redirectURL),
	)

    // Build the factorial client
    cl, err := factorial.New(
		factorial.WithOAuth2Client(provider.Client(token)),
	)
	if err != nil {
		// Track error
	}

    // Use the factorial client for retrieve a list of employees
    employees, err := cl.ListEmployees()
	if err != nil {
		// Track error
	}

The next snippet will show you how to use the factorial client based on our token repository

    // Build the Oauth provider
    provider = factorial.NewOAuthProvider(
		factorial.WithClientID(clientID),
		factorial.WithClientSecret(clientSecret),
		factorial.WithScopes(scopes),
		factorial.WithRedirectURL(redirectURL),
	)

    // You can find the token repository on the repository.go file
    // as well a sample implementation on the persistence sample
	repo = NewMemoryRepository()

    // Build a new OAuth client with a custom Source with repository
    cl, err := factorial.New(
		factorial.WithOAuth2Client(provider.ClientWithSource(
			factorial.NewTokenSource(
				repo,
				uuid.Nil,
				provider,
			),
		)),
	)
	if err != nil {
		// Track error
	}

    // Use the factorial client for retrieve a list of employees
    employees, err := cl.ListEmployees()
	if err != nil {
		// Track error
	}

# Packages

No description provided by the author

# Functions

New builds a Factorial client from the provided accessToken and options.
NewOAuthProvider will create a new OAuthProvider applying the given options.
NewTokenSource will build a new token source with the given criteria.
WithAPIURL sets the API URL for the client.
WithClientID will setup a new clientID for the OAuth2 config.
WithClientSecret will setup a new client secret for the OAuth2 config.
WithOAuth2Client provides a custom http client to the client.
WithRedirectURL will setup the redirect url needed for OAuth2.
WithScopes will setup the scopes that the OAuth2 should ask.

# Structs

Client for the Factorial API.
ClockInRequest will hold the basic information needed for create a new shift (ClockIn) in Factorial.
ClockOutRequest will hold the basic information needed for create a new shift (ClockOut) in Factorial.
CompanyHoliday holds the basic information related with the company holidays in Factorial.
CreateDocumentRequest will hold the basic information needed for create a new document in Factorial.
CreateEmployeeRequest is the object for create an employee.
CreateFolderRequest keeps the information needed for create a new folder.
CreateLeaveRequest keeps the information needed for create a new leave.
CreateLeaveTypeRequest keeps the information needed for create a new leave type.
CreateWebhookRequest keeps the information needed for create a new webhook.
DeleteWebhookRequest keeps the information needed for delete a new webhook.
Document keeps the basic information related with documents in Factorial.
Employee contains all the employee information.
Folder contains all the folder information.
Hiring encapsulates the hiring details of an employee.
HiringVersion keeps the basic information related with hiring versions in Factorial.
Leave contains all the leave information.
LeaveType contains all the leave type information.
Location keeps the basic information related with a location.
OAuthProvider keep the basic information needed for create and keep a connection using OAuth2.
Payslip keeps the basic information related with payslips in Factorial.
Shift keeps the basic information related with shifts in Factorial.
Team type holds the basic information for a team defined from Factorial.
UpdateDocumentRequest will hold the basic information for update a given document.
UpdateEmployeeRequest is the object for update an employee.
UpdateFolderRequest keeps the information needed for update a folder.
UpdateLeaveRequest keeps the information needed for update a leave.
UpdateLeaveTypeRequest keeps the information needed for update a leave type.
UpdateShiftRequest will hold the basic information for update a given shift.
Webhook contains all the webhook information.

# Interfaces

TokenRepository interface will be used for persist our oauth token.

# Type aliases

OAuthProviderOption defines an option for a OAuthProvider.
Option defines an option for a Client.