use reqwest::Method;
use serde::Serialize;
use super::seg;
use crate::{Client, Pager, Record, Request};
#[derive(Debug, Clone, Copy)]
pub struct ProxyApi<'a> {
client: &'a Client,
}
impl<'a> ProxyApi<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
fn req(&self, method: Method, path: String, integrated_account_id: &str) -> Request<Record> {
let mut req = self.client.request(method, path);
req.query_ref()
.insert("integrated_account_id", integrated_account_id);
req
}
pub fn list(&self, resource: &str, integrated_account_id: &str) -> Pager<Record> {
let mut pager = self.client.pager(format!("proxy/{}", seg(resource)));
pager
.query_ref()
.insert("integrated_account_id", integrated_account_id);
pager
}
pub fn get(&self, resource: &str, id: &str, integrated_account_id: &str) -> Request<Record> {
let path = format!("proxy/{}/{}", seg(resource), seg(id));
self.req(Method::GET, path, integrated_account_id)
}
pub fn create(
&self,
resource: &str,
integrated_account_id: &str,
body: impl Serialize,
) -> Request<Record> {
let path = format!("proxy/{}", seg(resource));
self.req(Method::POST, path, integrated_account_id)
.body(body)
}
pub fn update(
&self,
resource: &str,
id: &str,
integrated_account_id: &str,
body: impl Serialize,
) -> Request<Record> {
let path = format!("proxy/{}/{}", seg(resource), seg(id));
self.req(Method::PATCH, path, integrated_account_id)
.body(body)
}
pub fn delete(&self, resource: &str, id: &str, integrated_account_id: &str) -> Request<Record> {
let path = format!("proxy/{}/{}", seg(resource), seg(id));
self.req(Method::DELETE, path, integrated_account_id)
}
pub fn custom_method(
&self,
resource: &str,
method: &str,
integrated_account_id: &str,
) -> Request<Record> {
let path = format!("proxy/{}/{}", seg(resource), seg(method));
self.req(Method::POST, path, integrated_account_id)
}
}