use serde::Serialize;
use crate::ws::Arg;
#[derive(Debug, Serialize)]
#[non_exhaustive]
pub struct ChannelRequest<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<&'a str>,
pub op: &'a str,
pub args: &'a [Arg],
}
impl<'a> ChannelRequest<'a> {
pub fn subscribe(args: &'a [Arg]) -> Self {
Self {
id: None,
op: "subscribe",
args,
}
}
pub fn unsubscribe(args: &'a [Arg]) -> Self {
Self {
id: None,
op: "unsubscribe",
args,
}
}
pub fn id(mut self, id: &'a str) -> Self {
self.id = Some(id);
self
}
}
#[derive(Debug, Serialize)]
#[non_exhaustive]
pub struct LoginRequest<'a> {
pub op: &'static str,
pub args: [LoginArg<'a>; 1],
}
impl<'a> LoginRequest<'a> {
pub fn new(arg: LoginArg<'a>) -> Self {
Self {
op: "login",
args: [arg],
}
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct LoginArg<'a> {
pub api_key: &'a str,
pub passphrase: &'a str,
pub timestamp: &'a str,
pub sign: String,
}
impl<'a> LoginArg<'a> {
pub fn new(
api_key: &'a str,
passphrase: &'a str,
timestamp: &'a str,
sign: impl Into<String>,
) -> Self {
Self {
api_key,
passphrase,
timestamp,
sign: sign.into(),
}
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct OperationRequest<'a, A> {
pub id: String,
pub op: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub exp_time: Option<String>,
pub args: &'a [A],
}
impl<'a, A> OperationRequest<'a, A> {
pub fn new(id: impl Into<String>, op: impl Into<String>, args: &'a [A]) -> Self {
Self {
id: id.into(),
op: op.into(),
exp_time: None,
args,
}
}
pub fn exp_time(mut self, exp_time: impl Into<String>) -> Self {
self.exp_time = Some(exp_time.into());
self
}
}