diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-02-23 16:52:52 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-02-23 16:52:52 +0100 |
commit | 1b3cb7522118d711d43ca78d0c5d7e71a5afbf46 (patch) | |
tree | ef4b945aec8b2b17d269898a7c8eded0f82a6788 /src/api.rs | |
parent | 5fb4a94d60382cd14a5a00ba3d3245a79d17ecd2 (diff) | |
download | oslobike-1b3cb7522118d711d43ca78d0c5d7e71a5afbf46.tar.gz oslobike-1b3cb7522118d711d43ca78d0c5d7e71a5afbf46.tar.bz2 oslobike-1b3cb7522118d711d43ca78d0c5d7e71a5afbf46.zip |
Deserialize stations json data into native rust struct.
Diffstat (limited to 'src/api.rs')
-rw-r--r-- | src/api.rs | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -17,6 +17,7 @@ */ use reqwest; +use crate::station::{Station, StationContainer}; const API_BASE: &'static str = "https://oslobysykkel.no/api/v1"; @@ -40,9 +41,12 @@ impl Api { Api { client } } - pub fn stations(&self) -> String { - self.client.get(&url_for("stations")) + pub fn stations(&self) -> Vec<Station> { + let response_json = self.client.get(&url_for("stations")) .send().unwrap() - .text().unwrap() + .text().unwrap(); + + let v: StationContainer = serde_json::from_str(&response_json).unwrap(); + v.stations } } |