dialtone_reqwest 0.1.0

Dialtone HTTP Reqwest Client Library
Documentation
use chrono::{DateTime, Utc};
use dialtone_common::{
    ap::ActorType,
    rest::{
        actors::{actor_model::ActorPage, actor_pages_exchanges::GetActorPagesByHostRequest},
        api_paths::full_path::ACTOR_PAGES__BY_HOST,
    },
};

use crate::{dt_reqwest_error::DtReqwestError, site_connection::SiteConnection};

pub async fn page_actors_by_host(
    sc: &SiteConnection,
    host: Option<&str>,
    prev_date: Option<&DateTime<Utc>>,
    next_date: Option<&DateTime<Utc>>,
    limit: u32,
    actor_type: Option<&ActorType>,
) -> Result<ActorPage, DtReqwestError> {
    let host = match host {
        Some(host) => host,
        None => sc.host_name(),
    };
    let request = GetActorPagesByHostRequest {
        prev_date: prev_date.cloned(),
        next_date: next_date.cloned(),
        limit,
        actor_type: actor_type.cloned(),
        host_name: host.to_owned(),
    };
    let response = sc
        .get(ACTOR_PAGES__BY_HOST, &[])
        .query(&request)
        .send()
        .await?
        .error_for_status()?
        .json()
        .await?;
    Ok(response)
}