1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Keys API
//!
//! This module provides functionality to manage API keys.
use crate::client::RainClient;
use crate::error::Result;
use crate::models::keys::*;
use uuid::Uuid;
impl RainClient {
/// Create a key
///
/// # Arguments
///
/// * `request` - The key creation request
///
/// # Returns
///
/// Returns a [`Key`] containing the created key information (including the key itself).
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::keys::CreateKeyRequest;
/// use chrono::Utc;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let request = CreateKeyRequest {
/// name: "My API Key".to_string(),
/// expires_at: Utc::now() + chrono::Duration::days(90),
/// };
/// let key = client.create_key(&request).await?;
/// println!("Created key: {}", key.key);
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn create_key(&self, request: &CreateKeyRequest) -> Result<Key> {
let path = "/keys";
self.post(path, request).await
}
/// Delete a key
///
/// # Arguments
///
/// * `key_id` - The unique identifier of the key to delete
///
/// # Returns
///
/// Returns success (204 No Content) with no response body.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `404` - Key not found
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use uuid::Uuid;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let key_id = Uuid::new_v4();
/// client.delete_key(&key_id).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn delete_key(&self, key_id: &Uuid) -> Result<()> {
let path = format!("/keys/{key_id}");
self.delete(&path).await
}
// ============================================================================
// Blocking Methods
// ============================================================================
/// Create a key (blocking)
#[cfg(feature = "sync")]
pub fn create_key_blocking(&self, request: &CreateKeyRequest) -> Result<Key> {
let path = "/keys";
self.post_blocking(path, request)
}
/// Delete a key (blocking)
#[cfg(feature = "sync")]
pub fn delete_key_blocking(&self, key_id: &Uuid) -> Result<()> {
let path = format!("/keys/{key_id}");
self.delete_blocking(&path)
}
}