Skip to content

Commit

Permalink
rust: Move API resources into separate files (#1558)
Browse files Browse the repository at this point in the history
… to prepare for these being replaced by generated files.
  • Loading branch information
svix-jplatte authored Dec 11, 2024
2 parents ff0ccbc + 5fe6735 commit 41088db
Show file tree
Hide file tree
Showing 12 changed files with 1,530 additions and 1,498 deletions.
1,498 changes: 0 additions & 1,498 deletions rust/src/api.rs

This file was deleted.

119 changes: 119 additions & 0 deletions rust/src/api/application.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use super::PostOptions;
use crate::{apis::application_api, error::Result, models::*, Configuration};

#[derive(Default)]
pub struct ApplicationListOptions {
pub iterator: Option<String>,
pub limit: Option<i32>,
pub order: Option<Ordering>,
}

pub struct Application<'a> {
cfg: &'a Configuration,
}

impl<'a> Application<'a> {
pub(super) fn new(cfg: &'a Configuration) -> Self {
Self { cfg }
}

pub async fn list(
&self,
options: Option<ApplicationListOptions>,
) -> Result<ListResponseApplicationOut> {
let ApplicationListOptions {
iterator,
limit,
order,
} = options.unwrap_or_default();
application_api::v1_period_application_period_list(
self.cfg,
application_api::V1PeriodApplicationPeriodListParams {
iterator,
limit,
order,
},
)
.await
}

pub async fn create(
&self,
application_in: ApplicationIn,
options: Option<PostOptions>,
) -> Result<ApplicationOut> {
let PostOptions { idempotency_key } = options.unwrap_or_default();
application_api::v1_period_application_period_create(
self.cfg,
application_api::V1PeriodApplicationPeriodCreateParams {
application_in,
idempotency_key,
get_if_exists: None,
},
)
.await
}

pub async fn get_or_create(
&self,
application_in: ApplicationIn,
options: Option<PostOptions>,
) -> Result<ApplicationOut> {
let PostOptions { idempotency_key } = options.unwrap_or_default();
application_api::v1_period_application_period_create(
self.cfg,
application_api::V1PeriodApplicationPeriodCreateParams {
application_in,
idempotency_key,
get_if_exists: Some(true),
},
)
.await
}

pub async fn get(&self, app_id: String) -> Result<ApplicationOut> {
application_api::v1_period_application_period_get(
self.cfg,
application_api::V1PeriodApplicationPeriodGetParams { app_id },
)
.await
}

pub async fn update(
&self,
app_id: String,
application_in: ApplicationIn,
) -> Result<ApplicationOut> {
application_api::v1_period_application_period_update(
self.cfg,
application_api::V1PeriodApplicationPeriodUpdateParams {
app_id,
application_in,
},
)
.await
}

pub async fn patch(
&self,
app_id: String,
application_patch: ApplicationPatch,
) -> Result<ApplicationOut> {
application_api::v1_period_application_period_patch(
self.cfg,
application_api::V1PeriodApplicationPeriodPatchParams {
app_id,
application_patch,
},
)
.await
}

pub async fn delete(&self, app_id: String) -> Result<()> {
application_api::v1_period_application_period_delete(
self.cfg,
application_api::V1PeriodApplicationPeriodDeleteParams { app_id },
)
.await
}
}
54 changes: 54 additions & 0 deletions rust/src/api/authentication.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use super::PostOptions;
use crate::{apis::authentication_api, error::Result, models::*, Configuration};
pub struct Authentication<'a> {
cfg: &'a Configuration,
}

impl<'a> Authentication<'a> {
pub(super) fn new(cfg: &'a Configuration) -> Self {
Self { cfg }
}

pub async fn dashboard_access(
&self,
app_id: String,
options: Option<PostOptions>,
) -> Result<DashboardAccessOut> {
let options = options.unwrap_or_default();
authentication_api::v1_period_authentication_period_dashboard_access(
self.cfg,
authentication_api::V1PeriodAuthenticationPeriodDashboardAccessParams {
app_id,
idempotency_key: options.idempotency_key,
},
)
.await
}

pub async fn app_portal_access(
&self,
app_id: String,
app_portal_access_in: AppPortalAccessIn,
options: Option<PostOptions>,
) -> Result<AppPortalAccessOut> {
let options = options.unwrap_or_default();
authentication_api::v1_period_authentication_period_app_portal_access(
self.cfg,
authentication_api::V1PeriodAuthenticationPeriodAppPortalAccessParams {
app_id,
app_portal_access_in,
idempotency_key: options.idempotency_key,
},
)
.await
}

pub async fn logout(&self, options: Option<PostOptions>) -> Result<()> {
let PostOptions { idempotency_key } = options.unwrap_or_default();
authentication_api::v1_period_authentication_period_logout(
self.cfg,
authentication_api::V1PeriodAuthenticationPeriodLogoutParams { idempotency_key },
)
.await
}
}
52 changes: 52 additions & 0 deletions rust/src/api/background_task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use crate::{apis::background_tasks_api, error::Result, models::*, Configuration};

#[derive(Default)]
pub struct BackgroundTaskListOptions {
pub iterator: Option<String>,
pub limit: Option<i32>,
pub order: Option<Ordering>,
pub status: Option<BackgroundTaskStatus>,
pub task: Option<BackgroundTaskType>,
}

pub struct BackgroundTask<'a> {
cfg: &'a Configuration,
}

impl<'a> BackgroundTask<'a> {
pub(super) fn new(cfg: &'a Configuration) -> Self {
Self { cfg }
}

pub async fn list(
&self,
options: Option<BackgroundTaskListOptions>,
) -> Result<ListResponseBackgroundTaskOut> {
let BackgroundTaskListOptions {
iterator,
limit,
order,
status,
task,
} = options.unwrap_or_default();
background_tasks_api::list_background_tasks(
self.cfg,
background_tasks_api::ListBackgroundTasksParams {
status,
task,
limit,
iterator,
order,
},
)
.await
}

pub async fn get(&self, task_id: String) -> Result<BackgroundTaskOut> {
background_tasks_api::get_background_task(
self.cfg,
background_tasks_api::GetBackgroundTaskParams { task_id },
)
.await
}
}
Loading

0 comments on commit 41088db

Please sign in to comment.