diff options
-rw-r--r-- | src/lib.rs | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -16,15 +16,34 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +use reqwest; + +const API_BASE: &'static str = "https://oslobysykkel.no/api/v1"; + +fn url_for(endpoint: &str) -> String { + [API_BASE, endpoint].join("/") +} + pub struct Api { + api_key: String, + client: reqwest::Client, } impl Api { - pub fn new(_api_key: String) -> Api { - Api { } + pub fn new(api_key: String) -> Api { + let mut hdrs = reqwest::header::HeaderMap::new(); + hdrs.insert("client-identifier", reqwest::header::HeaderValue::from_str(&api_key).unwrap()); + + let client = reqwest::Client::builder() + .default_headers(hdrs) + .build().unwrap(); + + Api { api_key, client } } pub fn stations(&self) -> String { - String::from("Hey, bop - alula!") + self.client.get(&url_for("stations")) + .send().unwrap() + .text().unwrap() } } |