Skip to content

Commit

Permalink
add message and example, return json value from feed and message
Browse files Browse the repository at this point in the history
  • Loading branch information
mycognosist committed Feb 13, 2024
1 parent 37d5160 commit 200fb2f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions solar_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
9 changes: 2 additions & 7 deletions solar_client/examples/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ 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<()> {
let client = Client::new(SERVER_ADDR.to_owned())?;

let feed = client.feed(PUB_KEY).await?;
println!("{:#?}", feed);
// [
// "@dW5ch5miTnxLJDVDtB4ZCvrVxh+S8kGCQIBbd5paLhw=.ed25519",
// "@QIlKZ8DMw9XpjpRZ96RBLpfkLnOUZSqamC6WMddGh3I=.ed25519",
// ...
// "@+rMXLy1md42gvbBq+6l6rp95/drh6QyACO1ZZMMnWI0=.ed25519",
// ]
// TODO

Ok(())
}
34 changes: 34 additions & 0 deletions solar_client/examples/message.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
6 changes: 5 additions & 1 deletion solar_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<String>;
async fn feed(&self, pub_key: &str) -> Vec<Value>;

async fn follows(&self, pub_key: &str) -> Vec<String>;

Expand All @@ -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;
Expand Down

0 comments on commit 200fb2f

Please sign in to comment.