summary refs log tree commit diff
path: root/src/micropub.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/micropub.rs')
-rw-r--r--src/micropub.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/micropub.rs b/src/micropub.rs
index e855459..dbd8f9a 100644
--- a/src/micropub.rs
+++ b/src/micropub.rs
@@ -6,7 +6,7 @@ pub struct Client {
     micropub: String,
     access_token: String,
 
-    //http: soup::Session,
+    http: soup::Session,
 }
 
 #[derive(Debug, thiserror::Error)]
@@ -22,12 +22,12 @@ pub enum Error {
 }
 
 impl Client {
-    pub fn new(uri: glib::Uri, token: String) -> Self {
+    pub fn new(http: soup::Session, uri: glib::Uri, token: String) -> Self {
         Self {
             micropub: uri.to_string(),
             access_token: token,
 
-            //http: soup::Session::new()
+            http,
         }
     }
 
@@ -42,8 +42,7 @@ impl Client {
         // TODO: create a SoupAuth subclass that allows pasting in a token
         headers.append("Authorization", &format!("Bearer {}", self.access_token));
 
-        let http = soup::Session::new();
-        let body = http.send_and_read_future(&exch, glib::Priority::DEFAULT).await?;
+        let body = self.http.send_and_read_future(&exch, glib::Priority::DEFAULT).await?;
 
         Ok(serde_json::from_slice(&body)?)
     }
@@ -58,8 +57,7 @@ impl Client {
             Some(&glib::Bytes::from_owned(serde_json::to_vec(&post).unwrap()))
         );
 
-        let http = soup::Session::new();
-        let body = http.send_and_read_future(&exch, glib::Priority::DEFAULT).await?;
+        let body = self.http.send_and_read_future(&exch, glib::Priority::DEFAULT).await?;
 
         match exch.status() {
             soup::Status::Created | soup::Status::Accepted => {