use reqwest::Method;
use serde::Serialize;
use super::path;
use crate::{Client, Record, Request};
#[derive(Debug, Clone, Copy)]
pub struct CustomApi<'a> {
client: &'a Client,
}
impl<'a> CustomApi<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
fn req(&self, method: Method, p: &str, integrated_account_id: &str) -> Request<Record> {
let mut req = self.client.request(method, format!("custom/{}", path(p)));
req.query_ref()
.insert("integrated_account_id", integrated_account_id);
req
}
pub fn get(&self, path: &str, integrated_account_id: &str) -> Request<Record> {
self.req(Method::GET, path, integrated_account_id)
}
pub fn post(
&self,
path: &str,
integrated_account_id: &str,
body: impl Serialize,
) -> Request<Record> {
self.req(Method::POST, path, integrated_account_id)
.body(body)
}
pub fn put(
&self,
path: &str,
integrated_account_id: &str,
body: impl Serialize,
) -> Request<Record> {
self.req(Method::PUT, path, integrated_account_id)
.body(body)
}
pub fn patch(
&self,
path: &str,
integrated_account_id: &str,
body: impl Serialize,
) -> Request<Record> {
self.req(Method::PATCH, path, integrated_account_id)
.body(body)
}
pub fn delete(&self, path: &str, integrated_account_id: &str) -> Request<Record> {
self.req(Method::DELETE, path, integrated_account_id)
}
}