Skip to main content

forem_openapi_client/apis/
articles_api.rs

1/*
2 * Forem API V1
3 *
4 * Access Forem articles, users and other resources via API.         For a real-world example of Forem in action, check out [DEV](https://www.dev.to).         All endpoints can be accessed with the 'api-key' header and a accept header, but         some of them are accessible publicly without authentication.          Dates and date times, unless otherwise specified, must be in         the [RFC 3339](https://tools.ietf.org/html/rfc3339) format.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`create_article`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateArticleError {
20    Status401(),
21    Status422(),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_article_by_id`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetArticleByIdError {
29    Status404(),
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`get_article_by_path`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetArticleByPathError {
37    Status404(),
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`get_articles`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum GetArticlesError {
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`get_latest_articles`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetLatestArticlesError {
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed errors of method [`get_org_articles`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum GetOrgArticlesError {
59    Status404(),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`get_user_all_articles`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetUserAllArticlesError {
67    Status401(),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`get_user_articles`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum GetUserArticlesError {
75    Status401(),
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`get_user_published_articles`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum GetUserPublishedArticlesError {
83    Status401(),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`get_user_unpublished_articles`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum GetUserUnpublishedArticlesError {
91    Status401(),
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`unpublish_article`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum UnpublishArticleError {
99    Status401(),
100    Status404(),
101    UnknownValue(serde_json::Value),
102}
103
104/// struct for typed errors of method [`update_article`]
105#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(untagged)]
107pub enum UpdateArticleError {
108    Status404(),
109    Status401(),
110    Status422(),
111    UnknownValue(serde_json::Value),
112}
113
114/// struct for typed errors of method [`videos`]
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum VideosError {
118    UnknownValue(serde_json::Value),
119}
120
121/// This endpoint allows the client to create a new article.  \"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.
122pub async fn create_article(
123    configuration: &configuration::Configuration,
124    article: Option<crate::models::Article>,
125) -> Result<(), Error<CreateArticleError>> {
126    let local_var_configuration = configuration;
127
128    let local_var_client = &local_var_configuration.client;
129
130    let local_var_uri_str = format!("{}/api/articles", local_var_configuration.base_path);
131    let mut local_var_req_builder =
132        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
133
134    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
135        local_var_req_builder =
136            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
137    }
138    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
139        let local_var_key = local_var_apikey.key.clone();
140        let local_var_value = match local_var_apikey.prefix {
141            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
142            None => local_var_key,
143        };
144        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
145    };
146    local_var_req_builder = local_var_req_builder.json(&article);
147
148    let local_var_req = local_var_req_builder.build()?;
149    let local_var_resp = local_var_client.execute(local_var_req).await?;
150
151    let local_var_status = local_var_resp.status();
152    let local_var_content = local_var_resp.text().await?;
153
154    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
155        Ok(())
156    } else {
157        let local_var_entity: Option<CreateArticleError> =
158            serde_json::from_str(&local_var_content).ok();
159        let local_var_error = ResponseContent {
160            status: local_var_status,
161            content: local_var_content,
162            entity: local_var_entity,
163        };
164        Err(Error::ResponseError(local_var_error))
165    }
166}
167
168/// This endpoint allows the client to retrieve a single published article given its `id`.
169pub async fn get_article_by_id(
170    configuration: &configuration::Configuration,
171    id: i32,
172) -> Result<Vec<crate::models::ArticleIndex>, Error<GetArticleByIdError>> {
173    let local_var_configuration = configuration;
174
175    let local_var_client = &local_var_configuration.client;
176
177    let local_var_uri_str = format!(
178        "{}/api/articles/{id}",
179        local_var_configuration.base_path,
180        id = id
181    );
182    let mut local_var_req_builder =
183        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
184
185    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
186        local_var_req_builder =
187            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188    }
189
190    let local_var_req = local_var_req_builder.build()?;
191    let local_var_resp = local_var_client.execute(local_var_req).await?;
192
193    let local_var_status = local_var_resp.status();
194    let local_var_content = local_var_resp.text().await?;
195
196    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
197        serde_json::from_str(&local_var_content).map_err(Error::from)
198    } else {
199        let local_var_entity: Option<GetArticleByIdError> =
200            serde_json::from_str(&local_var_content).ok();
201        let local_var_error = ResponseContent {
202            status: local_var_status,
203            content: local_var_content,
204            entity: local_var_entity,
205        };
206        Err(Error::ResponseError(local_var_error))
207    }
208}
209
210/// This endpoint allows the client to retrieve a single published article given its `path`.
211pub async fn get_article_by_path(
212    configuration: &configuration::Configuration,
213    username: &str,
214    slug: &str,
215) -> Result<Vec<crate::models::ArticleIndex>, Error<GetArticleByPathError>> {
216    let local_var_configuration = configuration;
217
218    let local_var_client = &local_var_configuration.client;
219
220    let local_var_uri_str = format!(
221        "{}/api/articles/{username}/{slug}",
222        local_var_configuration.base_path,
223        username = crate::apis::urlencode(username),
224        slug = crate::apis::urlencode(slug)
225    );
226    let mut local_var_req_builder =
227        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
228
229    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
230        local_var_req_builder =
231            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
232    }
233
234    let local_var_req = local_var_req_builder.build()?;
235    let local_var_resp = local_var_client.execute(local_var_req).await?;
236
237    let local_var_status = local_var_resp.status();
238    let local_var_content = local_var_resp.text().await?;
239
240    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
241        serde_json::from_str(&local_var_content).map_err(Error::from)
242    } else {
243        let local_var_entity: Option<GetArticleByPathError> =
244            serde_json::from_str(&local_var_content).ok();
245        let local_var_error = ResponseContent {
246            status: local_var_status,
247            content: local_var_content,
248            entity: local_var_entity,
249        };
250        Err(Error::ResponseError(local_var_error))
251    }
252}
253
254/// This endpoint allows the client to retrieve a list of articles.  \"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.  By default it will return featured, published articles ordered by descending popularity.  It supports pagination, each page will contain `30` articles by default.
255pub async fn get_articles(
256    configuration: &configuration::Configuration,
257    page: Option<i32>,
258    per_page: Option<i32>,
259    tag: Option<&str>,
260    tags: Option<&str>,
261    tags_exclude: Option<&str>,
262    username: Option<&str>,
263    state: Option<&str>,
264    top: Option<i32>,
265    collection_id: Option<i32>,
266) -> Result<Vec<crate::models::ArticleIndex>, Error<GetArticlesError>> {
267    let local_var_configuration = configuration;
268
269    let local_var_client = &local_var_configuration.client;
270
271    let local_var_uri_str = format!("{}/api/articles", local_var_configuration.base_path);
272    let mut local_var_req_builder =
273        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
274
275    if let Some(ref local_var_str) = page {
276        local_var_req_builder =
277            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
278    }
279    if let Some(ref local_var_str) = per_page {
280        local_var_req_builder =
281            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
282    }
283    if let Some(ref local_var_str) = tag {
284        local_var_req_builder = local_var_req_builder.query(&[("tag", &local_var_str.to_string())]);
285    }
286    if let Some(ref local_var_str) = tags {
287        local_var_req_builder =
288            local_var_req_builder.query(&[("tags", &local_var_str.to_string())]);
289    }
290    if let Some(ref local_var_str) = tags_exclude {
291        local_var_req_builder =
292            local_var_req_builder.query(&[("tags_exclude", &local_var_str.to_string())]);
293    }
294    if let Some(ref local_var_str) = username {
295        local_var_req_builder =
296            local_var_req_builder.query(&[("username", &local_var_str.to_string())]);
297    }
298    if let Some(ref local_var_str) = state {
299        local_var_req_builder =
300            local_var_req_builder.query(&[("state", &local_var_str.to_string())]);
301    }
302    if let Some(ref local_var_str) = top {
303        local_var_req_builder = local_var_req_builder.query(&[("top", &local_var_str.to_string())]);
304    }
305    if let Some(ref local_var_str) = collection_id {
306        local_var_req_builder =
307            local_var_req_builder.query(&[("collection_id", &local_var_str.to_string())]);
308    }
309    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
310        local_var_req_builder =
311            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
312    }
313
314    let local_var_req = local_var_req_builder.build()?;
315    let local_var_resp = local_var_client.execute(local_var_req).await?;
316
317    let local_var_status = local_var_resp.status();
318    let local_var_content = local_var_resp.text().await?;
319
320    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
321        serde_json::from_str(&local_var_content).map_err(Error::from)
322    } else {
323        let local_var_entity: Option<GetArticlesError> =
324            serde_json::from_str(&local_var_content).ok();
325        let local_var_error = ResponseContent {
326            status: local_var_status,
327            content: local_var_content,
328            entity: local_var_entity,
329        };
330        Err(Error::ResponseError(local_var_error))
331    }
332}
333
334/// This endpoint allows the client to retrieve a list of articles. ordered by descending publish date.  It supports pagination, each page will contain 30 articles by default.
335pub async fn get_latest_articles(
336    configuration: &configuration::Configuration,
337    page: Option<i32>,
338    per_page: Option<i32>,
339) -> Result<Vec<crate::models::ArticleIndex>, Error<GetLatestArticlesError>> {
340    let local_var_configuration = configuration;
341
342    let local_var_client = &local_var_configuration.client;
343
344    let local_var_uri_str = format!("{}/api/articles/latest", local_var_configuration.base_path);
345    let mut local_var_req_builder =
346        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
347
348    if let Some(ref local_var_str) = page {
349        local_var_req_builder =
350            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
351    }
352    if let Some(ref local_var_str) = per_page {
353        local_var_req_builder =
354            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
355    }
356    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
357        local_var_req_builder =
358            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
359    }
360
361    let local_var_req = local_var_req_builder.build()?;
362    let local_var_resp = local_var_client.execute(local_var_req).await?;
363
364    let local_var_status = local_var_resp.status();
365    let local_var_content = local_var_resp.text().await?;
366
367    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
368        serde_json::from_str(&local_var_content).map_err(Error::from)
369    } else {
370        let local_var_entity: Option<GetLatestArticlesError> =
371            serde_json::from_str(&local_var_content).ok();
372        let local_var_error = ResponseContent {
373            status: local_var_status,
374            content: local_var_content,
375            entity: local_var_entity,
376        };
377        Err(Error::ResponseError(local_var_error))
378    }
379}
380
381/// This endpoint allows the client to retrieve a list of Articles belonging to the organization  It supports pagination, each page will contain `30` users by default.
382pub async fn get_org_articles(
383    configuration: &configuration::Configuration,
384    username: &str,
385    page: Option<i32>,
386    per_page: Option<i32>,
387) -> Result<Vec<crate::models::ArticleIndex>, Error<GetOrgArticlesError>> {
388    let local_var_configuration = configuration;
389
390    let local_var_client = &local_var_configuration.client;
391
392    let local_var_uri_str = format!(
393        "{}/api/organizations/{username}/articles",
394        local_var_configuration.base_path,
395        username = crate::apis::urlencode(username)
396    );
397    let mut local_var_req_builder =
398        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
399
400    if let Some(ref local_var_str) = page {
401        local_var_req_builder =
402            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
403    }
404    if let Some(ref local_var_str) = per_page {
405        local_var_req_builder =
406            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
407    }
408    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
409        local_var_req_builder =
410            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
411    }
412
413    let local_var_req = local_var_req_builder.build()?;
414    let local_var_resp = local_var_client.execute(local_var_req).await?;
415
416    let local_var_status = local_var_resp.status();
417    let local_var_content = local_var_resp.text().await?;
418
419    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
420        serde_json::from_str(&local_var_content).map_err(Error::from)
421    } else {
422        let local_var_entity: Option<GetOrgArticlesError> =
423            serde_json::from_str(&local_var_content).ok();
424        let local_var_error = ResponseContent {
425            status: local_var_status,
426            content: local_var_content,
427            entity: local_var_entity,
428        };
429        Err(Error::ResponseError(local_var_error))
430    }
431}
432
433/// This endpoint allows the client to retrieve a list of all articles on behalf of an authenticated user.  \"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.  It will return both published and unpublished articles with pagination.  Unpublished articles will be at the top of the list in reverse chronological creation order. Published articles will follow in reverse chronological publication order.  By default a page will contain 30 articles.
434pub async fn get_user_all_articles(
435    configuration: &configuration::Configuration,
436    page: Option<i32>,
437    per_page: Option<i32>,
438) -> Result<Vec<crate::models::ArticleIndex>, Error<GetUserAllArticlesError>> {
439    let local_var_configuration = configuration;
440
441    let local_var_client = &local_var_configuration.client;
442
443    let local_var_uri_str = format!("{}/api/articles/me/all", local_var_configuration.base_path);
444    let mut local_var_req_builder =
445        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
446
447    if let Some(ref local_var_str) = page {
448        local_var_req_builder =
449            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
450    }
451    if let Some(ref local_var_str) = per_page {
452        local_var_req_builder =
453            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
454    }
455    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
456        local_var_req_builder =
457            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
458    }
459    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
460        let local_var_key = local_var_apikey.key.clone();
461        let local_var_value = match local_var_apikey.prefix {
462            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
463            None => local_var_key,
464        };
465        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
466    };
467
468    let local_var_req = local_var_req_builder.build()?;
469    let local_var_resp = local_var_client.execute(local_var_req).await?;
470
471    let local_var_status = local_var_resp.status();
472    let local_var_content = local_var_resp.text().await?;
473
474    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
475        serde_json::from_str(&local_var_content).map_err(Error::from)
476    } else {
477        let local_var_entity: Option<GetUserAllArticlesError> =
478            serde_json::from_str(&local_var_content).ok();
479        let local_var_error = ResponseContent {
480            status: local_var_status,
481            content: local_var_content,
482            entity: local_var_entity,
483        };
484        Err(Error::ResponseError(local_var_error))
485    }
486}
487
488/// This endpoint allows the client to retrieve a list of published articles on behalf of an authenticated user.  \"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.  Published articles will be in reverse chronological publication order.  It will return published articles with pagination. By default a page will contain 30 articles.
489pub async fn get_user_articles(
490    configuration: &configuration::Configuration,
491    page: Option<i32>,
492    per_page: Option<i32>,
493) -> Result<Vec<crate::models::ArticleIndex>, Error<GetUserArticlesError>> {
494    let local_var_configuration = configuration;
495
496    let local_var_client = &local_var_configuration.client;
497
498    let local_var_uri_str = format!("{}/api/articles/me", local_var_configuration.base_path);
499    let mut local_var_req_builder =
500        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
501
502    if let Some(ref local_var_str) = page {
503        local_var_req_builder =
504            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
505    }
506    if let Some(ref local_var_str) = per_page {
507        local_var_req_builder =
508            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
509    }
510    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
511        local_var_req_builder =
512            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
513    }
514    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
515        let local_var_key = local_var_apikey.key.clone();
516        let local_var_value = match local_var_apikey.prefix {
517            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
518            None => local_var_key,
519        };
520        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
521    };
522
523    let local_var_req = local_var_req_builder.build()?;
524    let local_var_resp = local_var_client.execute(local_var_req).await?;
525
526    let local_var_status = local_var_resp.status();
527    let local_var_content = local_var_resp.text().await?;
528
529    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
530        serde_json::from_str(&local_var_content).map_err(Error::from)
531    } else {
532        let local_var_entity: Option<GetUserArticlesError> =
533            serde_json::from_str(&local_var_content).ok();
534        let local_var_error = ResponseContent {
535            status: local_var_status,
536            content: local_var_content,
537            entity: local_var_entity,
538        };
539        Err(Error::ResponseError(local_var_error))
540    }
541}
542
543/// This endpoint allows the client to retrieve a list of published articles on behalf of an authenticated user.  \"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.  Published articles will be in reverse chronological publication order.  It will return published articles with pagination. By default a page will contain 30 articles.
544pub async fn get_user_published_articles(
545    configuration: &configuration::Configuration,
546    page: Option<i32>,
547    per_page: Option<i32>,
548) -> Result<Vec<crate::models::ArticleIndex>, Error<GetUserPublishedArticlesError>> {
549    let local_var_configuration = configuration;
550
551    let local_var_client = &local_var_configuration.client;
552
553    let local_var_uri_str = format!(
554        "{}/api/articles/me/published",
555        local_var_configuration.base_path
556    );
557    let mut local_var_req_builder =
558        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
559
560    if let Some(ref local_var_str) = page {
561        local_var_req_builder =
562            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
563    }
564    if let Some(ref local_var_str) = per_page {
565        local_var_req_builder =
566            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
567    }
568    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
569        local_var_req_builder =
570            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
571    }
572    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
573        let local_var_key = local_var_apikey.key.clone();
574        let local_var_value = match local_var_apikey.prefix {
575            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
576            None => local_var_key,
577        };
578        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
579    };
580
581    let local_var_req = local_var_req_builder.build()?;
582    let local_var_resp = local_var_client.execute(local_var_req).await?;
583
584    let local_var_status = local_var_resp.status();
585    let local_var_content = local_var_resp.text().await?;
586
587    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
588        serde_json::from_str(&local_var_content).map_err(Error::from)
589    } else {
590        let local_var_entity: Option<GetUserPublishedArticlesError> =
591            serde_json::from_str(&local_var_content).ok();
592        let local_var_error = ResponseContent {
593            status: local_var_status,
594            content: local_var_content,
595            entity: local_var_entity,
596        };
597        Err(Error::ResponseError(local_var_error))
598    }
599}
600
601/// This endpoint allows the client to retrieve a list of unpublished articles on behalf of an authenticated user.  \"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.  Unpublished articles will be in reverse chronological creation order.  It will return unpublished articles with pagination. By default a page will contain 30 articles.
602pub async fn get_user_unpublished_articles(
603    configuration: &configuration::Configuration,
604    page: Option<i32>,
605    per_page: Option<i32>,
606) -> Result<Vec<crate::models::ArticleIndex>, Error<GetUserUnpublishedArticlesError>> {
607    let local_var_configuration = configuration;
608
609    let local_var_client = &local_var_configuration.client;
610
611    let local_var_uri_str = format!(
612        "{}/api/articles/me/unpublished",
613        local_var_configuration.base_path
614    );
615    let mut local_var_req_builder =
616        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
617
618    if let Some(ref local_var_str) = page {
619        local_var_req_builder =
620            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
621    }
622    if let Some(ref local_var_str) = per_page {
623        local_var_req_builder =
624            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
625    }
626    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
627        local_var_req_builder =
628            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
629    }
630    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
631        let local_var_key = local_var_apikey.key.clone();
632        let local_var_value = match local_var_apikey.prefix {
633            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
634            None => local_var_key,
635        };
636        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
637    };
638
639    let local_var_req = local_var_req_builder.build()?;
640    let local_var_resp = local_var_client.execute(local_var_req).await?;
641
642    let local_var_status = local_var_resp.status();
643    let local_var_content = local_var_resp.text().await?;
644
645    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
646        serde_json::from_str(&local_var_content).map_err(Error::from)
647    } else {
648        let local_var_entity: Option<GetUserUnpublishedArticlesError> =
649            serde_json::from_str(&local_var_content).ok();
650        let local_var_error = ResponseContent {
651            status: local_var_status,
652            content: local_var_content,
653            entity: local_var_entity,
654        };
655        Err(Error::ResponseError(local_var_error))
656    }
657}
658
659/// This endpoint allows the client to unpublish an article.  The user associated with the API key must have any 'admin' or 'moderator' role.  The article will be unpublished and will no longer be visible to the public. It will remain in the database and will set back to draft status on the author's posts dashboard. Any notifications associated with the article will be deleted. Any comments on the article will remain.
660pub async fn unpublish_article(
661    configuration: &configuration::Configuration,
662    id: i32,
663    note: Option<&str>,
664) -> Result<(), Error<UnpublishArticleError>> {
665    let local_var_configuration = configuration;
666
667    let local_var_client = &local_var_configuration.client;
668
669    let local_var_uri_str = format!(
670        "{}/api/articles/{id}/unpublish",
671        local_var_configuration.base_path,
672        id = id
673    );
674    let mut local_var_req_builder =
675        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
676
677    if let Some(ref local_var_str) = note {
678        local_var_req_builder =
679            local_var_req_builder.query(&[("note", &local_var_str.to_string())]);
680    }
681    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
682        local_var_req_builder =
683            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
684    }
685    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
686        let local_var_key = local_var_apikey.key.clone();
687        let local_var_value = match local_var_apikey.prefix {
688            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
689            None => local_var_key,
690        };
691        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
692    };
693
694    let local_var_req = local_var_req_builder.build()?;
695    let local_var_resp = local_var_client.execute(local_var_req).await?;
696
697    let local_var_status = local_var_resp.status();
698    let local_var_content = local_var_resp.text().await?;
699
700    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
701        Ok(())
702    } else {
703        let local_var_entity: Option<UnpublishArticleError> =
704            serde_json::from_str(&local_var_content).ok();
705        let local_var_error = ResponseContent {
706            status: local_var_status,
707            content: local_var_content,
708            entity: local_var_entity,
709        };
710        Err(Error::ResponseError(local_var_error))
711    }
712}
713
714/// This endpoint allows the client to update an existing article.  \"Articles\" are all the posts that users create on DEV that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.
715pub async fn update_article(
716    configuration: &configuration::Configuration,
717    id: i32,
718    article: Option<crate::models::Article>,
719) -> Result<(), Error<UpdateArticleError>> {
720    let local_var_configuration = configuration;
721
722    let local_var_client = &local_var_configuration.client;
723
724    let local_var_uri_str = format!(
725        "{}/api/articles/{id}",
726        local_var_configuration.base_path,
727        id = id
728    );
729    let mut local_var_req_builder =
730        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
731
732    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
733        local_var_req_builder =
734            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
735    }
736    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
737        let local_var_key = local_var_apikey.key.clone();
738        let local_var_value = match local_var_apikey.prefix {
739            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
740            None => local_var_key,
741        };
742        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
743    };
744    local_var_req_builder = local_var_req_builder.json(&article);
745
746    let local_var_req = local_var_req_builder.build()?;
747    let local_var_resp = local_var_client.execute(local_var_req).await?;
748
749    let local_var_status = local_var_resp.status();
750    let local_var_content = local_var_resp.text().await?;
751
752    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
753        Ok(())
754    } else {
755        let local_var_entity: Option<UpdateArticleError> =
756            serde_json::from_str(&local_var_content).ok();
757        let local_var_error = ResponseContent {
758            status: local_var_status,
759            content: local_var_content,
760            entity: local_var_entity,
761        };
762        Err(Error::ResponseError(local_var_error))
763    }
764}
765
766/// This endpoint allows the client to retrieve a list of articles that are uploaded with a video.  It will only return published video articles ordered by descending popularity.  It supports pagination, each page will contain 24 articles by default.
767pub async fn videos(
768    configuration: &configuration::Configuration,
769    page: Option<i32>,
770    per_page: Option<i32>,
771) -> Result<Vec<crate::models::VideoArticle>, Error<VideosError>> {
772    let local_var_configuration = configuration;
773
774    let local_var_client = &local_var_configuration.client;
775
776    let local_var_uri_str = format!("{}/api/videos", local_var_configuration.base_path);
777    let mut local_var_req_builder =
778        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
779
780    if let Some(ref local_var_str) = page {
781        local_var_req_builder =
782            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
783    }
784    if let Some(ref local_var_str) = per_page {
785        local_var_req_builder =
786            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
787    }
788    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
789        local_var_req_builder =
790            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
791    }
792
793    let local_var_req = local_var_req_builder.build()?;
794    let local_var_resp = local_var_client.execute(local_var_req).await?;
795
796    let local_var_status = local_var_resp.status();
797    let local_var_content = local_var_resp.text().await?;
798
799    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
800        serde_json::from_str(&local_var_content).map_err(Error::from)
801    } else {
802        let local_var_entity: Option<VideosError> = serde_json::from_str(&local_var_content).ok();
803        let local_var_error = ResponseContent {
804            status: local_var_status,
805            content: local_var_content,
806            entity: local_var_entity,
807        };
808        Err(Error::ResponseError(local_var_error))
809    }
810}