diff --git a/examples/ssb-client.rs b/examples/ssb-client.rs index cc879cf..8c09f4f 100644 --- a/examples/ssb-client.rs +++ b/examples/ssb-client.rs @@ -41,13 +41,16 @@ async fn run() -> Result<(), GolgiError> { // println!("description: {}", post_msg_ref); // */ + + let author = "@L/z54cbc8V1kL1/MiBhpEKuN3QJkSoZYNaukny3ghIs=.ed25519".to_string(); + // let query = SubsetQuery::Type { // op: "type".to_string(), // string: "post".to_string(), // }; let query = SubsetQuery::Type { op: "author".to_string(), - string: "@L/z54cbc8V1kL1/MiBhpEKuN3QJkSoZYNaukny3ghIs=.ed25519".to_string(), + string: author, }; let query_response = sbot_client.getsubset(query).await?; println!("{}", query_response); @@ -58,7 +61,7 @@ async fn run() -> Result<(), GolgiError> { // println!("log: {}", log_response); // println!("Calling create_history"); -// let hist_response = sbot_client.create_history_stream("@L/z54cbc8V1kL1/MiBhpEKuN3QJkSoZYNaukny3ghIs=.ed25519".to_string()).await?; +// let hist_response = sbot_client.create_history_stream(author).await?; // println!("hist: {:?}", hist_response); Ok(()) diff --git a/src/sbot.rs b/src/sbot.rs index 85262c3..2228193 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -18,6 +18,7 @@ use kuska_ssb::{ rpc::{RpcReader, RpcWriter}, feed::{Feed, Message} }; +use serde_json::Value; use crate::error::GolgiError; use crate::utils; @@ -171,11 +172,11 @@ impl Sbot { */ /// Call the `createHistoryStream` RPC method and print the output. - pub async fn create_history_stream(&mut self, id: String) -> Result, GolgiError> { + pub async fn create_history_stream(&mut self, id: String) -> Result, GolgiError> { let args = CreateHistoryStreamIn::new(id); let req_id = self.client.create_history_stream_req_send(&args).await?; // TODO: message_res_parse is currently throwing "Failed to serializ JSON slice" // utils::get_async_until_eof(&mut self.rpc_reader, req_id, utils::message_res_parse).await - utils::get_async_until_eof(&mut self.rpc_reader, req_id, utils::string_res_parse).await + utils::get_async_until_eof(&mut self.rpc_reader, req_id, utils::json_res_parse).await } } diff --git a/src/utils.rs b/src/utils.rs index 57cc59e..4dd5b7d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,6 +11,7 @@ use std::fmt::Debug; use async_std::io::Read; use kuska_ssb::api::dto::WhoAmIOut; +use serde_json::Value; use kuska_ssb::feed::{Feed, Message}; use kuska_ssb::rpc::{RecvMsg, RequestNo, RpcReader}; @@ -21,6 +22,7 @@ pub fn getsubset_res_parse(body: &[u8]) -> Result { Ok(std::str::from_utf8(body).unwrap().to_string()) } +// parses a kvt pub fn feed_res_parse(body: &[u8]) -> Result { Ok(Feed::from_slice(body)?) } @@ -37,6 +39,13 @@ pub fn string_res_parse(body: &[u8]) -> Result { Ok(std::str::from_utf8(body).unwrap().to_string()) } +pub fn json_res_parse(body: &[u8]) -> Result { + let content = std::str::from_utf8(&body).unwrap().to_string(); + println!("content: {:?}", content); + let message: Value = serde_json::from_slice(body)?; + Ok(message) +} + //pub fn publish_res_parse(body: &[u8]) -> Result { pub fn publish_res_parse(body: &[u8]) -> Result {