Aller au contenu

papillon-turboself-core

Node.js

Node Package Manager

Pour utiliser l'API, vous pouvez utiliser le package npm papillon-turboself-core disponible sur npmjs.com .

Le répo du module est disponible sur Github .

Documentation

Sommaire

Installation

With NPM :

npm install papillon-turboself-core

Gestion des erreurs

Chaque réponse retourner de ce package retourne la même forme de réponse.

{
  error: false, //BOOL : Y'a t'il une erreur
  errorMessage: '', //STRING : Raison de l'erreur (vide si il y a pas d'erreur)
  data: {
    ...
  }
}

Fonctions

login()

Description:
Permet de se connecter au service MyTurboself

Paramètres:

login(username, password)
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    let result = await ts.login('username@mail.com', 'Password1234')
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: {
    token: 'XXXXXXXXXXXX...',
    userId: XXXXXXX,
    etabId: XXXXXX
  }
}

getUserInfo()

Description:
Obtient les informations de l'utilisateur connecté

Paramètres:

getUserInfo()
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.getUserInfo()
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: {
    id: XXXXXX,
    origId: XXXXX,
    type: 0,
    lastName: 'Doe',
    firstName: 'Jonh',
    class: 'CE1',
    method: 'Argent',
    quality: 'TICKET',
    authorization: {
        pay: true,
        book: true,
        cafeteria: false
    },
    lastSync: '20XX-XX-XXTXX:XX:XX.XXXZ',
    disabled: false,
    isPasswordSecure: true,
    cardData: null
  }
}

getHome()

Description:
Obtient l'écran d'acceuil de l'utilisateur connecté

Paramètres:

getHome()
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.getHome()
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: {
    userInfo: {
      id: 'XXXXXXXXXX',
      balance: -10.5,
      estimatedBalance: -150.10,
      estimatedFor: '20XX-XX-XX'
    },
    history: [
      {
        id: XXXXXXXXX,
        name: 'Self',
        date: '20XX-XX-XXTXX:XX:XX.000Z',
        cost: -40.8
      },
      ...
    ]
  }
}

getBooking()

Description:
Obtient les réservations d'une semaine de l'utilisateur connecté

Paramètres:

getBooking(date = new Date())
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.getBooking()
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: {
    weekId: 'XXXXXXXXXXX',
    days: [
      {
        id: 'XXXXXXXXXXX',
        dayNumber: 1, //(1: Lundi, 5: Vendredi)
        booked: true,
        lastSyncBooked: 1,
        canEdit: false,
        label: 'Lundi 11 Déc.',
        date: '11-12-2023'
      },
      ...
    ]
  }
}

setBooking()

Description:
Défini une réservation de l'utilisateur connecté

Paramètres:

setBooking(weekId : Int, dayNumber : Int, booked : Bool)
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.setBooking(XXXXXXXXXXX, 3 (Mercredi), false)
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: {
    id: 'XXXXXXXXXXX',
    dayNumber: 3,
    booked: false
  }
}

getHistory()

Description:
Obtient l'historique complet de l'utilisateur connecté

Paramètres:

getHistory()
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.getHistory()
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: [
    {
      id: XXXXXXXXX,
      name: 'Self',
      cost: -40.70,
      date: '20XX-XX-XXTXX:XX:XX.XXXZ'
    },
    ...
  }
]
}

getBalance()

Description:
Obtient le solde de l'utilisateur connecté

Paramètres:

getBalance()
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.getBalance()
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: {
    id: 'XXXXXXXXXX',
    balance: 10.0,
    estimatedBalance: -45.13,
    estimatedFor: '20XX-XX-XX'
  }
}

canBookEvening()

Description:
Retourne si l'utilisateur connecté peut réserver le soir

Paramètres:

canBookEvening()
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.canBookEvening()
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: false
}

getEtabInfo()

Description:
Obtient les informations de l'établissement de l'utilisateur connecté

Paramètres:

getEtabInfo()
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts. getEtabInfo()
    console.log(result)
}

main()
Retour:
{
  error: false,
  errorMessage: '',
  data: {
    id: XXXX,
    TSid: 1,
    code2p5: XXXX,
    name: 'Lycée/Collège XXX',
    version: 'XXX',
    disabled: false,
    symbol: '€',
    minCreditAdd: 15.5,
    prixDej: 2.87,
    address: {
      line1: '1 Rue Doe Jonh',
      line2: '',
      postalCode: '10000',
      city: 'Ville connu'
    },
    contact: {
      url: 'http://mon.lycee-ou-college.com/',
      email: 'mail@college-lycee.com',
      tel: '0606060606'
    },
    sync: {
      first: '20XX-XX-XXTXX:XX:XX.XXXZ',
      last: '20XX-XX-XXTXX:XX:XX.XXXZ'
    }
  }
}

getLastPayment()

Description:
Obtient le dernier paiments de l'utilisateur connecté

Paramètres:

getLastPayment()
Exemple:
const TurboSelf = require('papillon-turboself-core')
let ts = new TurboSelf();

async function main() {
    await ts.login('username@mail.com', 'Password1234')
    let result = ts.getLastPayment()
    console.log(result)
}

main()
Retour:
{
    error: false,
    errorMessage:'',
    data: {
        id: 0000000,
        etabId: 0000000,
        date: '20XX-XX-XXTXX:XX:XX.XXXZ',
        amount: 20,
        method: 'CB',
        updateDate: '20XX-XX-XXTXX:XX:XX.XXXZ',
        status: 'OK',
        transactionId: 'XXXXXXXXXXXXXX',
        token: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
        message: 'Paiement accepté'
    }
}