aboutsummaryrefslogtreecommitdiff
path: root/lib
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
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')
-rw-r--r--lib/patreon/Cargo.toml3
-rw-r--r--lib/patreon/src/lib.rs17
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/patreon/Cargo.toml b/lib/patreon/Cargo.toml
index 47298b5..fc204a4 100644
--- a/lib/patreon/Cargo.toml
+++ b/lib/patreon/Cargo.toml
@@ -12,7 +12,8 @@ reqwest = { version = "0.10", features = ["json"] }
serde_json = "1.0"
serde = { version = "1", features = ["derive"] }
thiserror = "1"
-log = "0"
+tracing = "0.1"
+tracing-futures = "0.2"
[dev-dependencies]
tokio = { version = "0.2", features = ["macros"] }
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())
}
}