diff --git a/compose.yml b/compose.yml index 6134641..270565a 100644 --- a/compose.yml +++ b/compose.yml @@ -1,6 +1,6 @@ services: api: - image: andrecosta222/gaps-notifier-api + image: ghcr.io/andrecostaaa/gaps-notifier-api:latest restart: always build: context: . diff --git a/media/schema.png b/media/schema.png new file mode 100644 index 0000000..e9f20f8 Binary files /dev/null and b/media/schema.png differ diff --git a/readme.md b/readme.md index 227a3e5..fe5d298 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,218 @@ # Gaps Notifier API + +## Introduction + +- Gaps Notifier provides notifications to multiple users around [gaps](https://gaps.heig-vd.ch/) + +## [Gaps](https://gaps.heig-vd.ch/) + +- Gaps is an Academical Planning System + +## Gaps Notifier + +- This api is meant to notify users when events happen in gaps + +- This api is run by users for users, which means that it can't notify anyone if no data is fed into it + +- To automatize this data feeding, the [gaps-cli](https://github.com/heig-lherman/gaps-cli) or the [gaps-scraper](https://github.com/AndreCostaaa/gaps-scraper) can be used + +![](./media/schema.png) +_Main communication schema_ + +## Communication Sequence + +### New Event + +1. A new event is detected +2. A POST request is done to the REST API +3. The subscribers to this particular event are notified through webhooks + +## Discord + +- Integration with discord is very easily done since the gaps-notifier-api uses webhooks to notify users of events. Check this stackoverflow [thread](https://stackoverflow.com/questions/75305136/how-to-create-a-function-to-send-messages) + +## Important - Usage Recommendation + +- Since this application relies on information input from users to be useful, we highly recommend using the already hosted instance. This allows you to benefit from the collective contributions of all users, enhancing the utility and value of the application. + +## API + +- This application is currently being hosted by [Lutonite](https://github.com/Lutonite). + +- If you wish to use it, please write me or [Lutonite](https://github.com/Lutonite) an email and we'll gladly create a user for you. + +#### Retrieving an access token + +
+ POST /api/token (Retrieves an access token) + +##### Parameters + +> | name | type | data type | description | +> | ---- | -------- | ----------- | ----------------------- | +> | None | required | object JSON | `{ user_id: }` | + +##### Responses + +> | http code | content-type | response | +> | --------- | ------------------ | ---------------------------------------------------------------------------------------------------------- | +> | `200` | `application/json` | `{"access_token": , "token_type": "Bearer", "expiration_timestamp": }` | +> | `404` | `application/json` | `{"error":"Invalid User"}` | + +##### Example cURL + +> ```javascript +> curl -X POST -H "Content-Type: application/json" -d '{"user_id": }' /api/token +> ``` + +
+ +--- + +#### Subscribing + +
+ POST /api/subscribe (Subscribes to one course) + +##### Parameters + +> | name | type | data type | description | +> | ---- | -------- | ----------- | --------------------------------------------------------------------------------------- | +> | None | required | object JSON | `{"course": , "class": , "webhook_url": "}` | + +##### Responses + +> | http code | content-type | response | +> | --------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------- | +> | `200` | `application/json` | `{"user":{"id":}, "course": , "class": "webhook_url": ` | +> | `400` | `application/json` | `{"error":"Invalid token"}` | +> | `400` | `application/json` | `{"error":"Missing credentials"}` | +> | `422` | `text/plain; charset=utf-8` | `}` | + +##### Example cURL + +> ```javascript +> curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"course": , "class": "}' /subscribe +> ``` + +
+ +
+ POST /api/subscribe/all (Subscribes to every course) + +##### Parameters + +> | name | type | data type | description | +> | ---- | -------- | ----------- | -------------------------------- | +> | None | required | object JSON | `{"webhook_url": }` | + +##### Responses + +> | http code | content-type | response | +> | --------- | --------------------------- | -------------------------------------------------------- | +> | `200` | `application/json` | `{"user":{"id":}, "webhook_url": ` | +> | `400` | `application/json` | `{"error":"Invalid token"}` | +> | `400` | `application/json` | `{"error":"Missing credentials"}` | +> | `422` | `text/plain; charset=utf-8` | `}` | + +##### Example cURL + +> ```javascript +> curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"webhook_url": ""}' /subscribe/all +> ``` + +
+ +--- + +#### Submiting a grade + + + +
+ POST /api/grade (Submits a grade) + +##### Parameters + +> | name | type | data type | description | +> | ---- | -------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------- | +> | None | required | object JSON | `{"name": , "course": , "class": , "class_average": }` | + +##### Responses + +> | http code | content-type | response | +> | --------- | --------------------------- | ------------------------------------------- | +> | `201` | `text/plain; charset=utf-8` | `Grade Created` | +> | `409` | `text/plain; charset=utf-8` | `Grade already exists` | +> | `400` | `application/json` | `{"error":"Invalid token"}` | +> | `400` | `application/json` | `{"error":"Missing credentials"}` | +> | `422` | `text/plain; charset=utf-8` | `}` | + +##### Example cURL + +> ```javascript +> curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"course":, "class":, "name":, "class_average": }' /api/grade +> ``` + +
+ +--- + +### Admin Space + +--- + +#### Create a user + +
+ POST /api/user (Creates a new user) + +##### Parameters + +- No parameters + +##### Responses + +> | http code | content-type | response | +> | --------- | ------------------ | --------------------------------- | +> | `200` | `application/json` | `{"id": }` | +> | `400` | `application/json` | `{"error":"Invalid token"}` | +> | `400` | `application/json` | `{"error":"Missing credentials"}` | +> | `401` | `` | `` | + +##### Example cURL + +> ```javascript +> curl -X POST -H "Authorization: Bearer " /api/user +> ``` + +
+ +--- + +## Code + +- The source code is written in [rust](https://www.rust-lang.org/) using the (axum)[https://docs.rs/axum/latest/axum/] framework + +## Deploying + +### Docker + +- A docker image is available [here](https://github.com/AndreCostaaa/gaps-notifier-api/pkgs/container/gaps-notifier-api) + +### Requirements + +- [redis](https://redis.io/) +- Environnement variables: + +```env +JWT_SECRET +ADMIN_TOKEN +REDIS_URL +``` + +Admin token is the static bearer token for admin usage + +## License + +This application is licensed under the GNU General Public License v3.0. It is open to everyone to use and modify as they wish, in accordance with the license's terms and conditions.