ory_client/apis/
events_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateEventStreamError {
22 Status400(models::ErrorGeneric),
23 Status403(models::ErrorGeneric),
24 Status409(models::ErrorGeneric),
25 DefaultResponse(models::ErrorGeneric),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteEventStreamError {
33 Status400(models::ErrorGeneric),
34 Status403(models::ErrorGeneric),
35 Status409(models::ErrorGeneric),
36 DefaultResponse(models::ErrorGeneric),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ListEventStreamsError {
44 Status400(models::ErrorGeneric),
45 Status403(models::ErrorGeneric),
46 DefaultResponse(models::ErrorGeneric),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum SetEventStreamError {
54 Status400(models::ErrorGeneric),
55 Status403(models::ErrorGeneric),
56 Status409(models::ErrorGeneric),
57 DefaultResponse(models::ErrorGeneric),
58 UnknownValue(serde_json::Value),
59}
60
61
62pub async fn create_event_stream(configuration: &configuration::Configuration, project_id: &str, create_event_stream_body: models::CreateEventStreamBody) -> Result<models::EventStream, Error<CreateEventStreamError>> {
63 let p_project_id = project_id;
65 let p_create_event_stream_body = create_event_stream_body;
66
67 let uri_str = format!("{}/projects/{project_id}/eventstreams", configuration.base_path, project_id=crate::apis::urlencode(p_project_id));
68 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
69
70 if let Some(ref user_agent) = configuration.user_agent {
71 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
72 }
73 if let Some(ref token) = configuration.bearer_access_token {
74 req_builder = req_builder.bearer_auth(token.to_owned());
75 };
76 req_builder = req_builder.json(&p_create_event_stream_body);
77
78 let req = req_builder.build()?;
79 let resp = configuration.client.execute(req).await?;
80
81 let status = resp.status();
82 let content_type = resp
83 .headers()
84 .get("content-type")
85 .and_then(|v| v.to_str().ok())
86 .unwrap_or("application/octet-stream");
87 let content_type = super::ContentType::from(content_type);
88
89 if !status.is_client_error() && !status.is_server_error() {
90 let content = resp.text().await?;
91 match content_type {
92 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
93 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EventStream`"))),
94 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EventStream`")))),
95 }
96 } else {
97 let content = resp.text().await?;
98 let entity: Option<CreateEventStreamError> = serde_json::from_str(&content).ok();
99 Err(Error::ResponseError(ResponseContent { status, content, entity }))
100 }
101}
102
103pub async fn delete_event_stream(configuration: &configuration::Configuration, project_id: &str, event_stream_id: &str) -> Result<(), Error<DeleteEventStreamError>> {
105 let p_project_id = project_id;
107 let p_event_stream_id = event_stream_id;
108
109 let uri_str = format!("{}/projects/{project_id}/eventstreams/{event_stream_id}", configuration.base_path, project_id=crate::apis::urlencode(p_project_id), event_stream_id=crate::apis::urlencode(p_event_stream_id));
110 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
111
112 if let Some(ref user_agent) = configuration.user_agent {
113 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114 }
115 if let Some(ref token) = configuration.bearer_access_token {
116 req_builder = req_builder.bearer_auth(token.to_owned());
117 };
118
119 let req = req_builder.build()?;
120 let resp = configuration.client.execute(req).await?;
121
122 let status = resp.status();
123
124 if !status.is_client_error() && !status.is_server_error() {
125 Ok(())
126 } else {
127 let content = resp.text().await?;
128 let entity: Option<DeleteEventStreamError> = serde_json::from_str(&content).ok();
129 Err(Error::ResponseError(ResponseContent { status, content, entity }))
130 }
131}
132
133pub async fn list_event_streams(configuration: &configuration::Configuration, project_id: &str) -> Result<models::ListEventStreams, Error<ListEventStreamsError>> {
134 let p_project_id = project_id;
136
137 let uri_str = format!("{}/projects/{project_id}/eventstreams", configuration.base_path, project_id=crate::apis::urlencode(p_project_id));
138 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140 if let Some(ref user_agent) = configuration.user_agent {
141 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142 }
143 if let Some(ref token) = configuration.bearer_access_token {
144 req_builder = req_builder.bearer_auth(token.to_owned());
145 };
146
147 let req = req_builder.build()?;
148 let resp = configuration.client.execute(req).await?;
149
150 let status = resp.status();
151 let content_type = resp
152 .headers()
153 .get("content-type")
154 .and_then(|v| v.to_str().ok())
155 .unwrap_or("application/octet-stream");
156 let content_type = super::ContentType::from(content_type);
157
158 if !status.is_client_error() && !status.is_server_error() {
159 let content = resp.text().await?;
160 match content_type {
161 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListEventStreams`"))),
163 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListEventStreams`")))),
164 }
165 } else {
166 let content = resp.text().await?;
167 let entity: Option<ListEventStreamsError> = serde_json::from_str(&content).ok();
168 Err(Error::ResponseError(ResponseContent { status, content, entity }))
169 }
170}
171
172pub async fn set_event_stream(configuration: &configuration::Configuration, project_id: &str, event_stream_id: &str, set_event_stream_body: Option<models::SetEventStreamBody>) -> Result<models::EventStream, Error<SetEventStreamError>> {
173 let p_project_id = project_id;
175 let p_event_stream_id = event_stream_id;
176 let p_set_event_stream_body = set_event_stream_body;
177
178 let uri_str = format!("{}/projects/{project_id}/eventstreams/{event_stream_id}", configuration.base_path, project_id=crate::apis::urlencode(p_project_id), event_stream_id=crate::apis::urlencode(p_event_stream_id));
179 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
180
181 if let Some(ref user_agent) = configuration.user_agent {
182 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
183 }
184 if let Some(ref token) = configuration.bearer_access_token {
185 req_builder = req_builder.bearer_auth(token.to_owned());
186 };
187 req_builder = req_builder.json(&p_set_event_stream_body);
188
189 let req = req_builder.build()?;
190 let resp = configuration.client.execute(req).await?;
191
192 let status = resp.status();
193 let content_type = resp
194 .headers()
195 .get("content-type")
196 .and_then(|v| v.to_str().ok())
197 .unwrap_or("application/octet-stream");
198 let content_type = super::ContentType::from(content_type);
199
200 if !status.is_client_error() && !status.is_server_error() {
201 let content = resp.text().await?;
202 match content_type {
203 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EventStream`"))),
205 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EventStream`")))),
206 }
207 } else {
208 let content = resp.text().await?;
209 let entity: Option<SetEventStreamError> = serde_json::from_str(&content).ok();
210 Err(Error::ResponseError(ResponseContent { status, content, entity }))
211 }
212}
213