use crate::FluentRequest;
use serde::{Serialize, Deserialize};
use httpclient::InMemoryResponseExt;
use crate::model::{CountryCode, InstitutionsSearchRequestOptions, Products};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InstitutionsSearchRequest {
pub country_codes: Vec<CountryCode>,
pub options: Option<InstitutionsSearchRequestOptions>,
pub products: Option<Vec<Products>>,
pub query: String,
}
impl FluentRequest<'_, InstitutionsSearchRequest> {
pub fn options(mut self, options: InstitutionsSearchRequestOptions) -> Self {
self.params.options = Some(options);
self
}
pub fn products(mut self, products: Vec<Products>) -> Self {
self.params.products = Some(products);
self
}
}
impl<'a> ::std::future::IntoFuture for FluentRequest<'a, InstitutionsSearchRequest> {
type Output = httpclient::InMemoryResult<crate::model::InstitutionsSearchResponse>;
type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
let url = "/institutions/search";
let mut r = self.client.client.post(url);
r = r
.json(
serde_json::json!({ "country_codes" : self.params.country_codes }),
);
if let Some(ref unwrapped) = self.params.options {
r = r.json(serde_json::json!({ "options" : unwrapped }));
}
if let Some(ref unwrapped) = self.params.products {
r = r.json(serde_json::json!({ "products" : unwrapped }));
}
r = r.json(serde_json::json!({ "query" : self.params.query }));
r = self.client.authenticate(r);
let res = r.await?;
res.json().map_err(Into::into)
})
}
}
impl crate::PlaidClient {
pub fn institutions_search(
&self,
country_codes: Vec<CountryCode>,
query: &str,
) -> FluentRequest<'_, InstitutionsSearchRequest> {
FluentRequest {
client: self,
params: InstitutionsSearchRequest {
country_codes,
options: None,
products: None,
query: query.to_owned(),
},
}
}
}