summaryrefslogtreecommitdiff
path: root/src/strava.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/strava.rs')
-rw-r--r--src/strava.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/strava.rs b/src/strava.rs
index dcd8dc1..df7d2a4 100644
--- a/src/strava.rs
+++ b/src/strava.rs
@@ -1,6 +1,12 @@
use reqwest;
use serde::Deserialize;
use serde::Serialize;
+use chrono::Utc;
+use chrono::DateTime;
+use chrono::serde::ts_seconds;
+use serde_json::Value;
+use serde_json::from_value;
+use crate::error::Error;
#[derive(Serialize, Deserialize, Debug)]
pub struct AthleteSummary {
@@ -12,17 +18,18 @@ pub struct AthleteSummary {
#[derive(Serialize, Deserialize, Debug)]
pub struct Token {
- expires_in: i64,
- refresh_token: String,
- access_token: String,
- athlete: AthleteSummary,
+ #[serde(with = "ts_seconds")]
+ pub expires_at: DateTime<Utc>,
+ pub refresh_token: String,
+ pub access_token: String,
+ pub athlete: AthleteSummary,
}
pub fn exchange_token(
client_id: &str,
client_secret: &str,
code: &str,
-) -> Result<Token, reqwest::Error> {
+) -> Result<Token, Error> {
let client = reqwest::blocking::Client::new();
let params = [
("client_id", client_id),
@@ -31,5 +38,6 @@ pub fn exchange_token(
];
let uri = "https://www.strava.com/oauth/token";
let req = client.post(uri).form(&params);
- req.send().map(|r| r.json())?
+ let json: Value = req.send().map(|r| r.json())??;
+ from_value(json).map_err(From::from)
}