wordstat-rs 0.1.0

A library that allows easy interactions with Yandex Direct API for getting statistics about keyword searches from Wordstat service
Documentation
use serde_json::Value;
use crate::{WordstatError, check_status};
use crate::client::Client;

/// Sends the request to the API using Wordstat client to delete the report with
/// the passed report_id.
pub async fn delete_report(client: &Client, report_id: i64) -> Result<(), WordstatError> {
    let method = "DeleteWordstatReport";
    let params = Value::Number(report_id.into());
    let result = client.post(method, Some(params)).await?;

    check_status(&result)?;
    let Some(data_val) = result.get("data") else { return Err(WordstatError::BadResponse{ reason: "Data field not found in response" }) };
    let Some(return_code) = data_val.as_i64() else { return Err(WordstatError::BadResponse{ reason: "Data field is not an integer" }) };

    if return_code != 1 {
        Err(WordstatError::UnknownError)
    }
    else {
        Ok(())
    }
}