memos_api/apis/
webhook_service_api.rs1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum WebhookServiceCreateWebhookError {
22 DefaultResponse(models::GooglerpcStatus),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum WebhookServiceDeleteWebhookError {
30 DefaultResponse(models::GooglerpcStatus),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum WebhookServiceGetWebhookError {
38 DefaultResponse(models::GooglerpcStatus),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum WebhookServiceListWebhooksError {
46 DefaultResponse(models::GooglerpcStatus),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum WebhookServiceUpdateWebhookError {
54 DefaultResponse(models::GooglerpcStatus),
55 UnknownValue(serde_json::Value),
56}
57
58
59pub fn webhook_service_create_webhook(configuration: &configuration::Configuration, body: models::V1CreateWebhookRequest) -> Result<models::V1Webhook, Error<WebhookServiceCreateWebhookError>> {
60 let local_var_configuration = configuration;
61
62 let local_var_client = &local_var_configuration.client;
63
64 let local_var_uri_str = format!("{}/api/v1/webhooks", local_var_configuration.base_path);
65 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
66
67 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
68 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
69 }
70 local_var_req_builder = local_var_req_builder.json(&body);
71
72 let local_var_req = local_var_req_builder.build()?;
73 let local_var_resp = local_var_client.execute(local_var_req)?;
74
75 let local_var_status = local_var_resp.status();
76 let local_var_content = local_var_resp.text()?;
77
78 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
79 serde_json::from_str(&local_var_content).map_err(Error::from)
80 } else {
81 let local_var_entity: Option<WebhookServiceCreateWebhookError> = serde_json::from_str(&local_var_content).ok();
82 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
83 Err(Error::ResponseError(local_var_error))
84 }
85}
86
87pub fn webhook_service_delete_webhook(configuration: &configuration::Configuration, id: i32) -> Result<serde_json::Value, Error<WebhookServiceDeleteWebhookError>> {
88 let local_var_configuration = configuration;
89
90 let local_var_client = &local_var_configuration.client;
91
92 let local_var_uri_str = format!("{}/api/v1/webhooks/{id}", local_var_configuration.base_path, id=id);
93 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
94
95 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
96 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97 }
98
99 let local_var_req = local_var_req_builder.build()?;
100 let local_var_resp = local_var_client.execute(local_var_req)?;
101
102 let local_var_status = local_var_resp.status();
103 let local_var_content = local_var_resp.text()?;
104
105 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
106 serde_json::from_str(&local_var_content).map_err(Error::from)
107 } else {
108 let local_var_entity: Option<WebhookServiceDeleteWebhookError> = serde_json::from_str(&local_var_content).ok();
109 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
110 Err(Error::ResponseError(local_var_error))
111 }
112}
113
114pub fn webhook_service_get_webhook(configuration: &configuration::Configuration, id: i32) -> Result<models::V1Webhook, Error<WebhookServiceGetWebhookError>> {
115 let local_var_configuration = configuration;
116
117 let local_var_client = &local_var_configuration.client;
118
119 let local_var_uri_str = format!("{}/api/v1/webhooks/{id}", local_var_configuration.base_path, id=id);
120 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
121
122 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
123 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
124 }
125
126 let local_var_req = local_var_req_builder.build()?;
127 let local_var_resp = local_var_client.execute(local_var_req)?;
128
129 let local_var_status = local_var_resp.status();
130 let local_var_content = local_var_resp.text()?;
131
132 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
133 serde_json::from_str(&local_var_content).map_err(Error::from)
134 } else {
135 let local_var_entity: Option<WebhookServiceGetWebhookError> = serde_json::from_str(&local_var_content).ok();
136 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
137 Err(Error::ResponseError(local_var_error))
138 }
139}
140
141pub fn webhook_service_list_webhooks(configuration: &configuration::Configuration, creator_id: Option<i32>) -> Result<models::V1ListWebhooksResponse, Error<WebhookServiceListWebhooksError>> {
142 let local_var_configuration = configuration;
143
144 let local_var_client = &local_var_configuration.client;
145
146 let local_var_uri_str = format!("{}/api/v1/webhooks", local_var_configuration.base_path);
147 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
148
149 if let Some(ref local_var_str) = creator_id {
150 local_var_req_builder = local_var_req_builder.query(&[("creatorId", &local_var_str.to_string())]);
151 }
152 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
153 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154 }
155
156 let local_var_req = local_var_req_builder.build()?;
157 let local_var_resp = local_var_client.execute(local_var_req)?;
158
159 let local_var_status = local_var_resp.status();
160 let local_var_content = local_var_resp.text()?;
161
162 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
163 serde_json::from_str(&local_var_content).map_err(Error::from)
164 } else {
165 let local_var_entity: Option<WebhookServiceListWebhooksError> = serde_json::from_str(&local_var_content).ok();
166 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
167 Err(Error::ResponseError(local_var_error))
168 }
169}
170
171pub fn webhook_service_update_webhook(configuration: &configuration::Configuration, webhook_id: i32, webhook: models::WebhookServiceUpdateWebhookRequest) -> Result<models::V1Webhook, Error<WebhookServiceUpdateWebhookError>> {
172 let local_var_configuration = configuration;
173
174 let local_var_client = &local_var_configuration.client;
175
176 let local_var_uri_str = format!("{}/api/v1/webhooks/{webhook_id}", local_var_configuration.base_path, webhook_id=webhook_id);
177 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
178
179 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
180 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
181 }
182 local_var_req_builder = local_var_req_builder.json(&webhook);
183
184 let local_var_req = local_var_req_builder.build()?;
185 let local_var_resp = local_var_client.execute(local_var_req)?;
186
187 let local_var_status = local_var_resp.status();
188 let local_var_content = local_var_resp.text()?;
189
190 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
191 serde_json::from_str(&local_var_content).map_err(Error::from)
192 } else {
193 let local_var_entity: Option<WebhookServiceUpdateWebhookError> = serde_json::from_str(&local_var_content).ok();
194 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
195 Err(Error::ResponseError(local_var_error))
196 }
197}
198