From e2b9f384bf4033eddf321b5b5020ac4847609b37 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Wed, 18 May 2022 20:17:48 -0400 Subject: [PATCH] look for patreon creds in ~ instead of . Signed-off-by: Xe Iaso --- Cargo.lock | 2 ++ Cargo.toml | 1 + lib/patreon/Cargo.toml | 1 + lib/patreon/src/lib.rs | 9 ++++----- src/app/mod.rs | 5 +++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b487962..2161cf8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1619,6 +1619,7 @@ name = "patreon" version = "0.1.0" dependencies = [ "chrono", + "dirs", "envy", "pretty_env_logger", "reqwest", @@ -3110,6 +3111,7 @@ dependencies = [ "color-eyre", "comrak", "derive_more", + "dirs", "envy", "estimated_read_time", "eyre", diff --git a/Cargo.toml b/Cargo.toml index 490a517..f08f312 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ color-eyre = "0.6" chrono = "0.4" comrak = "0.12.1" derive_more = "0.99" +dirs = "4" envy = "0.4" estimated_read_time = "1" futures = "0.3" diff --git a/lib/patreon/Cargo.toml b/lib/patreon/Cargo.toml index e5907b1..fe6d40c 100644 --- a/lib/patreon/Cargo.toml +++ b/lib/patreon/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] chrono = { version = "0.4", features = ["serde"] } +dirs = "4" reqwest = { version = "0.11", features = ["json"] } serde_json = "1.0" serde = { version = "1", features = ["derive"] } diff --git a/lib/patreon/src/lib.rs b/lib/patreon/src/lib.rs index a2fa63d..4072c94 100644 --- a/lib/patreon/src/lib.rs +++ b/lib/patreon/src/lib.rs @@ -125,16 +125,15 @@ pub struct Links { impl Client { pub fn new() -> Result { - let mut creds = Credentials::default(); - - let p = Path::new(".patreon.json"); + let mut p = dirs::home_dir().unwrap_or(".".into()); + p.push(".patreon.json"); let config = fs::read_to_string(p)?; - creds = serde_json::from_str(&config)?; + let creds = serde_json::from_str(&config)?; Ok(Self { cli: reqwest::Client::new(), base_url: "https://api.patreon.com".into(), - creds: creds, + creds, }) } diff --git a/src/app/mod.rs b/src/app/mod.rs index fe87a88..1109b30 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -4,7 +4,7 @@ use chrono::prelude::*; use serde::Deserialize; use std::{ fs, - path::{Path, PathBuf}, + path::PathBuf, }; use tracing::{error, instrument}; @@ -22,7 +22,8 @@ pub struct Config { #[instrument] async fn patrons() -> Result> { - let p = Path::new(".patreon.json"); + let mut p = dirs::home_dir().unwrap_or(".".into()); + p.push(".patreon.json"); if !p.exists() { info!("{:?} does not exist", p); return Ok(None);