#[macro_export]
macro_rules! api_get {
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
) => {
$(#[$m])*
pub async fn $fn_name(&self, $( $param: $param_t, )*) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
self.esi.
query("GET", $visibility, &path, None, None)
.await
}
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
$( ; $( ($qparam:ident: $qparam_t:ty) => $qreplace:literal ),+ )?
$( ; $( Optional($opt_qparam:ident: $opt_qparam_t:ty) => $opt_qreplace:literal ),+ )?
) => {
$(#[$m])*
pub async fn $fn_name(
&self,
$( $param: $param_t, )*
$($( $qparam: $qparam_t, )*)?
$($( $opt_qparam: Option<$opt_qparam_t>, )*)?
) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
let params = vec![
$($(
($qreplace, $qparam.to_string()),
)+)?
];
$(
let mut params = params; $(
if let Some($opt_qparam) = $opt_qparam {
params.push(($opt_qreplace, $opt_qparam.to_string()));
}
)+
)?
let params: Vec<(&str, &str)> = params.iter().map(|(a, b)| (*a, &**b)).collect();
self.esi.
query("GET", $visibility, &path, Some(¶ms), None)
.await
}
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
; $( $qkind:ident($qparam:ident: $qparam_t:ty) => $qkey:literal ),+ $(,)?
) => {
$crate::__esi_endpoint!(
$(#[$m])*
$fn_name, $op_id, $visibility, $ret_type, "GET",
[ $( ($param: $param_t) => $replace ),* ]
[ $( $qkind($qparam: $qparam_t) => $qkey ),+ ]
[ ]
);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __esi_query_type {
(Required, $t:ty) => { $t };
(Optional, $t:ty) => { Option<$t> };
(Many, $t:ty) => { $t };
(OptionalMany, $t:ty) => { Option<$t> };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __esi_push_query {
($params:ident, Required, $name:ident, $key:literal) => {
$params.push(($key, $name.to_string()));
};
($params:ident, Optional, $name:ident, $key:literal) => {
if let Some(value) = $name {
$params.push(($key, value.to_string()));
}
};
($params:ident, Many, $name:ident, $key:literal) => {
for value in $name.iter() {
$params.push(($key, value.to_string()));
}
};
($params:ident, OptionalMany, $name:ident, $key:literal) => {
if let Some(list) = $name {
for value in list.iter() {
$params.push(($key, value.to_string()));
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __esi_body {
() => {
None::<String>
};
($body:ident) => {
Some(serde_json::to_string($body)?)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __esi_endpoint {
(
$(#[$m:meta])*
$fn_name:ident, $op_id:literal, $visibility:expr, $ret_type:ty, $method:literal,
[ $( ($param:ident: $param_t:ty) => $replace:literal ),* ]
[ $( $qkind:ident($qparam:ident: $qparam_t:ty) => $qkey:literal ),* ]
[ $( $body_param:ident: $body_t:ty )? ]
) => {
$(#[$m])*
#[allow(clippy::vec_init_then_push)]
pub async fn $fn_name(
&self,
$( $param: $param_t, )*
$( $qparam: $crate::__esi_query_type!($qkind, $qparam_t), )*
$( $body_param: $body_t, )?
) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
#[allow(unused_mut)]
let mut params: Vec<(&str, String)> = Vec::new();
$(
$crate::__esi_push_query!(params, $qkind, $qparam, $qkey);
)*
let params: Vec<(&str, &str)> = params.iter().map(|(a, b)| (*a, &**b)).collect();
let body: Option<String> = $crate::__esi_body!($($body_param)?);
self.esi
.query($method, $visibility, &path, Some(¶ms), body.as_deref())
.await
}
};
}
#[macro_export]
macro_rules! api_post {
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*,
$body_param:ident: $param_type:ty,
) => {
$(#[$m])*
pub async fn $fn_name(&self, $( $param: $param_t, )* $body_param: $param_type) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
let body = serde_json::to_string($body_param)?;
self.esi.
query("POST", $visibility, &path, None, Some(&body))
.await
}
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
; Chunked($body_param:ident: $body_t:ty, $max:literal) $(,)?
) => {
$(#[$m])*
#[doc = concat!(stringify!($max), " items per request; longer lists are split into several requests,")]
pub async fn $fn_name(&self, $( $param: $param_t, )* $body_param: $body_t) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
self.esi
.post_chunked($visibility, &path, $body_param, $max)
.await
}
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
; $( $qkind:ident($qparam:ident: $qparam_t:ty) => $qkey:literal ),*
; $body_param:ident: $body_t:ty $(,)?
) => {
$crate::__esi_endpoint!(
$(#[$m])*
$fn_name, $op_id, $visibility, $ret_type, "POST",
[ $( ($param: $param_t) => $replace ),* ]
[ $( $qkind($qparam: $qparam_t) => $qkey ),* ]
[ $body_param: $body_t ]
);
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
; NoBody $(,)?
) => {
$crate::__esi_endpoint!(
$(#[$m])*
$fn_name, $op_id, $visibility, $ret_type, "POST",
[ $( ($param: $param_t) => $replace ),* ]
[ ]
[ ]
);
};
}
#[macro_export]
macro_rules! api_put {
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*,
$body_param:ident: $param_type:ty,
) => {
$(#[$m])*
pub async fn $fn_name(&self, $( $param: $param_t, )* $body_param: $param_type) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
let body = serde_json::to_string($body_param)?;
self.esi.
query("PUT", $visibility, &path, None, Some(&body))
.await
}
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
; $( $qkind:ident($qparam:ident: $qparam_t:ty) => $qkey:literal ),*
; $body_param:ident: $body_t:ty $(,)?
) => {
$crate::__esi_endpoint!(
$(#[$m])*
$fn_name, $op_id, $visibility, $ret_type, "PUT",
[ $( ($param: $param_t) => $replace ),* ]
[ $( $qkind($qparam: $qparam_t) => $qkey ),* ]
[ $body_param: $body_t ]
);
};
}
#[macro_export]
macro_rules! api_delete {
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
) => {
$(#[$m])*
pub async fn $fn_name(&self, $( $param: $param_t, )*) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
self.esi.
query("DELETE", $visibility, &path, None, None)
.await
}
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
$( ; $( ($qparam:ident: $qparam_t:ty) => $qreplace:literal ),+ )?
) => {
$(#[$m])*
pub async fn $fn_name(
&self,
$( $param: $param_t, )*
$($( $qparam: $qparam_t, )*)?
) -> EsiResult<$ret_type> {
let path = self
.esi
.get_endpoint_for_op_id($op_id)?
$(
.replace($replace, &$param.to_string())
)*;
let params = vec![
$($(
($qreplace, $qparam.to_string()),
)+)?
];
let params: Vec<(&str, &str)> = params.iter().map(|(a, b)| (*a, &**b)).collect();
self.esi.
query("DELETE", $visibility, &path, Some(¶ms), None)
.await
}
};
(
$(#[$m:meta])*
$fn_name:ident,
$op_id:literal,
$visibility:expr,
$ret_type:ty,
$( ($param:ident: $param_t:ty) => $replace:literal ),*
; $( $qkind:ident($qparam:ident: $qparam_t:ty) => $qkey:literal ),+ $(,)?
) => {
$crate::__esi_endpoint!(
$(#[$m])*
$fn_name, $op_id, $visibility, $ret_type, "DELETE",
[ $( ($param: $param_t) => $replace ),* ]
[ $( $qkind($qparam: $qparam_t) => $qkey ),+ ]
[ ]
);
};
}