aboutsummaryrefslogtreecommitdiff
path: root/lib/patreon/src
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2020-10-02 18:36:57 -0400
committerGitHub <noreply@github.com>2020-10-02 18:36:57 -0400
commitfa13e57835e487d586024a2e065e8f4b30dc88cd (patch)
treee62623fec8d1f3e376453cb33ad0e42b2019b589 /lib/patreon/src
parenta6ee2e7e36e8e8fac6f7c5f452cd6a0a06790584 (diff)
downloadxesite-fa13e57835e487d586024a2e065e8f4b30dc88cd.tar.xz
xesite-fa13e57835e487d586024a2e065e8f4b30dc88cd.zip
incorporate tracing instead of log (#222)
* incorporate tracing instead of log * fix a test * fix a test
Diffstat (limited to 'lib/patreon/src')
-rw-r--r--lib/patreon/src/lib.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/patreon/src/lib.rs b/lib/patreon/src/lib.rs
index 57e2c02..5e37ad7 100644
--- a/lib/patreon/src/lib.rs
+++ b/lib/patreon/src/lib.rs
@@ -1,6 +1,7 @@
+use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use thiserror::Error;
-use chrono::prelude::*;
+use tracing::{debug, error, instrument};
pub type Campaigns = Vec<Object<Campaign>>;
pub type Pledges = Vec<Object<Pledge>>;
@@ -70,7 +71,7 @@ pub enum Error {
Request(#[from] reqwest::Error),
}
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Credentials {
pub client_id: String,
pub client_secret: String,
@@ -112,6 +113,7 @@ impl Client {
}
}
+ #[instrument(skip(self))]
pub async fn campaign(&self) -> Result<Data<Vec<Object<Campaign>>, ()>> {
let data = self
.cli
@@ -126,11 +128,14 @@ impl Client {
)
.send()
.await?
- .error_for_status()?.text().await?;
- log::debug!("campaign response: {}", data);
+ .error_for_status()?
+ .text()
+ .await?;
+ debug!("campaign response: {}", data);
Ok(serde_json::from_str(&data)?)
}
+ #[instrument(skip(self))]
pub async fn pledges(&self, camp_id: String) -> Result<Vec<Object<User>>> {
let data = self
.cli
@@ -148,8 +153,8 @@ impl Client {
.error_for_status()?
.text()
.await?;
- log::debug!("pledges for {}: {}", camp_id, data);
- let data : Data<Vec<Object<Pledge>>, Object<User>> = serde_json::from_str(&data)?;
+ debug!("pledges for {}: {}", camp_id, data);
+ let data: Data<Vec<Object<Pledge>>, Object<User>> = serde_json::from_str(&data)?;
Ok(data.included.unwrap())
}
}