1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3CollectionGetError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ApiV3CollectionIdGetError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ApiV3CollectionIdPutError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ApiV3CollectionPutError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn api_v3_collection_get(configuration: &configuration::Configuration, tmdb_id: Option<i32>) -> Result<Vec<crate::models::CollectionResource>, Error<ApiV3CollectionGetError>> {
48 let local_var_configuration = configuration;
49
50 let local_var_client = &local_var_configuration.client;
51
52 let local_var_uri_str = format!("{}/api/v3/collection", local_var_configuration.base_path);
53 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
54
55 if let Some(ref local_var_str) = tmdb_id {
56 local_var_req_builder = local_var_req_builder.query(&[("tmdbId", &local_var_str.to_string())]);
57 }
58 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
59 let local_var_key = local_var_apikey.key.clone();
60 let local_var_value = match local_var_apikey.prefix {
61 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
62 None => local_var_key,
63 };
64 local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
65 }
66 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
67 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
68 }
69 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
70 let local_var_key = local_var_apikey.key.clone();
71 let local_var_value = match local_var_apikey.prefix {
72 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
73 None => local_var_key,
74 };
75 local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
76 };
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<ApiV3CollectionGetError> = 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
93pub async fn api_v3_collection_id_get(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::CollectionResource, Error<ApiV3CollectionIdGetError>> {
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/v3/collection/{id}", local_var_configuration.base_path, id=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_apikey) = local_var_configuration.api_key {
102 let local_var_key = local_var_apikey.key.clone();
103 let local_var_value = match local_var_apikey.prefix {
104 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
105 None => local_var_key,
106 };
107 local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
108 }
109 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
110 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
111 }
112 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
113 let local_var_key = local_var_apikey.key.clone();
114 let local_var_value = match local_var_apikey.prefix {
115 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
116 None => local_var_key,
117 };
118 local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
119 };
120
121 let local_var_req = local_var_req_builder.build()?;
122 let local_var_resp = local_var_client.execute(local_var_req).await?;
123
124 let local_var_status = local_var_resp.status();
125 let local_var_content = local_var_resp.text().await?;
126
127 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
128 serde_json::from_str(&local_var_content).map_err(Error::from)
129 } else {
130 let local_var_entity: Option<ApiV3CollectionIdGetError> = serde_json::from_str(&local_var_content).ok();
131 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
132 Err(Error::ResponseError(local_var_error))
133 }
134}
135
136pub async fn api_v3_collection_id_put(configuration: &configuration::Configuration, id: &str, collection_resource: Option<crate::models::CollectionResource>) -> Result<crate::models::CollectionResource, Error<ApiV3CollectionIdPutError>> {
137 let local_var_configuration = configuration;
138
139 let local_var_client = &local_var_configuration.client;
140
141 let local_var_uri_str = format!("{}/api/v3/collection/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
142 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
143
144 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
145 let local_var_key = local_var_apikey.key.clone();
146 let local_var_value = match local_var_apikey.prefix {
147 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
148 None => local_var_key,
149 };
150 local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
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 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
156 let local_var_key = local_var_apikey.key.clone();
157 let local_var_value = match local_var_apikey.prefix {
158 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
159 None => local_var_key,
160 };
161 local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
162 };
163 local_var_req_builder = local_var_req_builder.json(&collection_resource);
164
165 let local_var_req = local_var_req_builder.build()?;
166 let local_var_resp = local_var_client.execute(local_var_req).await?;
167
168 let local_var_status = local_var_resp.status();
169 let local_var_content = local_var_resp.text().await?;
170
171 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
172 serde_json::from_str(&local_var_content).map_err(Error::from)
173 } else {
174 let local_var_entity: Option<ApiV3CollectionIdPutError> = serde_json::from_str(&local_var_content).ok();
175 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
176 Err(Error::ResponseError(local_var_error))
177 }
178}
179
180pub async fn api_v3_collection_put(configuration: &configuration::Configuration, collection_update_resource: Option<crate::models::CollectionUpdateResource>) -> Result<(), Error<ApiV3CollectionPutError>> {
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/v3/collection", local_var_configuration.base_path);
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_apikey) = local_var_configuration.api_key {
189 let local_var_key = local_var_apikey.key.clone();
190 let local_var_value = match local_var_apikey.prefix {
191 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
192 None => local_var_key,
193 };
194 local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
195 }
196 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
198 }
199 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
200 let local_var_key = local_var_apikey.key.clone();
201 let local_var_value = match local_var_apikey.prefix {
202 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
203 None => local_var_key,
204 };
205 local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
206 };
207 local_var_req_builder = local_var_req_builder.json(&collection_update_resource);
208
209 let local_var_req = local_var_req_builder.build()?;
210 let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212 let local_var_status = local_var_resp.status();
213 let local_var_content = local_var_resp.text().await?;
214
215 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
216 Ok(())
217 } else {
218 let local_var_entity: Option<ApiV3CollectionPutError> = serde_json::from_str(&local_var_content).ok();
219 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
220 Err(Error::ResponseError(local_var_error))
221 }
222}
223