From a226e7d888df3342f26e7eaaf1a24d0397d4dbad Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 1 Feb 2020 13:11:33 -0500 Subject: First steps of importer/db/strava integration --- src/strava.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/strava.rs') diff --git a/src/strava.rs b/src/strava.rs index 7df728c..6be5466 100644 --- a/src/strava.rs +++ b/src/strava.rs @@ -8,6 +8,38 @@ use serde::Serialize; use serde_json::from_value; use serde_json::Value; +pub trait StravaApi { + fn get(&self, method: &str, access_token: &str, parasm: &T) -> Result; +} + +pub struct StravaImpl { + client: reqwest::blocking::Client, + base_url: String, +} + +impl StravaImpl { + pub fn new() -> StravaImpl { + StravaImpl { + client: reqwest::blocking::Client::new(), + base_url: "https://www.strava.com/api/v3".to_string(), + } + } +} + +impl StravaApi for StravaImpl { + fn get(&self, method: &str, access_token: &str, + params: &T) -> Result { + let uri = format!("{}{}", self.base_url, method); + let response = self.client.get(&uri) + .bearer_auth(access_token) + .query(params) + .send()?; + info!("StravaApi::get({}) returned {:?}", method, response); + let json = response.json()?; + Ok(json) + } +} + #[derive(Serialize, Deserialize, Debug)] pub struct AthleteSummary { id: i64, -- cgit v1.2.3