ory_client/apis/
events_api.rs

1/*
2 * Ory APIs
3 *
4 * # Introduction Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers.  ## SDKs This document describes the APIs available in the Ory Network. The APIs are available as SDKs for the following languages:  | Language       | Download SDK                                                     | Documentation                                                                        | | -------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | Dart           | [pub.dev](https://pub.dev/packages/ory_client)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/dart/README.md)       | | .NET           | [nuget.org](https://www.nuget.org/packages/Ory.Client/)          | [README](https://github.com/ory/sdk/blob/master/clients/client/dotnet/README.md)     | | Elixir         | [hex.pm](https://hex.pm/packages/ory_client)                     | [README](https://github.com/ory/sdk/blob/master/clients/client/elixir/README.md)     | | Go             | [github.com](https://github.com/ory/client-go)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/go/README.md)         | | Java           | [maven.org](https://search.maven.org/artifact/sh.ory/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/java/README.md)       | | JavaScript     | [npmjs.com](https://www.npmjs.com/package/@ory/client)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript/README.md) | | JavaScript (With fetch) | [npmjs.com](https://www.npmjs.com/package/@ory/client-fetch)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript-fetch/README.md) |  | PHP            | [packagist.org](https://packagist.org/packages/ory/client)       | [README](https://github.com/ory/sdk/blob/master/clients/client/php/README.md)        | | Python         | [pypi.org](https://pypi.org/project/ory-client/)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/python/README.md)     | | Ruby           | [rubygems.org](https://rubygems.org/gems/ory-client)             | [README](https://github.com/ory/sdk/blob/master/clients/client/ruby/README.md)       | | Rust           | [crates.io](https://crates.io/crates/ory-client)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/rust/README.md)       | 
5 *
6 * The version of the OpenAPI document: v1.22.4
7 * Contact: support@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`create_event_stream`]
19#[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/// struct for typed errors of method [`delete_event_stream`]
30#[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/// struct for typed errors of method [`list_event_streams`]
41#[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/// struct for typed errors of method [`set_event_stream`]
51#[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    // add a prefix to parameters to efficiently prevent name collisions
64    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
103/// Remove an event stream from a project.
104pub async fn delete_event_stream(configuration: &configuration::Configuration, project_id: &str, event_stream_id: &str) -> Result<(), Error<DeleteEventStreamError>> {
105    // add a prefix to parameters to efficiently prevent name collisions
106    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    // add a prefix to parameters to efficiently prevent name collisions
135    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    // add a prefix to parameters to efficiently prevent name collisions
174    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