From 200fb2fa578d23c984d4228733f54d9a1db52565 Mon Sep 17 00:00:00 2001 From: mycognosist Date: Tue, 13 Feb 2024 13:54:16 +0200 Subject: [PATCH] add message and example, return json value from feed and message --- solar_client/Cargo.toml | 1 + solar_client/examples/feed.rs | 9 ++------- solar_client/examples/message.rs | 34 ++++++++++++++++++++++++++++++++ solar_client/src/lib.rs | 6 +++++- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 solar_client/examples/message.rs diff --git a/solar_client/Cargo.toml b/solar_client/Cargo.toml index 1d468a0..c0902cd 100644 --- a/solar_client/Cargo.toml +++ b/solar_client/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" anyhow = "1.0.79" jsonrpc_client = { version = "0.7.1", features = ["macros", "reqwest"] } reqwest = { version = "0.11", default-features = false, features = [ "json" ] } +serde_json = { version = "1", features = ["preserve_order", "arbitrary_precision"] } [dev-dependencies] tokio = { version = "1.36.0", features = [ "macros", "rt-multi-thread" ] } diff --git a/solar_client/examples/feed.rs b/solar_client/examples/feed.rs index 5f524b0..e392ae0 100644 --- a/solar_client/examples/feed.rs +++ b/solar_client/examples/feed.rs @@ -2,7 +2,7 @@ use anyhow::Result; use solar_client::{Client, SolarClient}; const SERVER_ADDR: &str = "http://127.0.0.1:3030"; -const PUB_KEY: &str = "@HEqy940T6uB+T+d9Jaa58aNfRzLx9eRWqkZljBmnkmk=.ed25519"; +const PUB_KEY: &str = "@qK93G/R9R5J2fiqK+kxV72HqqPUcss+rth8rACcYr4s=.ed25519"; #[tokio::main] async fn main() -> Result<()> { @@ -10,12 +10,7 @@ async fn main() -> Result<()> { let feed = client.feed(PUB_KEY).await?; println!("{:#?}", feed); - // [ - // "@dW5ch5miTnxLJDVDtB4ZCvrVxh+S8kGCQIBbd5paLhw=.ed25519", - // "@QIlKZ8DMw9XpjpRZ96RBLpfkLnOUZSqamC6WMddGh3I=.ed25519", - // ... - // "@+rMXLy1md42gvbBq+6l6rp95/drh6QyACO1ZZMMnWI0=.ed25519", - // ] + // TODO Ok(()) } diff --git a/solar_client/examples/message.rs b/solar_client/examples/message.rs new file mode 100644 index 0000000..2ebdae2 --- /dev/null +++ b/solar_client/examples/message.rs @@ -0,0 +1,34 @@ +use anyhow::Result; +use solar_client::{Client, SolarClient}; + +const SERVER_ADDR: &str = "http://127.0.0.1:3030"; +const MSG_REF: &str = "%RCb++/ZhqV1lJNIcoNrk4yM3AfBobT7u8seObZgcEbA=.sha256"; + +#[tokio::main] +async fn main() -> Result<()> { + let client = Client::new(SERVER_ADDR.to_owned())?; + + let message = client.message(MSG_REF).await?; + println!("{:#?}", message); + /* + Object { + "key": String("%RCb++/ZhqV1lJNIcoNrk4yM3AfBobT7u8seObZgcEbA=.sha256"), + "value": Object { + "previous": String("%uhtIvUJeHicd+i/biMI/IlLiLkN4pAYgrVq4CA2rSYA=.sha256"), + "sequence": Number(227), + "author": String("@qK93G/R9R5J2fiqK+kxV72HqqPUcss+rth8rACcYr4s=.ed25519"), + "timestamp": Number(1707730214482), + "hash": String("sha256"), + "content": Object { + "type": String("post"), + "text": String("Testing out the solar JSON-RPC client"), + }, + "signature": String("fsDScOQ3Zbm9sRpcUfKV+Rtf/I70vKpRW3BTIuK3IoZGhYj9Z/pdHDGAWUh+9ixToAevdKltgJZWa7DUWdAuCw==.sig.ed25519"), + }, + "timestamp": Number(1707730214.4837818), + "rts": Null, + } + */ + + Ok(()) +} diff --git a/solar_client/src/lib.rs b/solar_client/src/lib.rs index 045355e..698b8ff 100644 --- a/solar_client/src/lib.rs +++ b/solar_client/src/lib.rs @@ -1,4 +1,6 @@ use anyhow::Result; +// TODO: Should we rather be using a custom kuska type? +use serde_json::Value; #[jsonrpc_client::api] pub trait SolarClient { @@ -14,7 +16,7 @@ pub trait SolarClient { async fn latest_self_description(&self, pub_key: &str) -> String; - async fn feed(&self, pub_key: &str) -> Vec; + async fn feed(&self, pub_key: &str) -> Vec; async fn follows(&self, pub_key: &str) -> Vec; @@ -32,6 +34,8 @@ pub trait SolarClient { async fn latest_self_image(&self, pub_key: &str) -> String; + async fn message(&self, msg_ref: &str) -> Value; + async fn ping(&self) -> String; async fn whoami(&self) -> String;