Working on getsubset

This commit is contained in:
notplants 2021-12-28 10:24:35 -05:00
parent 807bb8700c
commit 37b4a21899
3 changed files with 17 additions and 4 deletions

View File

@ -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(())

View File

@ -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<Vec<String>, GolgiError> {
pub async fn create_history_stream(&mut self, id: String) -> Result<Vec<Value>, 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
}
}

View File

@ -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<String, GolgiError> {
Ok(std::str::from_utf8(body).unwrap().to_string())
}
// parses a kvt
pub fn feed_res_parse(body: &[u8]) -> Result<Feed, GolgiError> {
Ok(Feed::from_slice(body)?)
}
@ -37,6 +39,13 @@ pub fn string_res_parse(body: &[u8]) -> Result<String, GolgiError> {
Ok(std::str::from_utf8(body).unwrap().to_string())
}
pub fn json_res_parse(body: &[u8]) -> Result<Value, GolgiError> {
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<PublishOut, GolgiError> {
pub fn publish_res_parse(body: &[u8]) -> Result<String, GolgiError> {