stcp_scraper/stops/
mod.rs

1mod fetch;
2mod parse;
3
4use crate::{Error, response::StcpResponse, Code};
5use serde::{Deserialize, Serialize};
6
7#[derive(Deserialize, Serialize, Debug, PartialEq)]
8pub struct Stop {
9   /// STCP Zone, e.g., "MAI1" or "PRT3"
10   pub zone: String,
11
12   /// Stop code, e.g., "FRX3" or "TVA1"
13   pub code: String,
14
15   /// Stop name, e.g., "FREIXO" or "TV. ALDEIA"
16   pub name: String,
17
18   /// Stop's address, e.g. "R.MAURICIO PEREIRA PINTO"
19   pub address: String,
20
21   /// Stop index (starting from 1) in the sequence of all stops in a given direction
22   pub sequence: u8,
23}
24
25type StopsResponse = StcpResponse<Stop>;
26
27pub fn fetch_stops(line: &Code, direction: u8) -> Result<Vec<Stop>, Error> {
28   let json = fetch::fetch_stops(&line, direction)?;
29
30   let stops = parse::parse_stops(&json)?;
31
32   Ok(stops.records)
33}