openapp_sdk_core/resources/
api_keys.rs1use std::sync::Arc;
4
5use reqwest::Method;
6
7use super::JsonValue;
8use crate::{
9 error::SdkError,
10 transport::{RequestSpec, Transport},
11};
12
13#[derive(Debug, Clone)]
14pub struct ApiKeysClient {
15 transport: Arc<Transport>,
16}
17
18impl ApiKeysClient {
19 pub(crate) fn new(transport: Arc<Transport>) -> Self {
20 Self { transport }
21 }
22
23 pub async fn list(&self) -> Result<Vec<JsonValue>, SdkError> {
25 self.transport
26 .request_json::<(), Vec<JsonValue>>(RequestSpec {
27 method: Method::GET,
28 path: "/api-keys",
29 ..Default::default()
30 })
31 .await
32 }
33
34 pub async fn create(&self, body: &JsonValue) -> Result<JsonValue, SdkError> {
36 self.transport
37 .request_json::<JsonValue, JsonValue>(RequestSpec {
38 method: Method::POST,
39 path: "/api-keys",
40 body: Some(body),
41 ..Default::default()
42 })
43 .await
44 }
45
46 pub async fn update(&self, id: &str, body: &JsonValue) -> Result<JsonValue, SdkError> {
48 let path = format!("/api-keys/{id}");
49 self.transport
50 .request_json::<JsonValue, JsonValue>(RequestSpec {
51 method: Method::PATCH,
52 path: &path,
53 body: Some(body),
54 ..Default::default()
55 })
56 .await
57 }
58
59 pub async fn revoke(&self, id: &str) -> Result<(), SdkError> {
61 let path = format!("/api-keys/{id}");
62 self.transport
63 .request_json::<(), ()>(RequestSpec {
64 method: Method::DELETE,
65 path: &path,
66 ..Default::default()
67 })
68 .await
69 }
70
71 pub async fn restore(&self, id: &str) -> Result<JsonValue, SdkError> {
73 let path = format!("/api-keys/{id}/restore");
74 self.transport
75 .request_json::<(), JsonValue>(RequestSpec {
76 method: Method::POST,
77 path: &path,
78 ..Default::default()
79 })
80 .await
81 }
82
83 pub async fn purge(&self, id: &str) -> Result<(), SdkError> {
85 let path = format!("/api-keys/{id}/purge");
86 self.transport
87 .request_json::<(), ()>(RequestSpec {
88 method: Method::DELETE,
89 path: &path,
90 ..Default::default()
91 })
92 .await
93 }
94}