/// Make a query to the Mattermost instance API.
///
/// This method is "raw" in that the calling code must
/// supply the method, query parameters, body, **and**
/// a struct for the shape of the data returned (or
/// `serde_json::Value` for "dynamic" data).
///
/// Developers are encouraged to look for a specific endpoint
/// function that is for the API endpoint that is desired,
/// but this function is exposed to calling code so that
/// this library can be more flexible.
Make a query to the Mattermost instance API.
This method is "raw" in that the calling code must
supply the method, query parameters, body, **and
a struct for the shape of the data returned (or
`serde_json::Value` for "dynamic" data).

Developers are encouraged to look for a specific endpoint
function that is for the API endpoint that is desired,
but this function is exposed to calling code so that
this library can be more flexible.
Make a query to the Mattermost instance API . This method is " raw " in that the calling code must supply the method query parameters body ** and a struct for the shape of the data returned ( or ` serde_json :: Value ` for " dynamic " data ) . Developers are encouraged to look for a specific endpoint function that is for the API endpoint that is desired but this function is exposed to calling code so that this library can be more flexible .
pub async fn query<T: DeserializeOwned>(
        &self,
        method: &str,
        endpoint: &str,
        query: Option<&[(&str, &str)]>,
        body: Option<&str>,
    ) -> Result<T, ApiError> {
        let url = format!("{}/api/v4/{}", self.instance_url, endpoint);
        debug!(
            "Making {} request to {} with query {:?}",
            method, url, query
        );
        let mut req_builder = self
            .client
            .request(Method::from_str(method)?, &url)
            .headers(self.request_headers()?)
            .query(query.unwrap_or(&[]));
        req_builder = match body {
            Some(b) => req_builder.body(b.to_owned()),
            None => req_builder,
        };
        let resp = self.client.execute(req_builder.build()?).await?;
        if !resp.status().is_success() {
            error!(
                "Got status {} when requesting data from {}",
                resp.status(),
                url
            );
            let status = resp.status().as_u16();
            // attempt to get the standard error information out and return that
            if let Ok(text) = resp.text().await {
                if let Ok(data) = serde_json::from_str::<MattermostError>(&text) {
                    return Err(ApiError::MattermostApiError(data));
                }
            }
            // fallback to generic HTTP status code error
            return Err(ApiError::StatusCodeError(status));
        }
        Ok(resp.json().await?)
    }
pub async fn query < T : DeserializeOwned > ( & self , method : & str , endpoint : & str , query : Option < & [ ( & str , & str ) ] > , body : Option < & str > , ) -> Result < T , ApiError > { let url = format ! ( " " self instance_url endpoint ) ; debug ! ( " " method url query ) ; let mut req_builder = self . client . request ( Method :: from_str ( method ) ? , & url ) . headers ( self . request_headers ( ) ? ) . query ( query . unwrap_or ( & [ ] ) ) ; req_builder = match body { Some ( b ) => req_builder . body ( b . to_owned ( ) ) , None => req_builder , } ; let resp = self . client . execute ( req_builder . build ( ) ? ) . await ? ; if ! resp . status ( ) . is_success ( ) { error ! ( " " resp status ( ) url ) ; let status = resp . status ( ) . as_u16 ( ) ; // attempt to get the standard error information out and return that if let Ok ( text ) = resp . text ( ) . await { if let Ok ( data ) = serde_json :: from_str :: < MattermostError > ( & text ) { return Err ( ApiError :: MattermostApiError ( data ) ) ; } } // fallback to generic HTTP status code error return Err ( ApiError :: StatusCodeError ( status ) ) ; } Ok ( resp . json ( ) . await ? ) }
Make a query to the Mattermost instance API.
Make a query to the Mattermost instance API .
&self
method
&str
endpoint
&str
query
Option<&[(&str, &str)]>
body
Option<&str>