From f1b68ffc0f539b7782ed5cc593cbebc360fe4791 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 23 Feb 2019 19:19:44 +0100 Subject: Add a tiny bit of documentation. --- src/api.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/api.rs') diff --git a/src/api.rs b/src/api.rs index 826eaf2..d44c2c4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -33,11 +33,18 @@ fn url_for(endpoint: &str) -> String { [API_BASE, endpoint].join("/") } +/// The oslobike::Api struct holds the state for the Api. pub struct Api { client: reqwest::Client, } impl Api { + + /// Create an instance of the API like this: + /// + /// # let my_api_key = String::from("1234"); + /// let api = oslobike::Api::new(my_api_key).expect("An error occured"); + /// pub fn new(api_key: String) -> ApiResult { let mut hdrs = HeaderMap::new(); hdrs.insert("client-identifier", HeaderValue::from_str(&api_key)?); @@ -49,6 +56,7 @@ impl Api { Ok(Api { client }) } + /// Fetch the list of stations and their basic data from the api. pub fn stations(&self) -> ApiResult> { let response_json = self.client.get(&url_for("stations")) .send()? -- cgit v1.2.3