implement getSubset call
This commit is contained in:
parent
187d279d7b
commit
feae382ead
|
@ -1,6 +1,6 @@
|
|||
use std::process;
|
||||
|
||||
use kuska_ssb::api::dto::content::TypedMessage;
|
||||
use kuska_ssb::api::dto::content::{SubsetQuery, TypedMessage};
|
||||
|
||||
use golgi::error::GolgiError;
|
||||
use golgi::sbot::Sbot;
|
||||
|
@ -11,6 +11,7 @@ async fn run() -> Result<(), GolgiError> {
|
|||
let id = sbot_client.whoami().await?;
|
||||
println!("{}", id);
|
||||
|
||||
/*
|
||||
let name = TypedMessage::About {
|
||||
about: id,
|
||||
name: Some("golgi".to_string()),
|
||||
|
@ -33,8 +34,18 @@ async fn run() -> Result<(), GolgiError> {
|
|||
let post_msg_ref = sbot_client.publish(post).await?;
|
||||
println!("{}", post_msg_ref);
|
||||
|
||||
let post_msg_ref = sbot_client.publish_description("this is a description").await?;
|
||||
let post_msg_ref = sbot_client
|
||||
.publish_description("this is a description")
|
||||
.await?;
|
||||
println!("description: {}", post_msg_ref);
|
||||
*/
|
||||
|
||||
let query = SubsetQuery::Type {
|
||||
op: "type".to_string(),
|
||||
string: "vote".to_string(),
|
||||
};
|
||||
let query_response = sbot_client.getsubset(query).await?;
|
||||
println!("{}", query_response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
18
src/sbot.rs
18
src/sbot.rs
|
@ -8,7 +8,7 @@ use kuska_ssb::{
|
|||
api::{
|
||||
dto::{
|
||||
//content::{About, Post},
|
||||
content::TypedMessage,
|
||||
content::{SubsetQuery, TypedMessage},
|
||||
CreateHistoryStreamIn,
|
||||
},
|
||||
ApiCaller,
|
||||
|
@ -39,7 +39,6 @@ impl Sbot {
|
|||
/// for the sbot, then retrieve the public key, private key (secret) and identity from the
|
||||
/// `.ssb-go/secret` file. Open a TCP stream to the sbot and perform the secret handshake. If successful, create a box stream and split it into a writer and reader. Return RPC handles to the sbot as part of the `struct` output.
|
||||
pub async fn init(ip_port: Option<String>, net_id: Option<String>) -> Result<Sbot, GolgiError> {
|
||||
|
||||
let address = if ip_port.is_none() {
|
||||
"127.0.0.1:8008".to_string()
|
||||
} else {
|
||||
|
@ -90,6 +89,15 @@ impl Sbot {
|
|||
})
|
||||
}
|
||||
|
||||
/// Call the `partialReplication getSubset` RPC method and return a vector
|
||||
/// of messages as KVTs (key, value, timestamp).
|
||||
// TODO: add args for `descending` and `page` (max number of msgs in response)
|
||||
pub async fn getsubset(&mut self, query: SubsetQuery) -> Result<String, GolgiError> {
|
||||
let req_id = self.client.getsubset_req_send(query).await?;
|
||||
|
||||
utils::get_async(&mut self.rpc_reader, req_id, utils::getsubset_res_parse).await
|
||||
}
|
||||
|
||||
/// Call the `whoami` RPC method and return an `id`.
|
||||
pub async fn whoami(&mut self) -> Result<String, GolgiError> {
|
||||
let req_id = self.client.whoami_req_send().await?;
|
||||
|
@ -118,11 +126,13 @@ impl Sbot {
|
|||
///
|
||||
/// * `text` - A reference to a string slice which represents the text to be published in the post
|
||||
pub async fn publish_post(&mut self, text: &str) -> Result<String, GolgiError> {
|
||||
let msg = TypedMessage::Post{ text: text.to_string(), mentions: None};
|
||||
let msg = TypedMessage::Post {
|
||||
text: text.to_string(),
|
||||
mentions: None,
|
||||
};
|
||||
self.publish(msg).await
|
||||
}
|
||||
|
||||
|
||||
/// Wrapper for publish which constructs and publishes an about description message appropriately from a string.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -10,12 +10,17 @@ use std::fmt::Debug;
|
|||
|
||||
use async_std::io::Read;
|
||||
|
||||
use kuska_ssb::api::dto::{WhoAmIOut};
|
||||
use kuska_ssb::api::dto::WhoAmIOut;
|
||||
use kuska_ssb::feed::Feed;
|
||||
use kuska_ssb::rpc::{RecvMsg, RequestNo, RpcReader};
|
||||
|
||||
use crate::error::GolgiError;
|
||||
|
||||
pub fn getsubset_res_parse(body: &[u8]) -> Result<String, GolgiError> {
|
||||
// TODO: cleanup with proper error handling etc.
|
||||
Ok(std::str::from_utf8(body).unwrap().to_string())
|
||||
}
|
||||
|
||||
pub fn feed_res_parse(body: &[u8]) -> Result<Feed, GolgiError> {
|
||||
Ok(Feed::from_slice(body)?)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue