1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
mod fetch;
mod parse;

use crate::{Error, response::StcpResponse, Code};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, PartialEq)]
pub struct Stop {
   /// STCP Zone, e.g., "MAI1" or "PRT3"
   pub zone: String,

   /// Stop code, e.g., "FRX3" or "TVA1"
   pub code: String,

   /// Stop name, e.g., "FREIXO" or "TV. ALDEIA"
   pub name: String,

   /// Stop's address, e.g. "R.MAURICIO PEREIRA PINTO"
   pub address: String,

   /// Stop index (starting from 1) in the sequence of all stops in a given direction
   pub sequence: u8,
}

type StopsResponse = StcpResponse<Stop>;

pub fn fetch_stops(line: &Code, direction: u8) -> Result<Vec<Stop>, Error> {
   let json = fetch::fetch_stops(&line, direction)?;

   let stops = parse::parse_stops(&json)?;

   Ok(stops.records)
}