diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-02-23 16:10:49 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-02-23 16:10:49 +0100 |
commit | 5c87f3368b174f8e8525f6a522fbaa07e03c98f5 (patch) | |
tree | d438d642cff2c02c86941ba59ec88096b6cf757d /src | |
parent | 6018422c5a4691527784a07154b09cd6d65a08e8 (diff) | |
download | oslobike-5c87f3368b174f8e8525f6a522fbaa07e03c98f5.tar.gz oslobike-5c87f3368b174f8e8525f6a522fbaa07e03c98f5.tar.bz2 oslobike-5c87f3368b174f8e8525f6a522fbaa07e03c98f5.zip |
Fetch stations, dump response json to stdout.
Diffstat (limited to 'src')
-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() } } |