add publish api helper functions
This commit is contained in:
parent
d3d7061f50
commit
ccfd73f32a
|
@ -1,4 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
|
api::dto::content::TypedMessage,
|
||||||
feed::Message,
|
feed::Message,
|
||||||
rpc::{Body, BodyType, RequestNo, RpcType, RpcWriter},
|
rpc::{Body, BodyType, RequestNo, RpcType, RpcWriter},
|
||||||
};
|
};
|
||||||
|
@ -10,6 +11,7 @@ const MAX_RPC_BODY_LEN: usize = 65536;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ApiMethod {
|
pub enum ApiMethod {
|
||||||
|
Publish,
|
||||||
WhoAmI,
|
WhoAmI,
|
||||||
Get,
|
Get,
|
||||||
CreateHistoryStream,
|
CreateHistoryStream,
|
||||||
|
@ -23,6 +25,7 @@ impl ApiMethod {
|
||||||
pub fn selector(&self) -> &'static [&'static str] {
|
pub fn selector(&self) -> &'static [&'static str] {
|
||||||
use ApiMethod::*;
|
use ApiMethod::*;
|
||||||
match self {
|
match self {
|
||||||
|
Publish => &["publish"],
|
||||||
WhoAmI => &["whoami"],
|
WhoAmI => &["whoami"],
|
||||||
Get => &["get"],
|
Get => &["get"],
|
||||||
CreateHistoryStream => &["createHistoryStream"],
|
CreateHistoryStream => &["createHistoryStream"],
|
||||||
|
@ -35,6 +38,7 @@ impl ApiMethod {
|
||||||
pub fn from_selector(s: &[&str]) -> Option<Self> {
|
pub fn from_selector(s: &[&str]) -> Option<Self> {
|
||||||
use ApiMethod::*;
|
use ApiMethod::*;
|
||||||
match s {
|
match s {
|
||||||
|
["publish"] => Some(Publish),
|
||||||
["whoami"] => Some(WhoAmI),
|
["whoami"] => Some(WhoAmI),
|
||||||
["get"] => Some(Get),
|
["get"] => Some(Get),
|
||||||
["createHistoryStream"] => Some(CreateHistoryStream),
|
["createHistoryStream"] => Some(CreateHistoryStream),
|
||||||
|
@ -64,6 +68,23 @@ impl<W: Write + Unpin> ApiCaller<W> {
|
||||||
&mut self.rpc
|
&mut self.rpc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send ["publish"] request.
|
||||||
|
pub async fn publish_req_send(&mut self, msg: TypedMessage) -> Result<RequestNo> {
|
||||||
|
let req_no = self
|
||||||
|
.rpc
|
||||||
|
.send_request(ApiMethod::Publish.selector(), RpcType::Async, &msg)
|
||||||
|
.await?;
|
||||||
|
Ok(req_no)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Send ["publish"] response.
|
||||||
|
pub async fn publish_res_send(&mut self, req_no: RequestNo, msg_ref: String) -> Result<()> {
|
||||||
|
Ok(self
|
||||||
|
.rpc
|
||||||
|
.send_response(req_no, RpcType::Async, BodyType::JSON, msg_ref.as_bytes())
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
|
||||||
/// Send ["whoami"] request.
|
/// Send ["whoami"] request.
|
||||||
pub async fn whoami_req_send(&mut self) -> Result<RequestNo> {
|
pub async fn whoami_req_send(&mut self) -> Result<RequestNo> {
|
||||||
let args: [&str; 0] = [];
|
let args: [&str; 0] = [];
|
||||||
|
|
Loading…
Reference in New Issue