btcpay_client/apis/
notifications_current_user_api.rs

1/*
2 * BTCPay Greenfield API
3 *
4 * A full API to use your BTCPay Server
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`notifications_delete_notification`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum NotificationsDeleteNotificationError {
22    Status403(),
23    Status404(),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`notifications_get_notification`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum NotificationsGetNotificationError {
31    Status403(),
32    Status404(),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`notifications_get_notifications`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum NotificationsGetNotificationsError {
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`notifications_update_notification`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum NotificationsUpdateNotificationError {
47    Status403(),
48    Status404(),
49    UnknownValue(serde_json::Value),
50}
51
52
53/// Removes the specified notification.
54pub async fn notifications_delete_notification(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<NotificationsDeleteNotificationError>> {
55    let local_var_configuration = configuration;
56
57    let local_var_client = &local_var_configuration.client;
58
59    let local_var_uri_str = format!("{}/api/v1/users/me/notifications/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
60    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
61
62    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
63        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
64    }
65    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
66        let local_var_key = local_var_apikey.key.clone();
67        let local_var_value = match local_var_apikey.prefix {
68            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
69            None => local_var_key,
70        };
71        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
72    };
73    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
74        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
75    };
76
77    let local_var_req = local_var_req_builder.build()?;
78    let local_var_resp = local_var_client.execute(local_var_req).await?;
79
80    let local_var_status = local_var_resp.status();
81    let local_var_content = local_var_resp.text().await?;
82
83    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
84        Ok(())
85    } else {
86        let local_var_entity: Option<NotificationsDeleteNotificationError> = serde_json::from_str(&local_var_content).ok();
87        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
88        Err(Error::ResponseError(local_var_error))
89    }
90}
91
92/// View information about the specified notification
93pub async fn notifications_get_notification(configuration: &configuration::Configuration, id: &str) -> Result<crate::models::NotificationData, Error<NotificationsGetNotificationError>> {
94    let local_var_configuration = configuration;
95
96    let local_var_client = &local_var_configuration.client;
97
98    let local_var_uri_str = format!("{}/api/v1/users/me/notifications/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
99    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
100
101    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
102        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
103    }
104    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
105        let local_var_key = local_var_apikey.key.clone();
106        let local_var_value = match local_var_apikey.prefix {
107            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
108            None => local_var_key,
109        };
110        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
111    };
112    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
113        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
114    };
115
116    let local_var_req = local_var_req_builder.build()?;
117    let local_var_resp = local_var_client.execute(local_var_req).await?;
118
119    let local_var_status = local_var_resp.status();
120    let local_var_content = local_var_resp.text().await?;
121
122    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
123        serde_json::from_str(&local_var_content).map_err(Error::from)
124    } else {
125        let local_var_entity: Option<NotificationsGetNotificationError> = serde_json::from_str(&local_var_content).ok();
126        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
127        Err(Error::ResponseError(local_var_error))
128    }
129}
130
131/// View current user's notifications
132pub async fn notifications_get_notifications(configuration: &configuration::Configuration, seen: Option<&str>, skip: Option<f32>, take: Option<f32>) -> Result<crate::models::NotificationData, Error<NotificationsGetNotificationsError>> {
133    let local_var_configuration = configuration;
134
135    let local_var_client = &local_var_configuration.client;
136
137    let local_var_uri_str = format!("{}/api/v1/users/me/notifications", local_var_configuration.base_path);
138    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
139
140    if let Some(ref local_var_str) = seen {
141        local_var_req_builder = local_var_req_builder.query(&[("seen", &local_var_str.to_string())]);
142    }
143    if let Some(ref local_var_str) = skip {
144        local_var_req_builder = local_var_req_builder.query(&[("skip", &local_var_str.to_string())]);
145    }
146    if let Some(ref local_var_str) = take {
147        local_var_req_builder = local_var_req_builder.query(&[("take", &local_var_str.to_string())]);
148    }
149    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
150        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
151    }
152    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
153        let local_var_key = local_var_apikey.key.clone();
154        let local_var_value = match local_var_apikey.prefix {
155            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
156            None => local_var_key,
157        };
158        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
159    };
160    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
161        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
162    };
163
164    let local_var_req = local_var_req_builder.build()?;
165    let local_var_resp = local_var_client.execute(local_var_req).await?;
166
167    let local_var_status = local_var_resp.status();
168    let local_var_content = local_var_resp.text().await?;
169
170    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
171        serde_json::from_str(&local_var_content).map_err(Error::from)
172    } else {
173        let local_var_entity: Option<NotificationsGetNotificationsError> = serde_json::from_str(&local_var_content).ok();
174        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
175        Err(Error::ResponseError(local_var_error))
176    }
177}
178
179/// Updates the notification
180pub async fn notifications_update_notification(configuration: &configuration::Configuration, id: &str, update_notification: crate::models::UpdateNotification) -> Result<crate::models::NotificationData, Error<NotificationsUpdateNotificationError>> {
181    let local_var_configuration = configuration;
182
183    let local_var_client = &local_var_configuration.client;
184
185    let local_var_uri_str = format!("{}/api/v1/users/me/notifications/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
186    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
187
188    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
189        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
190    }
191    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
192        let local_var_key = local_var_apikey.key.clone();
193        let local_var_value = match local_var_apikey.prefix {
194            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
195            None => local_var_key,
196        };
197        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
198    };
199    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
200        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
201    };
202    local_var_req_builder = local_var_req_builder.json(&update_notification);
203
204    let local_var_req = local_var_req_builder.build()?;
205    let local_var_resp = local_var_client.execute(local_var_req).await?;
206
207    let local_var_status = local_var_resp.status();
208    let local_var_content = local_var_resp.text().await?;
209
210    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
211        serde_json::from_str(&local_var_content).map_err(Error::from)
212    } else {
213        let local_var_entity: Option<NotificationsUpdateNotificationError> = serde_json::from_str(&local_var_content).ok();
214        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
215        Err(Error::ResponseError(local_var_error))
216    }
217}
218