forem_openapi_client/apis/
profile_images_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 [`get_profile_image`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetProfileImageError {
20    Status404(),
21    UnknownValue(serde_json::Value),
22}
23
24/// This endpoint allows the client to retrieve a user or organization profile image information by its         corresponding username.
25pub async fn get_profile_image(
26    configuration: &configuration::Configuration,
27    username: &str,
28) -> Result<Vec<crate::models::ProfileImage>, Error<GetProfileImageError>> {
29    let local_var_configuration = configuration;
30
31    let local_var_client = &local_var_configuration.client;
32
33    let local_var_uri_str = format!(
34        "{}/api/profile_images/{username}",
35        local_var_configuration.base_path,
36        username = crate::apis::urlencode(username)
37    );
38    let mut local_var_req_builder =
39        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
40
41    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
42        local_var_req_builder =
43            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
44    }
45    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
46        let local_var_key = local_var_apikey.key.clone();
47        let local_var_value = match local_var_apikey.prefix {
48            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
49            None => local_var_key,
50        };
51        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
52    };
53
54    let local_var_req = local_var_req_builder.build()?;
55    let local_var_resp = local_var_client.execute(local_var_req).await?;
56
57    let local_var_status = local_var_resp.status();
58    let local_var_content = local_var_resp.text().await?;
59
60    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
61        serde_json::from_str(&local_var_content).map_err(Error::from)
62    } else {
63        let local_var_entity: Option<GetProfileImageError> =
64            serde_json::from_str(&local_var_content).ok();
65        let local_var_error = ResponseContent {
66            status: local_var_status,
67            content: local_var_content,
68            entity: local_var_entity,
69        };
70        Err(Error::ResponseError(local_var_error))
71    }
72}