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.17.2
7 * Contact: support@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
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    let local_var_configuration = configuration;
64
65    let local_var_client = &local_var_configuration.client;
66
67    let local_var_uri_str = format!("{}/projects/{project_id}/eventstreams", local_var_configuration.base_path, project_id=crate::apis::urlencode(project_id));
68    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
69
70    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
71        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72    }
73    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
74        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
75    };
76    local_var_req_builder = local_var_req_builder.json(&create_event_stream_body);
77
78    let local_var_req = local_var_req_builder.build()?;
79    let local_var_resp = local_var_client.execute(local_var_req).await?;
80
81    let local_var_status = local_var_resp.status();
82    let local_var_content = local_var_resp.text().await?;
83
84    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
85        serde_json::from_str(&local_var_content).map_err(Error::from)
86    } else {
87        let local_var_entity: Option<CreateEventStreamError> = serde_json::from_str(&local_var_content).ok();
88        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
89        Err(Error::ResponseError(local_var_error))
90    }
91}
92
93/// Remove an event stream from a project.
94pub async fn delete_event_stream(configuration: &configuration::Configuration, project_id: &str, event_stream_id: &str) -> Result<(), Error<DeleteEventStreamError>> {
95    let local_var_configuration = configuration;
96
97    let local_var_client = &local_var_configuration.client;
98
99    let local_var_uri_str = format!("{}/projects/{project_id}/eventstreams/{event_stream_id}", local_var_configuration.base_path, project_id=crate::apis::urlencode(project_id), event_stream_id=crate::apis::urlencode(event_stream_id));
100    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
101
102    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104    }
105    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
106        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
107    };
108
109    let local_var_req = local_var_req_builder.build()?;
110    let local_var_resp = local_var_client.execute(local_var_req).await?;
111
112    let local_var_status = local_var_resp.status();
113    let local_var_content = local_var_resp.text().await?;
114
115    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
116        Ok(())
117    } else {
118        let local_var_entity: Option<DeleteEventStreamError> = serde_json::from_str(&local_var_content).ok();
119        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
120        Err(Error::ResponseError(local_var_error))
121    }
122}
123
124pub async fn list_event_streams(configuration: &configuration::Configuration, project_id: &str) -> Result<models::ListEventStreams, Error<ListEventStreamsError>> {
125    let local_var_configuration = configuration;
126
127    let local_var_client = &local_var_configuration.client;
128
129    let local_var_uri_str = format!("{}/projects/{project_id}/eventstreams", local_var_configuration.base_path, project_id=crate::apis::urlencode(project_id));
130    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
131
132    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
133        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
134    }
135    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
136        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
137    };
138
139    let local_var_req = local_var_req_builder.build()?;
140    let local_var_resp = local_var_client.execute(local_var_req).await?;
141
142    let local_var_status = local_var_resp.status();
143    let local_var_content = local_var_resp.text().await?;
144
145    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
146        serde_json::from_str(&local_var_content).map_err(Error::from)
147    } else {
148        let local_var_entity: Option<ListEventStreamsError> = serde_json::from_str(&local_var_content).ok();
149        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
150        Err(Error::ResponseError(local_var_error))
151    }
152}
153
154pub 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>> {
155    let local_var_configuration = configuration;
156
157    let local_var_client = &local_var_configuration.client;
158
159    let local_var_uri_str = format!("{}/projects/{project_id}/eventstreams/{event_stream_id}", local_var_configuration.base_path, project_id=crate::apis::urlencode(project_id), event_stream_id=crate::apis::urlencode(event_stream_id));
160    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
161
162    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
163        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164    }
165    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
166        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
167    };
168    local_var_req_builder = local_var_req_builder.json(&set_event_stream_body);
169
170    let local_var_req = local_var_req_builder.build()?;
171    let local_var_resp = local_var_client.execute(local_var_req).await?;
172
173    let local_var_status = local_var_resp.status();
174    let local_var_content = local_var_resp.text().await?;
175
176    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
177        serde_json::from_str(&local_var_content).map_err(Error::from)
178    } else {
179        let local_var_entity: Option<SetEventStreamError> = serde_json::from_str(&local_var_content).ok();
180        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
181        Err(Error::ResponseError(local_var_error))
182    }
183}
184