azisaba-graph 0.1.0-rc.16

An API for connecting and sharing data across the Azisaba Network.
Documentation
/*
 * Azisaba Graph API
 *
 * An API for connecting and sharing data across the Azisaba Network.
 *
 * The version of the OpenAPI document: 0.0.1
 * 
 * Generated by: https://openapi-generator.tech
 */


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

/// struct for passing parameters to the method [`create_crawl`]
#[derive(Clone, Debug)]
pub struct CreateCrawlParams {
    pub create_crawl_request: models::CreateCrawlRequest
}

/// struct for passing parameters to the method [`delete_crawl_by_id`]
#[derive(Clone, Debug)]
pub struct DeleteCrawlByIdParams {
    /// The unique identifier of the crawl.
    pub crawl_id: String
}

/// struct for passing parameters to the method [`get_crawl_by_id`]
#[derive(Clone, Debug)]
pub struct GetCrawlByIdParams {
    /// The unique identifier of the crawl.
    pub crawl_id: String
}

/// struct for passing parameters to the method [`list_crawls`]
#[derive(Clone, Debug)]
pub struct ListCrawlsParams {
    /// The maximum number of crawls to return.
    pub limit: Option<u8>,
    /// The cursor returned by the previous request.
    pub cursor: Option<String>,
    /// The address used to filter crawls.
    pub address: Option<String>,
    /// The port used to filter crawls.
    pub port: Option<u16>,
    /// The version used to filter crawls.
    pub version: Option<String>,
    /// The protocol version used to filter crawls.
    pub protocol_version: Option<i32>,
    /// The inclusive lower bound of the crawl date and time.
    pub crawled_from: Option<chrono::DateTime<chrono::FixedOffset>>,
    /// The exclusive upper bound of the crawl date and time.
    pub crawled_to: Option<chrono::DateTime<chrono::FixedOffset>>
}


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

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

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

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


/// Creates a new crawl.
pub async fn create_crawl(configuration: &configuration::Configuration, params: CreateCrawlParams) -> Result<models::Crawl, Error<CreateCrawlError>> {

    let uri_str = format!("{}/crawls", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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());
    };
    req_builder = req_builder.json(&params.create_crawl_request);

    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::Crawl`"))),
            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::Crawl`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreateCrawlError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Deletes the crawl with the specified ID.
pub async fn delete_crawl_by_id(configuration: &configuration::Configuration, params: DeleteCrawlByIdParams) -> Result<(), Error<DeleteCrawlByIdError>> {

    let uri_str = format!("{}/crawls/{crawlId}", configuration.base_path, crawlId=crate::apis::urlencode(params.crawl_id));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteCrawlByIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Returns the crawl with the specified ID.
pub async fn get_crawl_by_id(configuration: &configuration::Configuration, params: GetCrawlByIdParams) -> Result<models::Crawl, Error<GetCrawlByIdError>> {

    let uri_str = format!("{}/crawls/{crawlId}", configuration.base_path, crawlId=crate::apis::urlencode(params.crawl_id));
    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::Crawl`"))),
            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::Crawl`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetCrawlByIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Returns a list of crawls.
pub async fn list_crawls(configuration: &configuration::Configuration, params: ListCrawlsParams) -> Result<models::ListCrawls200Response, Error<ListCrawlsError>> {

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

    if let Some(ref param_value) = params.limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.cursor {
        req_builder = req_builder.query(&[("cursor", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.address {
        req_builder = req_builder.query(&[("address", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.port {
        req_builder = req_builder.query(&[("port", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.version {
        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.protocol_version {
        req_builder = req_builder.query(&[("protocolVersion", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.crawled_from {
        req_builder = req_builder.query(&[("crawledFrom", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.crawled_to {
        req_builder = req_builder.query(&[("crawledTo", &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::ListCrawls200Response`"))),
            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::ListCrawls200Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<ListCrawlsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}