use super::WorkersTail;
use crate::framework::endpoint::{EndpointSpec, Method, RequestBody};
use crate::framework::response::ApiSuccess;
use serde::Serialize;
#[derive(Debug)]
pub struct CreateTail<'a> {
pub account_identifier: &'a str,
pub script_name: &'a str,
pub params: CreateTailParams,
}
impl EndpointSpec for CreateTail<'_> {
type JsonResponse = WorkersTail;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::POST
}
fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/tails",
self.account_identifier, self.script_name
)
}
#[inline]
fn body(&self) -> Option<RequestBody> {
if self.params.url.is_some() {
let body = serde_json::to_string(&self.params).unwrap();
Some(RequestBody::Json(body))
} else {
None
}
}
}
#[derive(Serialize, Clone, Debug, Default)]
pub struct CreateTailParams {
pub url: Option<String>,
}