stan-api
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -12,23 +12,11 @@ "use strict"; | ||
* | ||
* Ce module permet de récupérer la liste des lignes et arrêts du réseau ainsi que les prochains passages. | ||
* Ce module permet de récupérer: | ||
* - les prochains passages | ||
* - les lignes | ||
* - les directions | ||
* - les arrêts | ||
* | ||
*/ | ||
class Stan { | ||
httpClient; | ||
/** | ||
* @example ```js | ||
* const { Stan } = require('stan-api') | ||
* | ||
* const usager = new Stan() | ||
* ``` | ||
*/ | ||
constructor() { | ||
this.httpClient = axios_1.default.create({ | ||
baseURL: 'https://www.reseau-stan.com/?type=476', | ||
headers: { | ||
'X-Requested-With': 'XMLHttpRequest' | ||
} | ||
}); | ||
} | ||
/** | ||
* Lister les lignes du réseau de transport | ||
@@ -38,9 +26,8 @@ * @example ```js | ||
* | ||
* const usager = new Stan() | ||
* usager.getLignes().then(lignes => console.log(lignes)) | ||
* Stan.getLignes().then(lignes => console.log(lignes)) | ||
* ``` | ||
* @returns {Promise<Ligne[]>} | ||
*/ | ||
async getLignes() { | ||
const rep = (await this.httpClient.get('https://www.reseau-stan.com/')).data; | ||
static async getLignes() { | ||
const rep = (await Stan.getClient().get('https://www.reseau-stan.com/')).data; | ||
const regex = /data-ligne="(\d+)" data-numlignepublic="([^"]+)" data-osmid="(line[^"+]+)" data-libelle="([^"]+)" value="[^"]+">/g; | ||
@@ -61,2 +48,4 @@ const lignes = []; | ||
* Liste des arrêts d'une ligne | ||
* | ||
* NB: Un arret peut être commun à plusieurs lignes. | ||
* @param {Ligne} ligne Ligne | ||
@@ -66,4 +55,2 @@ * @example ```js | ||
* | ||
* const usager = new Stan() | ||
* | ||
* const ligneT4 = { | ||
@@ -75,8 +62,8 @@ * id: 2332, | ||
* } | ||
* usager.getArrets(ligneT4).then(arrets => console.log(arrets)) | ||
* Stan.getArrets(ligneT4).then(arrets => console.log(arrets)) | ||
* ``` | ||
* @returns {Promise<Arret[]>} | ||
*/ | ||
async getArrets(ligne) { | ||
const rep = (await this.httpClient.request({ | ||
static async getArrets(ligne) { | ||
const rep = (await Stan.getClient().request({ | ||
method: 'POST', | ||
@@ -104,3 +91,3 @@ data: qs_1.default.stringify({ | ||
/** | ||
* Lister les prochains passages d'un arrêt avec le temps d'arrivé estimé | ||
* Lister les prochains passages d'un arrêt avec le temps d'attente estimé | ||
* @param {Arret} arret Arrêt | ||
@@ -110,4 +97,2 @@ * @example ```js | ||
* | ||
* const usager = new Stan() | ||
* | ||
* const arret = { | ||
@@ -123,3 +108,3 @@ * ligne: { | ||
* } | ||
* usager.getProchainsPassages(arret).then(p => { | ||
* Stan.getProchainsPassages(arret).then(p => { | ||
* console.log(`Liste des prochains passages de l'arrêt "${arret.libelle}" de la ligne ${arret.ligne.numlignepublic}: | ||
@@ -139,4 +124,4 @@ * ${p.map(passage => `${passage.direction} - Temps d'attente: ${Math.trunc(passage.temps_min/60)}H${passage.temps_min%60}min`).join('\n')}`) | ||
*/ | ||
async getProchainsPassages(arret) { | ||
const rep = (await this.httpClient.request({ | ||
static async getProchainsPassages(arret) { | ||
const rep = (await Stan.getClient().request({ | ||
method: 'POST', | ||
@@ -180,3 +165,2 @@ data: qs_1.default.stringify({ | ||
* | ||
* const usager = new Stan() | ||
* const ligneT4 = { | ||
@@ -188,8 +172,8 @@ * id: 2332, | ||
* } | ||
* usager.getDirections(ligneT4).then(directions => console.log(directions)) | ||
* Stan.getDirections(ligneT4).then(directions => console.log(directions)) | ||
* ``` | ||
* @returns {Promise<Direction[]>} | ||
*/ | ||
async getDirections(ligne) { | ||
const rep = (await this.httpClient.request({ | ||
static async getDirections(ligne) { | ||
const rep = (await Stan.getClient().request({ | ||
method: 'POST', | ||
@@ -199,3 +183,4 @@ data: qs_1.default.stringify({ | ||
requete_val: { | ||
ligne: ligne.id | ||
ligne: ligne.id, | ||
numlignepublic: ligne.numlignepublic | ||
} | ||
@@ -222,4 +207,4 @@ }) | ||
*/ | ||
async getArretsDirection(direction) { | ||
const rep = (await this.httpClient.request({ | ||
static async getArretsDirection(direction) { | ||
const rep = (await Stan.getClient().request({ | ||
method: 'POST', | ||
@@ -251,3 +236,11 @@ data: qs_1.default.stringify({ | ||
} | ||
static getClient() { | ||
return axios_1.default.create({ | ||
baseURL: 'https://www.reseau-stan.com/?type=476', | ||
headers: { | ||
'X-Requested-With': 'XMLHttpRequest' | ||
} | ||
}); | ||
} | ||
} | ||
exports.Stan = Stan; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "stan-api", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Maël Gangloff", |
109
README.md
<a name="Stan"></a> | ||
## Stan | ||
Support non officiel de l'API du Service de Transport de l'Agglomération Nancéienne (STAN). Ce module permet de récupérer la liste des lignes et arrêts du réseau ainsi que les prochains passages. | ||
Support non officiel de l'API du Service de Transport de l'Agglomération Nancéienne (STAN). | ||
Ce module permet de récupérer: | ||
- les prochains passages | ||
- les lignes | ||
- les directions | ||
- les arrêts | ||
**Kind**: global class | ||
* [Stan](#Stan) | ||
* [.getLignes()](#Stan+getLignes) ⇒ <code>Promise.<Array.<Ligne>></code> | ||
* [.getArrets(ligne)](#Stan+getArrets) ⇒ <code>Promise.<Array.<Arret>></code> | ||
* [.getProchainsPassages(arret)](#Stan+getProchainsPassages) ⇒ <code>Promise.<Array.<Passage>></code> | ||
* [.getDirections(ligne)](#Stan+getDirections) ⇒ <code>Promise.<Array.<Direction>></code> | ||
* [.getArretsDirection(direction)](#Stan+getArretsDirection) ⇒ <code>Promise.<Array.<Arret>></code> | ||
* [.getLignes()](#Stan.getLignes) ⇒ <code>Promise.<Array.<Ligne>></code> | ||
* [.getArrets(ligne)](#Stan.getArrets) ⇒ <code>Promise.<Array.<Arret>></code> | ||
* [.getProchainsPassages(arret)](#Stan.getProchainsPassages) ⇒ <code>Promise.<Array.<Passage>></code> | ||
* [.getDirections(ligne)](#Stan.getDirections) ⇒ <code>Promise.<Array.<Direction>></code> | ||
* [.getArretsDirection(direction)](#Stan.getArretsDirection) ⇒ <code>Promise.<Array.<Arret>></code> | ||
<a name="Stan+getLignes"></a> | ||
<a name="Stan.getLignes"></a> | ||
### stan.getLignes() ⇒ <code>Promise.<Array.<Ligne>></code> | ||
### Stan.getLignes() ⇒ <code>Promise.<Array.<Ligne>></code> | ||
Lister les lignes du réseau de transport | ||
**Kind**: instance method of [<code>Stan</code>](#Stan) | ||
**Kind**: static method of [<code>Stan</code>](#Stan) | ||
**Example** | ||
```js const { Stan } = require('stan-api') const usager = new Stan() usager.getLignes().then(lignes => console.log(lignes)) ``` | ||
<a name="Stan+getArrets"></a> | ||
```js | ||
const { Stan } = require('stan-api') | ||
### stan.getArrets(ligne) ⇒ <code>Promise.<Array.<Arret>></code> | ||
Stan.getLignes().then(lignes => console.log(lignes)) | ||
``` | ||
<a name="Stan.getArrets"></a> | ||
### Stan.getArrets(ligne) ⇒ <code>Promise.<Array.<Arret>></code> | ||
Liste des arrêts d'une ligne | ||
**Kind**: instance method of [<code>Stan</code>](#Stan) | ||
NB: Un arret peut être commun à plusieurs lignes. | ||
**Kind**: static method of [<code>Stan</code>](#Stan) | ||
| Param | Type | Description | | ||
@@ -35,10 +47,20 @@ | --- | --- | --- | | ||
**Example** | ||
```js const { Stan } = require('stan-api') const usager = new Stan() const ligneT4 = { id: 2332, numlignepublic: 'T4', osmid: 'line:GST:4-97', libelle: 'Tempo 4 - Laxou CLB <> Houdemont Porte Sud' } usager.getArrets(ligneT4).then(arrets => console.log(arrets)) ``` | ||
<a name="Stan+getProchainsPassages"></a> | ||
```js | ||
const { Stan } = require('stan-api') | ||
### stan.getProchainsPassages(arret) ⇒ <code>Promise.<Array.<Passage>></code> | ||
Lister les prochains passages d'un arrêt avec le temps d'arrivé estimé | ||
const ligneT4 = { | ||
id: 2332, | ||
numlignepublic: 'T4', | ||
osmid: 'line:GST:4-97', | ||
libelle: 'Tempo 4 - Laxou CLB <> Houdemont Porte Sud' | ||
} | ||
Stan.getArrets(ligneT4).then(arrets => console.log(arrets)) | ||
``` | ||
<a name="Stan.getProchainsPassages"></a> | ||
**Kind**: instance method of [<code>Stan</code>](#Stan) | ||
### Stan.getProchainsPassages(arret) ⇒ <code>Promise.<Array.<Passage>></code> | ||
Lister les prochains passages d'un arrêt avec le temps d'attente estimé | ||
**Kind**: static method of [<code>Stan</code>](#Stan) | ||
| Param | Type | Description | | ||
@@ -49,9 +71,34 @@ | --- | --- | --- | | ||
**Example** | ||
```js const { Stan } = require('stan-api') const usager = new Stan() const arret = { ligne: { id: 2332, numlignepublic: 'T4', osmid: 'line:GST:4-97', libelle: 'Tempo 4 - Laxou CLB <> Houdemont Porte Sud' }, libelle: 'Place Stanislas - Dom Calmet', osmid: 'stop_point:GST:SP:NYPCL1' } usager.getProchainsPassages(arret).then(p => { console.log(`Liste des prochains passages de l'arrêt "${arret.libelle}" de la ligne ${arret.ligne.numlignepublic}: ${p.map(passage => `${passage.direction} - Temps d'attente: ${Math.trunc(passage.temps_min/60)}H${passage.temps_min%60}min`).join('\n')}`) }) ``` ``` Exemple sortie: Liste des prochains passages de l'arrêt "Place Stanislas - Dom Calmet" de la ligne T4: Direction Houdemont Porte Sud - Temps d'attente: 0H1min Direction Houdemont Porte Sud - Temps d'attente: 0H8min Direction Laxou Champ-le-Boeuf - Temps d'attente: 0H1min Direction Laxou Champ-le-Boeuf - Temps d'attente: 0H8min ``` | ||
<a name="Stan+getDirections"></a> | ||
```js | ||
const { Stan } = require('stan-api') | ||
### stan.getDirections(ligne) ⇒ <code>Promise.<Array.<Direction>></code> | ||
const arret = { | ||
ligne: { | ||
id: 2332, | ||
numlignepublic: 'T4', | ||
osmid: 'line:GST:4-97', | ||
libelle: 'Tempo 4 - Laxou CLB <> Houdemont Porte Sud' | ||
}, | ||
libelle: 'Place Stanislas - Dom Calmet', | ||
osmid: 'stop_point:GST:SP:NYPCL1' | ||
} | ||
Stan.getProchainsPassages(arret).then(p => { | ||
console.log(`Liste des prochains passages de l'arrêt "${arret.libelle}" de la ligne ${arret.ligne.numlignepublic}: | ||
${p.map(passage => `${passage.direction} - Temps d'attente: ${Math.trunc(passage.temps_min/60)}H${passage.temps_min%60}min`).join('\n')}`) | ||
}) | ||
``` | ||
``` | ||
Exemple sortie: | ||
Liste des prochains passages de l'arrêt "Place Stanislas - Dom Calmet" de la ligne T4: | ||
Direction Houdemont Porte Sud - Temps d'attente: 0H1min | ||
Direction Houdemont Porte Sud - Temps d'attente: 0H8min | ||
Direction Laxou Champ-le-Boeuf - Temps d'attente: 0H1min | ||
Direction Laxou Champ-le-Boeuf - Temps d'attente: 0H8min | ||
``` | ||
<a name="Stan.getDirections"></a> | ||
### Stan.getDirections(ligne) ⇒ <code>Promise.<Array.<Direction>></code> | ||
Lister les directions d'une ligne | ||
**Kind**: instance method of [<code>Stan</code>](#Stan) | ||
**Kind**: static method of [<code>Stan</code>](#Stan) | ||
@@ -63,9 +110,19 @@ | Param | Type | Description | | ||
**Example** | ||
```js const { Stan } = require('stan-api') const usager = new Stan() const ligneT4 = { id: 2332, numlignepublic: 'T4', osmid: 'line:GST:4-97', libelle: 'Tempo 4 - Laxou CLB <> Houdemont Porte Sud' } usager.getDirections(ligneT4).then(directions => console.log(directions)) ``` | ||
<a name="Stan+getArretsDirection"></a> | ||
```js | ||
const { Stan } = require('stan-api') | ||
### stan.getArretsDirection(direction) ⇒ <code>Promise.<Array.<Arret>></code> | ||
const ligneT4 = { | ||
id: 2332, | ||
numlignepublic: 'T4', | ||
osmid: 'line:GST:4-97', | ||
libelle: 'Tempo 4 - Laxou CLB <> Houdemont Porte Sud' | ||
} | ||
Stan.getDirections(ligneT4).then(directions => console.log(directions)) | ||
``` | ||
<a name="Stan.getArretsDirection"></a> | ||
### Stan.getArretsDirection(direction) ⇒ <code>Promise.<Array.<Arret>></code> | ||
Lister les arrêts sur le chemin d'une direction d'une ligne | ||
**Kind**: instance method of [<code>Stan</code>](#Stan) | ||
**Kind**: static method of [<code>Stan</code>](#Stan) | ||
@@ -72,0 +129,0 @@ | Param | Type | Description | |
@@ -1,2 +0,1 @@ | ||
import { AxiosInstance } from 'axios'; | ||
import { Arret } from './Ligne/Arret'; | ||
@@ -9,16 +8,11 @@ import { Direction } from './Ligne/Direction'; | ||
* | ||
* Ce module permet de récupérer la liste des lignes et arrêts du réseau ainsi que les prochains passages. | ||
* Ce module permet de récupérer: | ||
* - les prochains passages | ||
* - les lignes | ||
* - les directions | ||
* - les arrêts | ||
* | ||
*/ | ||
export declare class Stan { | ||
protected httpClient: AxiosInstance; | ||
/** | ||
* @example ```js | ||
* const { Stan } = require('stan-api') | ||
* | ||
* const usager = new Stan() | ||
* ``` | ||
*/ | ||
constructor(); | ||
/** | ||
* Lister les lignes du réseau de transport | ||
@@ -28,10 +22,11 @@ * @example ```js | ||
* | ||
* const usager = new Stan() | ||
* usager.getLignes().then(lignes => console.log(lignes)) | ||
* Stan.getLignes().then(lignes => console.log(lignes)) | ||
* ``` | ||
* @returns {Promise<Ligne[]>} | ||
*/ | ||
getLignes(): Promise<Ligne[]>; | ||
static getLignes(): Promise<Ligne[]>; | ||
/** | ||
* Liste des arrêts d'une ligne | ||
* | ||
* NB: Un arret peut être commun à plusieurs lignes. | ||
* @param {Ligne} ligne Ligne | ||
@@ -41,4 +36,2 @@ * @example ```js | ||
* | ||
* const usager = new Stan() | ||
* | ||
* const ligneT4 = { | ||
@@ -50,7 +43,7 @@ * id: 2332, | ||
* } | ||
* usager.getArrets(ligneT4).then(arrets => console.log(arrets)) | ||
* Stan.getArrets(ligneT4).then(arrets => console.log(arrets)) | ||
* ``` | ||
* @returns {Promise<Arret[]>} | ||
*/ | ||
getArrets(ligne: Partial<Ligne> & { | ||
static getArrets(ligne: Partial<Ligne> & { | ||
id: number; | ||
@@ -60,3 +53,3 @@ numlignepublic: string; | ||
/** | ||
* Lister les prochains passages d'un arrêt avec le temps d'arrivé estimé | ||
* Lister les prochains passages d'un arrêt avec le temps d'attente estimé | ||
* @param {Arret} arret Arrêt | ||
@@ -66,4 +59,2 @@ * @example ```js | ||
* | ||
* const usager = new Stan() | ||
* | ||
* const arret = { | ||
@@ -79,3 +70,3 @@ * ligne: { | ||
* } | ||
* usager.getProchainsPassages(arret).then(p => { | ||
* Stan.getProchainsPassages(arret).then(p => { | ||
* console.log(`Liste des prochains passages de l'arrêt "${arret.libelle}" de la ligne ${arret.ligne.numlignepublic}: | ||
@@ -95,3 +86,3 @@ * ${p.map(passage => `${passage.direction} - Temps d'attente: ${Math.trunc(passage.temps_min/60)}H${passage.temps_min%60}min`).join('\n')}`) | ||
*/ | ||
getProchainsPassages(arret: Partial<Arret> & { | ||
static getProchainsPassages(arret: Partial<Arret> & { | ||
osmid: string; | ||
@@ -106,3 +97,2 @@ ligne: Partial<Ligne>; | ||
* | ||
* const usager = new Stan() | ||
* const ligneT4 = { | ||
@@ -114,7 +104,7 @@ * id: 2332, | ||
* } | ||
* usager.getDirections(ligneT4).then(directions => console.log(directions)) | ||
* Stan.getDirections(ligneT4).then(directions => console.log(directions)) | ||
* ``` | ||
* @returns {Promise<Direction[]>} | ||
*/ | ||
getDirections(ligne: Partial<Ligne> & { | ||
static getDirections(ligne: Partial<Ligne> & { | ||
id: number; | ||
@@ -128,3 +118,4 @@ numlignepublic: string; | ||
*/ | ||
getArretsDirection(direction: Direction): Promise<Arret[]>; | ||
static getArretsDirection(direction: Direction): Promise<Arret[]>; | ||
private static getClient; | ||
} |
@@ -0,0 +0,0 @@ import { Direction } from './Direction'; |
@@ -0,0 +0,0 @@ import { Ligne } from './Ligne'; |
@@ -0,0 +0,0 @@ export interface Ligne { |
@@ -0,0 +0,0 @@ import { Arret } from './Arret'; |
Sorry, the diff of this file is not supported yet
130
53397
386