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
use serde::Deserialize;

use crate::{Error, response::StcpResponse, PubCode};

mod fetch;
mod parse;

#[derive(Deserialize, Debug, PartialEq)]
pub struct Destination {
    #[serde(rename = "descr_dir")]
    pub direction_description: String,

    #[serde(rename = "descr")]
    pub description: String,

    #[serde(rename = "dir")]
    pub direction_index: u8,
}

type DestinationsResponse = StcpResponse<Destination>;

pub fn fetch_destinations(line: &PubCode) -> Result<Vec<Destination>, Error> {
    let json = fetch::fetch_destinations(line)?;

    let destinations = parse::parse_destinations(&json)?;

    Ok(destinations.records)
}