Skip to main content

web_arena_indigo/
api_key.rs

1//! API key APIs.
2
3use crate::http::HttpClient;
4use crate::{WebArenaIndigoApi, WebArenaIndigoApiError};
5use serde::{Deserialize, Serialize};
6
7pub struct ApiKeyApi<'a> {
8    indigo: &'a WebArenaIndigoApi,
9}
10
11impl<'a> ApiKeyApi<'a> {
12    pub(crate) fn new(api: &'a WebArenaIndigoApi) -> Self {
13        ApiKeyApi { indigo: api }
14    }
15
16    /// `GET /webarenaIndigo/v1/auth/create/apikey`
17    pub async fn create_api_key(&self) -> Result<CreateApiKeyResponse, WebArenaIndigoApiError> {
18        HttpClient::get(
19            self.indigo.throttle(),
20            self.indigo.access_token(),
21            &self
22                .indigo
23                .endpoint("/webarenaIndigo/v1/auth/create/apikey"),
24        )
25        .await
26    }
27
28    /// `GET /webarenaIndigo/v1/auth/apikey`
29    pub async fn api_key_list(&self) -> Result<ApiKeyListResponse, WebArenaIndigoApiError> {
30        HttpClient::get(
31            self.indigo.throttle(),
32            self.indigo.access_token(),
33            &self.indigo.endpoint("/webarenaIndigo/v1/auth/apikey"),
34        )
35        .await
36    }
37
38    /// `DELETE /webarenaIndigo/v1/auth/apikey/{id}`
39    pub async fn destroy_api_key(
40        &self,
41        api_key_id: u32,
42    ) -> Result<DestroyApiKeyResponse, WebArenaIndigoApiError> {
43        HttpClient::delete(
44            self.indigo.throttle(),
45            self.indigo.access_token(),
46            &self
47                .indigo
48                .endpoint(&format!("/webarenaIndigo/v1/auth/apikey/{}", api_key_id)),
49        )
50        .await
51    }
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct CreateApiKeyResponse {
56    #[serde(rename = "apiKey")]
57    pub api_key: String,
58    #[serde(rename = "apiSecret")]
59    pub api_secret: String,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct ApiKeyListResponse {
64    pub success: bool,
65    pub total: u32,
66    #[serde(rename = "accesstokens")]
67    pub api_keys: Vec<ApiKey>,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ApiKey {
72    pub id: u32,
73    #[serde(rename = "apiKey")]
74    pub api_key: String,
75    pub created_at: String,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct DestroyApiKeyResponse {
80    pub success: bool,
81    pub message: String,
82}