From 019332a6c793fafac7221db88e89a04888267dfd Mon Sep 17 00:00:00 2001 From: Tom Theret Date: Sun, 7 Apr 2024 16:16:27 +0200 Subject: [PATCH] add exemples --- examples/client.js | 11 +++++++++++ examples/getBalance.js | 9 +++++++++ examples/getBookingWeek.js | 13 +++++++++++++ examples/getBookings.js | 13 ------------- examples/getEtablishment.js | 21 +++++++++++++++++++++ examples/getHistory.js | 9 +++++++++ examples/getHost.js | 9 +++++++++ examples/getLatestPayment.js | 9 +++++++++ examples/searchEstablishment.js | 12 ++++++++++++ scripts/tests/client.ts | 4 ++-- 10 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 examples/client.js create mode 100644 examples/getBalance.js create mode 100644 examples/getBookingWeek.js delete mode 100644 examples/getBookings.js create mode 100644 examples/getEtablishment.js create mode 100644 examples/getHistory.js create mode 100644 examples/getHost.js create mode 100644 examples/getLatestPayment.js create mode 100644 examples/searchEstablishment.js diff --git a/examples/client.js b/examples/client.js new file mode 100644 index 0000000..953891c --- /dev/null +++ b/examples/client.js @@ -0,0 +1,11 @@ +const TurboSelf = require('turboself-api') + +async function main() { + let client = await TurboSelf.authenticateWithCredentials({ username: "your_email", password: "your_password" }) + let siblings = await client.getSiblings() + let evening = await client.canBookEvening() + console.log("Number of siblings\x1b[34m » \x1b[1;32m" + siblings.length + "\x1b[0m") + console.log("Can book evening\x1b[34m » \x1b[1;32m" + evening) +} + +main() \ No newline at end of file diff --git a/examples/getBalance.js b/examples/getBalance.js new file mode 100644 index 0000000..2ca4a3c --- /dev/null +++ b/examples/getBalance.js @@ -0,0 +1,9 @@ +const TurboSelf = require('turboself-api') + +async function main() { + let client = await TurboSelf.authenticateWithCredentials({ username: "your_email", password: "your_password" }) + let balance = await client.getBalance() + console.log(balance) +} + +main() \ No newline at end of file diff --git a/examples/getBookingWeek.js b/examples/getBookingWeek.js new file mode 100644 index 0000000..52aa4a0 --- /dev/null +++ b/examples/getBookingWeek.js @@ -0,0 +1,13 @@ +const TurboSelf = require('turboself-api') + +async function main() { + let client = await TurboSelf.authenticateWithCredentials({ username: "your_email", password: "your_password" }) + let weeksAvailable = await client.getBookingWeek() + + for (let week of weeksAvailable.weeksNumber) { + const bookings = await client.getBookingWeek(week) + console.log({ bookings }) + } +} + +main() \ No newline at end of file diff --git a/examples/getBookings.js b/examples/getBookings.js deleted file mode 100644 index d2c796b..0000000 --- a/examples/getBookings.js +++ /dev/null @@ -1,13 +0,0 @@ -const TurboSelf = require('turboself-api') - -async function main() { - let client = await TurboSelf.authTurboselfWithCredentials("your_email", "your_password") - let weeksAvailable = await client.getBooksWeeksAvailable() - - for (let week of weeksAvailable) { - const bookings = await client.getBookings(week) - console.log(bookings[0].jours) - } -} - -main() \ No newline at end of file diff --git a/examples/getEtablishment.js b/examples/getEtablishment.js new file mode 100644 index 0000000..cd21290 --- /dev/null +++ b/examples/getEtablishment.js @@ -0,0 +1,21 @@ +const TurboSelf = require('turboself-api') + +async function main() { + console.log("\x1b[0mFetching etablishments ID 287\x1b[0m") + const search = await TurboSelf.getEtablishment(287) + console.log("Name\x1b[34m » \x1b[1;32m" + search.name + " \x1b[0m\x1b[0m") + console.log("Addresse\x1b[34m » \x1b[1;32m" + search.geolocation?.address1 + " " + search.geolocation?.zipCode + " " + search.geolocation?.city + " \x1b[0m\x1b[0m") + console.log("Version\x1b[34m » \x1b[1;32m" + search.version + " \x1b[0m\x1b[0m") + console.log("Code UAI\x1b[34m » \x1b[1;32m" + search.uai + " \x1b[0m\x1b[0m") + console.log("Code 2P5\x1b[34m » \x1b[1;32m" + search.code + " \x1b[0m\x1b[0m") + console.log("Monnaie\x1b[34m » \x1b[1;32m" + search.currencySymbol + " \x1b[0m\x1b[0m") + console.log("Crédit minimum\x1b[34m » \x1b[1;32m" + search.minimumCredit + " \x1b[0m\x1b[0m") + console.log("Repas minimum\x1b[34m » \x1b[1;32m" + search.minimumMeal + " \x1b[0m\x1b[0m") + console.log("MAC Address\x1b[34m » \x1b[1;32m" + search.macServerAddress + "\x1b[0m\x1b[0m") + console.log(" ") + console.log("Élève peuvent utiliser les QRCode ?\x1b[34m » \x1b[1;32m" + search.permissions?.canStudentUseQrCode + "\x1b[0m\x1b[0m") + console.log("Élève peuvent virer l'historique? \x1b[34m » \x1b[1;32m" + search.permissions?.canStudentSeeHistory + "\x1b[0m\x1b[0m") + console.log(search) +} + +main() \ No newline at end of file diff --git a/examples/getHistory.js b/examples/getHistory.js new file mode 100644 index 0000000..5b01970 --- /dev/null +++ b/examples/getHistory.js @@ -0,0 +1,9 @@ +const TurboSelf = require('turboself-api') + +async function main() { + let client = await TurboSelf.authenticateWithCredentials({ username: "your_email", password: "your_password" }) + let history = await client.getHistory() + console.log(history) +} + +main() \ No newline at end of file diff --git a/examples/getHost.js b/examples/getHost.js new file mode 100644 index 0000000..38d6d4c --- /dev/null +++ b/examples/getHost.js @@ -0,0 +1,9 @@ +const TurboSelf = require('turboself-api') + +async function main() { + let client = await TurboSelf.authenticateWithCredentials({ username: "your_email", password: "your_password" }) + let host = await client.getHost() + console.log(host) +} + +main() \ No newline at end of file diff --git a/examples/getLatestPayment.js b/examples/getLatestPayment.js new file mode 100644 index 0000000..d7b8cb8 --- /dev/null +++ b/examples/getLatestPayment.js @@ -0,0 +1,9 @@ +const TurboSelf = require('turboself-api') + +async function main() { + let client = await TurboSelf.authenticateWithCredentials({ username: "your_email", password: "your_password" }) + let latestPayment = await client.getLatestPayment() + console.log(latestPayment) +} + +main() \ No newline at end of file diff --git a/examples/searchEstablishment.js b/examples/searchEstablishment.js new file mode 100644 index 0000000..8faa3a2 --- /dev/null +++ b/examples/searchEstablishment.js @@ -0,0 +1,12 @@ +const TurboSelf = require('turboself-api') + +async function main() { + console.log("\x1b[0mFetching etablishments in Paris (search results are limited to 20)\x1b[0m") + const search = await TurboSelf.searchEstablishment("Paris", 20) + for (const etab of search) { + console.log("\x1b[34m» \x1b[1;32m" + etab.name + " \x1b[0mis running at version \x1b[1;32m" + etab.version + "\x1b[0m") + } + console.log(search) +} + +main() \ No newline at end of file diff --git a/scripts/tests/client.ts b/scripts/tests/client.ts index 8fa30ce..99bece9 100644 --- a/scripts/tests/client.ts +++ b/scripts/tests/client.ts @@ -2,8 +2,8 @@ import { authenticateWithCredentials, searchEstablishment } from "../../lib" async function main() { const client = await authenticateWithCredentials({ - username: "your email", - password: "your password" + username: "your_email", + password: "your_password" }) const host = await client.getHost()