thunderstore_api/apis/v2/
community.rs1use crate::apis::configuration::Configuration;
8use crate::apis::{urlencode, Error, ResponseContent};
9use crate::models::v2::community::{CategoryListResponse, ListResponse, PackageList};
10use crate::models::v2::package;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
14#[serde(untagged)]
15pub enum CategoryListError {
16 UnknownValue(serde_json::Value),
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum ListError {
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum PackageDetailsError {
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum ListPackagesError {
37 UnknownValue(serde_json::Value),
38}
39
40pub async fn list_categories(
41 configuration: &Configuration,
42 community: &str,
43 cursor: Option<&str>,
44) -> Result<CategoryListResponse, Error<CategoryListError>> {
45 let local_var_configuration = configuration;
46
47 let local_var_client = &local_var_configuration.client;
48
49 let local_var_uri_str = format!(
50 "{}/api/experimental/community/{community}/category/",
51 local_var_configuration.base_path,
52 community = urlencode(community)
53 );
54 let mut local_var_req_builder =
55 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
56
57 if let Some(local_var_str) = cursor {
58 local_var_req_builder =
59 local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
60 }
61 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
62 local_var_req_builder =
63 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
64 }
65 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
66 local_var_req_builder = local_var_req_builder
67 .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
68 };
69
70 let local_var_req = local_var_req_builder.build()?;
71 let local_var_resp = local_var_client.execute(local_var_req).await?;
72
73 let local_var_status = local_var_resp.status();
74 let local_var_content = local_var_resp.text().await?;
75
76 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
77 serde_json::from_str(&local_var_content).map_err(Error::from)
78 } else {
79 let local_var_entity: Option<CategoryListError> =
80 serde_json::from_str(&local_var_content).ok();
81 let local_var_error = ResponseContent {
82 status: local_var_status,
83 content: local_var_content,
84 entity: local_var_entity,
85 };
86 Err(Error::ResponseError(local_var_error))
87 }
88}
89
90pub async fn list(
91 configuration: &Configuration,
92 cursor: Option<&str>,
93) -> Result<ListResponse, Error<ListError>> {
94 let local_var_configuration = configuration;
95
96 let local_var_client = &local_var_configuration.client;
97
98 let local_var_uri_str = format!(
99 "{}/api/experimental/community/",
100 local_var_configuration.base_path
101 );
102 let mut local_var_req_builder =
103 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
104
105 if let Some(local_var_str) = cursor {
106 local_var_req_builder =
107 local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
108 }
109 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
110 local_var_req_builder =
111 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112 }
113 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
114 local_var_req_builder = local_var_req_builder
115 .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
116 };
117
118 let local_var_req = local_var_req_builder.build()?;
119 let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121 let local_var_status = local_var_resp.status();
122 let local_var_content = local_var_resp.text().await?;
123
124 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125 serde_json::from_str(&local_var_content).map_err(Error::from)
126 } else {
127 let local_var_entity: Option<ListError> = serde_json::from_str(&local_var_content).ok();
128 let local_var_error = ResponseContent {
129 status: local_var_status,
130 content: local_var_content,
131 entity: local_var_entity,
132 };
133 Err(Error::ResponseError(local_var_error))
134 }
135}
136
137pub async fn package_details(
139 configuration: &Configuration,
140 community_identifier: &str,
141 package_name: &str,
142 package_namespace: &str,
143) -> Result<package::DetailView, Error<PackageDetailsError>> {
144 let local_var_configuration = configuration;
145
146 let local_var_client = &local_var_configuration.client;
147
148 let local_var_uri_str = format!("{}/api/experimental/frontend/c/{community_identifier}/p/{package_namespace}/{package_name}/", local_var_configuration.base_path, community_identifier = urlencode(community_identifier), package_name = urlencode(package_name), package_namespace = urlencode(package_namespace));
149 let mut local_var_req_builder =
150 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
151
152 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
153 local_var_req_builder =
154 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
155 }
156 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
157 local_var_req_builder = local_var_req_builder
158 .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
159 };
160
161 let local_var_req = local_var_req_builder.build()?;
162 let local_var_resp = local_var_client.execute(local_var_req).await?;
163
164 let local_var_status = local_var_resp.status();
165 let local_var_content = local_var_resp.text().await?;
166
167 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
168 serde_json::from_str(&local_var_content).map_err(Error::from)
169 } else {
170 let local_var_entity: Option<PackageDetailsError> =
171 serde_json::from_str(&local_var_content).ok();
172 let local_var_error = ResponseContent {
173 status: local_var_status,
174 content: local_var_content,
175 entity: local_var_entity,
176 };
177 Err(Error::ResponseError(local_var_error))
178 }
179}
180
181pub async fn list_packages(
183 configuration: &Configuration,
184 community_identifier: &str,
185) -> Result<PackageList, Error<ListPackagesError>> {
186 let local_var_configuration = configuration;
187
188 let local_var_client = &local_var_configuration.client;
189
190 let local_var_uri_str = format!(
191 "{}/api/experimental/frontend/c/{community_identifier}/packages/",
192 local_var_configuration.base_path,
193 community_identifier = urlencode(community_identifier)
194 );
195 let mut local_var_req_builder =
196 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
197
198 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
199 local_var_req_builder =
200 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
201 }
202 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
203 local_var_req_builder = local_var_req_builder
204 .basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
205 };
206
207 let local_var_req = local_var_req_builder.build()?;
208 let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210 let local_var_status = local_var_resp.status();
211 let local_var_content = local_var_resp.text().await?;
212
213 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214 serde_json::from_str(&local_var_content).map_err(Error::from)
215 } else {
216 let local_var_entity: Option<ListPackagesError> =
217 serde_json::from_str(&local_var_content).ok();
218 let local_var_error = ResponseContent {
219 status: local_var_status,
220 content: local_var_content,
221 entity: local_var_entity,
222 };
223 Err(Error::ResponseError(local_var_error))
224 }
225}