use serde_json::json;
use crate::model::*;
use crate::RecurlyClient;
pub struct ListSitesRequest<'a> {
pub(crate) http_client: &'a RecurlyClient,
pub ids: Option<Vec<String>>,
pub limit: Option<i64>,
pub order: Option<String>,
pub sort: Option<String>,
pub state: Option<String>,
}
impl<'a> ListSitesRequest<'a> {
pub async fn send(self) -> anyhow::Result<SiteList> {
let mut r = self.http_client.client.get("/sites");
if let Some(ref unwrapped) = self.ids {
for item in unwrapped {
r = r.push_query("ids[]", &item.to_string());
}
}
if let Some(ref unwrapped) = self.limit {
r = r.push_query("limit", &unwrapped.to_string());
}
if let Some(ref unwrapped) = self.order {
r = r.push_query("order", &unwrapped.to_string());
}
if let Some(ref unwrapped) = self.sort {
r = r.push_query("sort", &unwrapped.to_string());
}
if let Some(ref unwrapped) = self.state {
r = r.push_query("state", &unwrapped.to_string());
}
r = self.http_client.authenticate(r);
let res = r.send().await.unwrap().error_for_status();
match res {
Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
Err(res) => {
let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
Err(anyhow::anyhow!("{:?}", text))
}
}
}
pub fn ids(mut self, ids: impl IntoIterator<Item = impl AsRef<str>>) -> Self {
self.ids = Some(ids.into_iter().map(|s| s.as_ref().to_owned()).collect());
self
}
pub fn limit(mut self, limit: i64) -> Self {
self.limit = Some(limit);
self
}
pub fn order(mut self, order: &str) -> Self {
self.order = Some(order.to_owned());
self
}
pub fn sort(mut self, sort: &str) -> Self {
self.sort = Some(sort.to_owned());
self
}
pub fn state(mut self, state: &str) -> Self {
self.state = Some(state.to_owned());
self
}
}