#![doc = "Generated implementation of authenticated SDK resource facades."]
use spiral_contract::call::CallError;
use crate::api::apps::AppsClient;
use crate::api::apps::objects::*;
use crate::auth::TokenSource;
use crate::http::HttpClient;
#[derive(Clone, Debug)]
pub struct AuthenticatedClient {
http: HttpClient,
client: AppsClient,
}
impl AuthenticatedClient {
pub fn new(base: &str) -> Result<Self, CallError<AppsError>> {
Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
}
pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<AppsError>> {
let client =
AppsClient::from_transport(http.base_url().as_str(), http.middleware_client())?;
Ok(Self { http, client })
}
pub fn with_client(mut self, client: reqwest::Client) -> Self {
self.http = self.http.with_client(client);
self.client = self.client.with_transport(self.http.middleware_client());
self
}
pub fn with_token_source(mut self, provider: TokenSource) -> Self {
self.http = self.http.with_token_source(provider);
self
}
pub async fn approve_installation(
&self,
installation_id: String,
) -> Result<Installation, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.approve_installation_http(auth_header, installation_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn create_application(
&self,
project_id: String,
request: ApplicationConfiguration,
) -> Result<Application, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.create_application_http(auth_header, project_id, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn decide_consent(
&self,
challenge: String,
request: ConsentDecision,
) -> Result<ConsentRedirect, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.decide_consent_http(auth_header, challenge, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn delete_application(
&self,
application_id: String,
) -> Result<Application, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.delete_application_http(auth_header, application_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_application(
&self,
application_id: String,
) -> Result<Application, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.get_application_http(auth_header, application_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_consent_request(
&self,
challenge: String,
) -> Result<ConsentRequest, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.get_consent_request_http(auth_header, challenge),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_current_installation(
&self,
) -> Result<InstallationDetails, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.get_current_installation_http(auth_header),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_installable_application(
&self,
application_id: String,
) -> Result<InstallableApplication, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.get_installable_application_http(auth_header, application_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_installation(
&self,
installation_id: String,
) -> Result<Installation, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.get_installation_http(auth_header, installation_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_organization_app_access(
&self,
) -> Result<OrganizationAppAccess, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.get_organization_app_access_http(auth_header),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_self(&self) -> Result<Application, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.get_self_http(auth_header),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_self_installation(
&self,
installation_id: String,
) -> Result<InstallationDetails, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.get_self_installation_http(auth_header, installation_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn get_user_installation(&self) -> Result<UserInstallation, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.get_user_installation_http(auth_header),
)
.await
.map_err(CallError::transport)?
}
pub async fn list_application_installations(
&self,
application_id: String,
request: ListApplicationsRequest,
) -> Result<InstallationPage, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.list_application_installations_http(auth_header, application_id, request),
)
.await
.map_err(CallError::transport)?
}
pub fn list_application_installations_list(
&self,
application_id: String,
request: ListApplicationsRequest,
) -> crate::List<'_, Installation> {
let options = crate::pagination::PageOptions {
token: request.page_token.clone(),
size: request.page_size,
};
crate::List::new(move |options| {
let application_id = ToOwned::to_owned(&application_id);
let mut request = request.clone();
request.page_token = options.token;
request.page_size = options.size;
Box::pin(async move {
let page = self
.list_application_installations(application_id, request)
.await?;
Ok(crate::Page {
items: page.installations,
next_page_token: page.next_page_token,
})
})
})
.with_options(options)
}
pub async fn list_applications(
&self,
project_id: String,
request: ListApplicationsRequest,
) -> Result<ApplicationPage, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.list_applications_http(auth_header, project_id, request),
)
.await
.map_err(CallError::transport)?
}
pub fn list_applications_list(
&self,
project_id: String,
request: ListApplicationsRequest,
) -> crate::List<'_, Application> {
let options = crate::pagination::PageOptions {
token: request.page_token.clone(),
size: request.page_size,
};
crate::List::new(move |options| {
let project_id = ToOwned::to_owned(&project_id);
let mut request = request.clone();
request.page_token = options.token;
request.page_size = options.size;
Box::pin(async move {
let page = self.list_applications(project_id, request).await?;
Ok(crate::Page {
items: page.applications,
next_page_token: page.next_page_token,
})
})
})
.with_options(options)
}
pub async fn list_installation_projects(
&self,
request: ListApplicationsRequest,
) -> Result<InstallationProjectPage, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.list_installation_projects_http(auth_header, request),
)
.await
.map_err(CallError::transport)?
}
pub fn list_installation_projects_list(
&self,
request: ListApplicationsRequest,
) -> crate::List<'_, InstallationProject> {
let options = crate::pagination::PageOptions {
token: request.page_token.clone(),
size: request.page_size,
};
crate::List::new(move |options| {
let mut request = request.clone();
request.page_token = options.token;
request.page_size = options.size;
Box::pin(async move {
let page = self.list_installation_projects(request).await?;
Ok(crate::Page {
items: page.projects,
next_page_token: page.next_page_token,
})
})
})
.with_options(options)
}
pub async fn list_installations(
&self,
request: ListApplicationsRequest,
) -> Result<InstallationPage, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.list_installations_http(auth_header, request),
)
.await
.map_err(CallError::transport)?
}
pub fn list_installations_list(
&self,
request: ListApplicationsRequest,
) -> crate::List<'_, Installation> {
let options = crate::pagination::PageOptions {
token: request.page_token.clone(),
size: request.page_size,
};
crate::List::new(move |options| {
let mut request = request.clone();
request.page_token = options.token;
request.page_size = options.size;
Box::pin(async move {
let page = self.list_installations(request).await?;
Ok(crate::Page {
items: page.installations,
next_page_token: page.next_page_token,
})
})
})
.with_options(options)
}
pub async fn list_scopes(&self) -> Result<ApplicationScopes, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.list_scopes_http(auth_header),
)
.await
.map_err(CallError::transport)?
}
pub async fn list_self_installations(
&self,
request: ListApplicationsRequest,
) -> Result<InstallationPage, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.list_self_installations_http(auth_header, request),
)
.await
.map_err(CallError::transport)?
}
pub fn list_self_installations_list(
&self,
request: ListApplicationsRequest,
) -> crate::List<'_, Installation> {
let options = crate::pagination::PageOptions {
token: request.page_token.clone(),
size: request.page_size,
};
crate::List::new(move |options| {
let mut request = request.clone();
request.page_token = options.token;
request.page_size = options.size;
Box::pin(async move {
let page = self.list_self_installations(request).await?;
Ok(crate::Page {
items: page.installations,
next_page_token: page.next_page_token,
})
})
})
.with_options(options)
}
pub async fn list_user_installation_projects(
&self,
installation_id: String,
request: ListApplicationsRequest,
) -> Result<InstallationProjectPage, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.list_user_installation_projects_http(auth_header, installation_id, request),
)
.await
.map_err(CallError::transport)?
}
pub fn list_user_installation_projects_list(
&self,
installation_id: String,
request: ListApplicationsRequest,
) -> crate::List<'_, InstallationProject> {
let options = crate::pagination::PageOptions {
token: request.page_token.clone(),
size: request.page_size,
};
crate::List::new(move |options| {
let installation_id = ToOwned::to_owned(&installation_id);
let mut request = request.clone();
request.page_token = options.token;
request.page_size = options.size;
Box::pin(async move {
let page = self
.list_user_installation_projects(installation_id, request)
.await?;
Ok(crate::Page {
items: page.projects,
next_page_token: page.next_page_token,
})
})
})
.with_options(options)
}
pub async fn put_application(
&self,
application_id: String,
request: ApplicationConfiguration,
) -> Result<Application, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.put_application_http(auth_header, application_id, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn put_organization_app_access(
&self,
request: OrganizationAppAccess,
) -> Result<OrganizationAppAccess, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.put_organization_app_access_http(auth_header, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn request_installation(
&self,
request: InstallationRequest,
) -> Result<Installation, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.request_installation_http(auth_header, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn review_installation(
&self,
installation_id: String,
request: InstallationReview,
) -> Result<Installation, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.review_installation_http(auth_header, installation_id, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn set_installation_status(
&self,
installation_id: String,
request: InstallationStatusChange,
) -> Result<Installation, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.set_installation_status_http(auth_header, installation_id, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn uninstall(
&self,
installation_id: String,
) -> Result<Installation, CallError<AppsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.uninstall_http(auth_header, installation_id),
)
.await
.map_err(CallError::transport)?
}
}