From 1b3cb7522118d711d43ca78d0c5d7e71a5afbf46 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 23 Feb 2019 16:52:52 +0100 Subject: Deserialize stations json data into native rust struct. --- src/api.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/api.rs') diff --git a/src/api.rs b/src/api.rs index f67408d..c31ea8f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -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 { + 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 } } -- cgit v1.2.3