Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Documentation #28

Merged
merged 4 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Run server example. Usage 'make run-server-example'
run-server-example: ; $(info Starting server example...)
go run examples/server/*.go

## Run persistence example. Usage 'make run-persistence-example'
run-persistence-example: ; $(info Starting persistence example...)
go run examples/persistence/*.go
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
# 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
}
```
Binary file removed examples/server/public/factorial_logo.png
Binary file not shown.