aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/api.rs8
1 files changed, 8 insertions, 0 deletions
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<Api> {
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<Vec<Station>> {
let response_json = self.client.get(&url_for("stations"))
.send()?