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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! Subtenants API
//!
//! This module provides functionality to manage subtenants.
use crate::client::RainClient;
use crate::error::Result;
use crate::models::subtenants::*;
use uuid::Uuid;
impl RainClient {
/// Get all subtenants
///
/// # Returns
///
/// Returns a [`Vec<Subtenant>`] containing the list of subtenants.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
///
/// # #[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 subtenants = client.list_subtenants().await?;
/// println!("Found {} subtenants", subtenants.len());
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn list_subtenants(&self) -> Result<Vec<Subtenant>> {
let path = "/subtenants";
self.get(path).await
}
/// Create a subtenant
///
/// # Arguments
///
/// * `request` - The subtenant creation request
///
/// # Returns
///
/// Returns a [`Subtenant`] containing the created subtenant information.
///
/// # 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::subtenants::CreateSubtenantRequest;
///
/// # #[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 = CreateSubtenantRequest {
/// name: Some("My Subtenant".to_string()),
/// };
/// let subtenant = client.create_subtenant(&request).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn create_subtenant(&self, request: &CreateSubtenantRequest) -> Result<Subtenant> {
let path = "/subtenants";
self.post(path, request).await
}
/// Get a subtenant by its id
///
/// # Arguments
///
/// * `subtenant_id` - The unique identifier of the subtenant
///
/// # Returns
///
/// Returns a [`Subtenant`] containing the subtenant information.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `404` - Subtenant not found
/// - `500` - Internal server error
#[cfg(feature = "async")]
pub async fn get_subtenant(&self, subtenant_id: &Uuid) -> Result<Subtenant> {
let path = format!("/subtenants/{subtenant_id}");
self.get(&path).await
}
/// Update a subtenant
///
/// # Arguments
///
/// * `subtenant_id` - The unique identifier of the subtenant
/// * `request` - The update request
///
/// # Returns
///
/// Returns success (204 No Content) with no response body.
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `404` - Subtenant not found
/// - `500` - Internal server error
#[cfg(feature = "async")]
pub async fn update_subtenant(
&self,
subtenant_id: &Uuid,
request: &UpdateSubtenantRequest,
) -> Result<()> {
let path = format!("/subtenants/{subtenant_id}");
let _: serde_json::Value = self.patch(&path, request).await?;
Ok(())
}
// ============================================================================
// Blocking Methods
// ============================================================================
/// Get all subtenants (blocking)
#[cfg(feature = "sync")]
pub fn list_subtenants_blocking(&self) -> Result<Vec<Subtenant>> {
let path = "/subtenants";
self.get_blocking(path)
}
/// Create a subtenant (blocking)
#[cfg(feature = "sync")]
pub fn create_subtenant_blocking(&self, request: &CreateSubtenantRequest) -> Result<Subtenant> {
let path = "/subtenants";
self.post_blocking(path, request)
}
/// Get a subtenant by its id (blocking)
#[cfg(feature = "sync")]
pub fn get_subtenant_blocking(&self, subtenant_id: &Uuid) -> Result<Subtenant> {
let path = format!("/subtenants/{subtenant_id}");
self.get_blocking(&path)
}
/// Update a subtenant (blocking)
#[cfg(feature = "sync")]
pub fn update_subtenant_blocking(
&self,
subtenant_id: &Uuid,
request: &UpdateSubtenantRequest,
) -> Result<()> {
let path = format!("/subtenants/{subtenant_id}");
let _: serde_json::Value = self.patch_blocking(&path, request)?;
Ok(())
}
}