Skip to content

Commit

Permalink
add exemples
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-theret committed Apr 7, 2024
1 parent 5c92b46 commit 019332a
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 15 deletions.
11 changes: 11 additions & 0 deletions examples/client.js
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions examples/getBalance.js
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 13 additions & 0 deletions examples/getBookingWeek.js
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 0 additions & 13 deletions examples/getBookings.js

This file was deleted.

21 changes: 21 additions & 0 deletions examples/getEtablishment.js
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions examples/getHistory.js
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions examples/getHost.js
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions examples/getLatestPayment.js
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions examples/searchEstablishment.js
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 2 additions & 2 deletions scripts/tests/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 019332a

Please sign in to comment.