1use 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 MembershipsGetOrganizationMembershipsError {
22 Status400(serde_json::Value),
23 Status401(serde_json::Value),
24 Status403(serde_json::Value),
25 Status404(serde_json::Value),
26 Status405(serde_json::Value),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum MembershipsGetProjectMembershipsError {
34 Status400(serde_json::Value),
35 Status401(serde_json::Value),
36 Status403(serde_json::Value),
37 Status404(serde_json::Value),
38 Status405(serde_json::Value),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum MembershipsUpdateOrganizationMembershipError {
46 Status400(serde_json::Value),
47 Status401(serde_json::Value),
48 Status403(serde_json::Value),
49 Status404(serde_json::Value),
50 Status405(serde_json::Value),
51 UnknownValue(serde_json::Value),
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum MembershipsUpdateProjectMembershipError {
58 Status400(serde_json::Value),
59 Status401(serde_json::Value),
60 Status403(serde_json::Value),
61 Status404(serde_json::Value),
62 Status405(serde_json::Value),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn memberships_get_organization_memberships(configuration: &configuration::Configuration, ) -> Result<models::MembershipsResponse, Error<MembershipsGetOrganizationMembershipsError>> {
69
70 let uri_str = format!("{}/api/public/organizations/memberships", configuration.base_path);
71 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
72
73 if let Some(ref user_agent) = configuration.user_agent {
74 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75 }
76 if let Some(ref auth_conf) = configuration.basic_auth {
77 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
78 };
79
80 let req = req_builder.build()?;
81 let resp = configuration.client.execute(req).await?;
82
83 let status = resp.status();
84 let content_type = resp
85 .headers()
86 .get("content-type")
87 .and_then(|v| v.to_str().ok())
88 .unwrap_or("application/octet-stream");
89 let content_type = super::ContentType::from(content_type);
90
91 if !status.is_client_error() && !status.is_server_error() {
92 let content = resp.text().await?;
93 match content_type {
94 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
95 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipsResponse`"))),
96 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::MembershipsResponse`")))),
97 }
98 } else {
99 let content = resp.text().await?;
100 let entity: Option<MembershipsGetOrganizationMembershipsError> = serde_json::from_str(&content).ok();
101 Err(Error::ResponseError(ResponseContent { status, content, entity }))
102 }
103}
104
105pub async fn memberships_get_project_memberships(configuration: &configuration::Configuration, project_id: &str) -> Result<models::MembershipsResponse, Error<MembershipsGetProjectMembershipsError>> {
107 let p_project_id = project_id;
109
110 let uri_str = format!("{}/api/public/projects/{projectId}/memberships", configuration.base_path, projectId=crate::apis::urlencode(p_project_id));
111 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
112
113 if let Some(ref user_agent) = configuration.user_agent {
114 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115 }
116 if let Some(ref auth_conf) = configuration.basic_auth {
117 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
118 };
119
120 let req = req_builder.build()?;
121 let resp = configuration.client.execute(req).await?;
122
123 let status = resp.status();
124 let content_type = resp
125 .headers()
126 .get("content-type")
127 .and_then(|v| v.to_str().ok())
128 .unwrap_or("application/octet-stream");
129 let content_type = super::ContentType::from(content_type);
130
131 if !status.is_client_error() && !status.is_server_error() {
132 let content = resp.text().await?;
133 match content_type {
134 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
135 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipsResponse`"))),
136 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::MembershipsResponse`")))),
137 }
138 } else {
139 let content = resp.text().await?;
140 let entity: Option<MembershipsGetProjectMembershipsError> = serde_json::from_str(&content).ok();
141 Err(Error::ResponseError(ResponseContent { status, content, entity }))
142 }
143}
144
145pub async fn memberships_update_organization_membership(configuration: &configuration::Configuration, membership_request: models::MembershipRequest) -> Result<models::MembershipResponse, Error<MembershipsUpdateOrganizationMembershipError>> {
147 let p_membership_request = membership_request;
149
150 let uri_str = format!("{}/api/public/organizations/memberships", configuration.base_path);
151 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
152
153 if let Some(ref user_agent) = configuration.user_agent {
154 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
155 }
156 if let Some(ref auth_conf) = configuration.basic_auth {
157 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
158 };
159 req_builder = req_builder.json(&p_membership_request);
160
161 let req = req_builder.build()?;
162 let resp = configuration.client.execute(req).await?;
163
164 let status = resp.status();
165 let content_type = resp
166 .headers()
167 .get("content-type")
168 .and_then(|v| v.to_str().ok())
169 .unwrap_or("application/octet-stream");
170 let content_type = super::ContentType::from(content_type);
171
172 if !status.is_client_error() && !status.is_server_error() {
173 let content = resp.text().await?;
174 match content_type {
175 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
176 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipResponse`"))),
177 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::MembershipResponse`")))),
178 }
179 } else {
180 let content = resp.text().await?;
181 let entity: Option<MembershipsUpdateOrganizationMembershipError> = serde_json::from_str(&content).ok();
182 Err(Error::ResponseError(ResponseContent { status, content, entity }))
183 }
184}
185
186pub async fn memberships_update_project_membership(configuration: &configuration::Configuration, project_id: &str, membership_request: models::MembershipRequest) -> Result<models::MembershipResponse, Error<MembershipsUpdateProjectMembershipError>> {
188 let p_project_id = project_id;
190 let p_membership_request = membership_request;
191
192 let uri_str = format!("{}/api/public/projects/{projectId}/memberships", configuration.base_path, projectId=crate::apis::urlencode(p_project_id));
193 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
194
195 if let Some(ref user_agent) = configuration.user_agent {
196 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
197 }
198 if let Some(ref auth_conf) = configuration.basic_auth {
199 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
200 };
201 req_builder = req_builder.json(&p_membership_request);
202
203 let req = req_builder.build()?;
204 let resp = configuration.client.execute(req).await?;
205
206 let status = resp.status();
207 let content_type = resp
208 .headers()
209 .get("content-type")
210 .and_then(|v| v.to_str().ok())
211 .unwrap_or("application/octet-stream");
212 let content_type = super::ContentType::from(content_type);
213
214 if !status.is_client_error() && !status.is_server_error() {
215 let content = resp.text().await?;
216 match content_type {
217 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
218 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipResponse`"))),
219 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::MembershipResponse`")))),
220 }
221 } else {
222 let content = resp.text().await?;
223 let entity: Option<MembershipsUpdateProjectMembershipError> = serde_json::from_str(&content).ok();
224 Err(Error::ResponseError(ResponseContent { status, content, entity }))
225 }
226}
227