-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d7ed822
Showing
5 changed files
with
548 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,155 @@ | ||
module.exports = { | ||
"env": { | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true, | ||
"browser": false | ||
}, | ||
"ignorePatterns": [ | ||
"node_modules/" | ||
], | ||
"extends": "eslint:recommended", | ||
"overrides": [ | ||
{ | ||
"env": { | ||
"node": true, | ||
}, | ||
"files": [ | ||
".eslintrc.{js,cjs}" | ||
], | ||
"parserOptions": { | ||
"sourceType": "script" | ||
} | ||
} | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"warn", | ||
"tab" | ||
], | ||
"linebreak-style": [ | ||
"warn", | ||
"windows" | ||
], | ||
"quotes": [ | ||
"warn", | ||
"double" | ||
], | ||
"semi": [ | ||
"warn", | ||
"never" | ||
], | ||
"implicit-arrow-linebreak": [ | ||
"warn", | ||
"beside" | ||
], | ||
"dot-notation": [ | ||
"warn" | ||
], | ||
"no-unused-vars": [ | ||
"warn", | ||
{ "args": "none" } | ||
], | ||
"no-unneeded-ternary": [ | ||
"warn" | ||
], | ||
"no-mixed-operators": [ | ||
"warn" | ||
], | ||
"nonblock-statement-body-position": [ | ||
"warn", | ||
"beside" | ||
], | ||
"spaced-comment": [ | ||
"warn", | ||
"always" | ||
], | ||
"no-multi-spaces": [ | ||
"warn" | ||
], | ||
"space-infix-ops": [ | ||
"warn" | ||
], | ||
"comma-spacing": [ | ||
"warn" | ||
], | ||
"key-spacing": [ | ||
"warn" | ||
], | ||
"space-in-parens": [ | ||
"warn" | ||
], | ||
"array-bracket-spacing": [ | ||
"warn" | ||
], | ||
"object-curly-spacing": [ | ||
"warn", | ||
"always" | ||
], | ||
"no-trailing-spaces": [ | ||
"warn" | ||
], | ||
"comma-style": [ | ||
"warn" | ||
], | ||
"no-array-constructor": [ | ||
"warn" | ||
], | ||
"prefer-template": [ | ||
"warn" | ||
], | ||
"template-curly-spacing": [ | ||
"warn" | ||
], | ||
"no-new-object": [ | ||
"warn" | ||
], | ||
"no-useless-concat": [ | ||
"warn" | ||
], | ||
"no-useless-return": [ | ||
"warn" | ||
], | ||
"no-useless-escape": [ | ||
"warn" | ||
], | ||
"no-useless-constructor": [ | ||
"warn" | ||
], | ||
"default-param-last": [ | ||
"warn" | ||
], | ||
"no-new-func": [ | ||
"warn" | ||
], | ||
"no-dupe-class-members": [ | ||
"warn" | ||
], | ||
"no-duplicate-imports": [ | ||
"warn" | ||
], | ||
"function-paren-newline": [ | ||
"warn", | ||
"multiline" | ||
], | ||
"prefer-arrow-callback": [ | ||
"warn" | ||
], | ||
"arrow-spacing": [ | ||
"warn" | ||
], | ||
"no-empty": [ | ||
"warn", | ||
{ "allowEmptyCatch": true } | ||
], | ||
"no-multiple-empty-lines": [ | ||
"warn", | ||
{ "max": 1 } | ||
], | ||
"no-redeclare": "off", | ||
"no-control-regex": "off", | ||
} | ||
} |
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,3 @@ | ||
pnpm-lock.yaml | ||
package-lock.json | ||
node_modules |
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,79 @@ | ||
# Freebox OS Wrapper | ||
|
||
Une librairie pour faciliter l'utilisation de l'API de [Freebox OS](https://dev.freebox.fr/sdk/os/) (interface pour les boxs françaises de l'opérateur Free). Facilite l'authentification et l'envoi de requêtes. | ||
|
||
|
||
## Pourquoi faire ? | ||
|
||
L'API de Freebox OS est capable d'exécuter de nombreuses actions sur la box, comme la gestion des téléchargements et des fichiers sur le disque interne, ou la gestion des contacts et des appels sur le téléphone fixe. Cependant, l'authentification et la première connexion (register) sont assez complexes. Cette librairie permet de simplifier ces étapes, pour vous offrir une meilleure expérience de développement. | ||
|
||
|
||
## Installation | ||
|
||
> Une version récente de Node.js est requise. Nous n'offrons pas de support pour les versions non LTS, et pour les navigateurs. | ||
```bash | ||
# Avec npm | ||
npm i freebox-wrapper | ||
|
||
# Ou avec pnpm | ||
pnpm i freebox-wrapper | ||
``` | ||
|
||
|
||
## Exemples | ||
|
||
### Register | ||
|
||
Cette étape ne doit être effectuée qu'une seule fois, et permet d'obtenir un `appToken`. C'est une étape obligatoire pour utiliser l'API de Freebox OS. L'écran d'affichage de la Freebox demandera à l'utilisateur de confirmer l'opération. | ||
|
||
```js | ||
var { RegisterFreebox } = require("freebox-wrapper") | ||
|
||
RegisterFreebox({ | ||
showLogs: true, // affiche les logs dans la console, true par défaut | ||
appId: "fbx.example", | ||
appName: "Mon appli", | ||
appVersion: "1.0.0", | ||
deviceName: "Mon ordi" | ||
}).then(console.log) | ||
``` | ||
|
||
### Authentification | ||
|
||
L'étape d'authentification permet d'obtenir un token de session, qui est nécessaire pour effectuer des requêtes à l'API. | ||
|
||
> L'authentification est automatiquement effectuée lors de l'envoi d'une requête si le token de session n'est pas encore disponible, l'utilisation de cette méthode n'est pas obligatoire. | ||
```js | ||
var { FreeboxClient } = require("freebox-wrapper") | ||
|
||
var client = new FreeboxClient({ | ||
verbose: true, // affiche une sortie plus détaillée dans la console, false par défaut | ||
appId: "fbx.example", | ||
appToken: "<obtenu avec RegisterFreebox>", | ||
apiDomain: "<obtenu avec RegisterFreebox>", | ||
httpsPort: "<obtenu avec RegisterFreebox>" | ||
}) | ||
client.authentificate().then(console.log) | ||
``` | ||
|
||
### Requête | ||
|
||
Une fois authentifié, vous pourrez effectuer des requêtes à l'API de Freebox OS. | ||
|
||
```js | ||
var systemInfo = await client.fetch({ | ||
url: "v8/system", | ||
method: "GET", // Peut être omis si GET (valeur par défaut) | ||
parseJson: true // Retourne la réponse parsée en JSON, ou une erreur si la réponse n'est pas du JSON. Si false, retourne la réponse donnée par node-fetch. | ||
}) | ||
console.log(systemInfo) | ||
``` | ||
|
||
> Le header `Content-Type` est automatiquement défini à `application/json` s'il n'est pas déjà défini. | ||
|
||
## Licence | ||
|
||
MIT © [Johan](https://johanstick.fr) |
Oops, something went wrong.