line-bot-sdk-insight 0.1.0

This document describes LINE Messaging API(Insight).
Documentation
/*
 * LINE Messaging API(Insight)
 *
 * This document describes LINE Messaging API(Insight).
 *
 * The version of the OpenAPI document: 0.0.1
 *
 * Generated by: https://openapi-generator.tech
 */

use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};

/// struct for typed errors of method [`get_friends_demographics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFriendsDemographicsError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_message_event`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMessageEventError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_number_of_followers`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetNumberOfFollowersError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_number_of_message_deliveries`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetNumberOfMessageDeliveriesError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_statistics_per_unit`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetStatisticsPerUnitError {
    UnknownValue(serde_json::Value),
}

/// Retrieves the demographic attributes for a LINE Official Account's friends.You can only retrieve information about friends for LINE Official Accounts created by users in Japan (JP), Thailand (TH), Taiwan (TW) and Indonesia (ID).
pub async fn get_friends_demographics(
    configuration: &configuration::Configuration,
) -> Result<models::GetFriendsDemographicsResponse, Error<GetFriendsDemographicsError>> {
    let uri_str = format!("{}/v2/bot/insight/demographic", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetFriendsDemographicsResponse`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetFriendsDemographicsResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetFriendsDemographicsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
pub async fn get_message_event(
    configuration: &configuration::Configuration,
    request_id: &str,
) -> Result<models::GetMessageEventResponse, Error<GetMessageEventError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_request_id = request_id;

    let uri_str = format!("{}/v2/bot/insight/message/event", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("requestId", &p_query_request_id.to_string())]);
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetMessageEventResponse`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetMessageEventResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetMessageEventError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Returns the number of users who have added the LINE Official Account on or before a specified date.
pub async fn get_number_of_followers(
    configuration: &configuration::Configuration,
    date: Option<&str>,
) -> Result<models::GetNumberOfFollowersResponse, Error<GetNumberOfFollowersError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_date = date;

    let uri_str = format!("{}/v2/bot/insight/followers", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_date {
        req_builder = req_builder.query(&[("date", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetNumberOfFollowersResponse`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetNumberOfFollowersResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetNumberOfFollowersError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Returns the number of messages sent from LINE Official Account on a specified day.
pub async fn get_number_of_message_deliveries(
    configuration: &configuration::Configuration,
    date: &str,
) -> Result<models::GetNumberOfMessageDeliveriesResponse, Error<GetNumberOfMessageDeliveriesError>>
{
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_date = date;

    let uri_str = format!(
        "{}/v2/bot/insight/message/delivery",
        configuration.base_path
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("date", &p_query_date.to_string())]);
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetNumberOfMessageDeliveriesResponse`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetNumberOfMessageDeliveriesResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetNumberOfMessageDeliveriesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// You can check the per-unit statistics of how users interact with push messages and multicast messages sent from your LINE Official Account.
pub async fn get_statistics_per_unit(
    configuration: &configuration::Configuration,
    custom_aggregation_unit: &str,
    from: &str,
    to: &str,
) -> Result<models::GetStatisticsPerUnitResponse, Error<GetStatisticsPerUnitError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_custom_aggregation_unit = custom_aggregation_unit;
    let p_query_from = from;
    let p_query_to = to;

    let uri_str = format!(
        "{}/v2/bot/insight/message/event/aggregation",
        configuration.base_path
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[(
        "customAggregationUnit",
        &p_query_custom_aggregation_unit.to_string(),
    )]);
    req_builder = req_builder.query(&[("from", &p_query_from.to_string())]);
    req_builder = req_builder.query(&[("to", &p_query_to.to_string())]);
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetStatisticsPerUnitResponse`"))),
            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetStatisticsPerUnitResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetStatisticsPerUnitError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}