This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from arexio/feature/21
Documentation
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
File renamed without changes