mattermost_rust_client/apis/
open_graph_api.rs

1/*
2 * Mattermost API Reference
3 *
4 * There is also a work-in-progress [Postman API reference](https://documenter.getpostman.com/view/4508214/RW8FERUn). 
5 *
6 * The version of the OpenAPI document: 4.0.0
7 * Contact: feedback@mattermost.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`open_graph`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum OpenGraphError {
22    Status501(crate::models::AppError),
23    UnknownValue(serde_json::Value),
24}
25
26
27/// Get Open Graph Metadata for a specif URL. Use the Open Graph protocol to get some generic metadata about a URL. Used for creating link previews.  __Minimum server version__: 3.10  ##### Permissions No permission required but must be logged in. 
28pub async fn open_graph(configuration: &configuration::Configuration, open_graph_request: crate::models::OpenGraphRequest) -> Result<crate::models::OpenGraph, Error<OpenGraphError>> {
29    let local_var_configuration = configuration;
30
31    let local_var_client = &local_var_configuration.client;
32
33    let local_var_uri_str = format!("{}/opengraph", local_var_configuration.base_path);
34    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
35
36    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
37        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
38    }
39    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
40        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
41    };
42    local_var_req_builder = local_var_req_builder.json(&open_graph_request);
43
44    let local_var_req = local_var_req_builder.build()?;
45    let local_var_resp = local_var_client.execute(local_var_req).await?;
46
47    let local_var_status = local_var_resp.status();
48    let local_var_content = local_var_resp.text().await?;
49
50    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
51        serde_json::from_str(&local_var_content).map_err(Error::from)
52    } else {
53        let local_var_entity: Option<OpenGraphError> = serde_json::from_str(&local_var_content).ok();
54        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
55        Err(Error::ResponseError(local_var_error))
56    }
57}
58