matomo-rs 0.1.0

Async client for the Matomo Reporting API, focused on data export and migration
Documentation
//! HTTP client-agnostic Rust bindings for the Matomo Reporting API, focused on
//! data export and migration.
//!
//! The crate is split into a transport-agnostic core ([`Client`], [`Endpoint`],
//! [`Query`]) and an optional [`reqwest`]-backed transport behind a feature
//! flag. Bring your own HTTP client by implementing [`Client`].
//!
//! Matomo's API is a single dispatch endpoint: every call is a
//! `POST {base}/index.php` with a `module=API&method=Module.action&format=json`
//! form body. Errors arrive as HTTP 200 with a `{"result":"error",...}` JSON
//! envelope rather than via status codes, so [`Endpoint::parse_response`]
//! detects that envelope instead of mapping status codes.
//!
//! # Features
//!
//! - `reqwest` — enables [`crate::reqwest::MatomoClient`], a ready-made
//!   [`Client`]. No TLS backend is selected by default; pair it with one below.
//! - `reqwest-rustls` — `reqwest` with `rustls`.
//! - `reqwest-native-tls` — `reqwest` with the OS-native TLS stack.
//! - `chrono` / `time` — `From` conversions into [`Date`].
//!
//! All features are off by default. If none of the `reqwest-*` features fit,
//! implement [`Client`] yourself against any HTTP backend.

#![forbid(unsafe_code)]

mod auth;
mod de;
pub mod endpoints;
mod error;
mod models;
mod params;
mod request;
mod transport;

pub use auth::Auth;
pub use error::{ApiErrorKind, Error, Result};
pub use models::{
    ActionDetail, ActionPage, Download, GoalConversion, Outlink, ReferrerAll, ReferrerType, Visit,
    VisitorType, VisitsSummary,
};
pub use params::{Date, DateRange, IdSite, Limit, Period, RangeEnd, Segment};
pub use request::Params;
pub use transport::{Client, Endpoint, ParseError, Query, QueryError};

#[cfg(feature = "reqwest")]
pub mod reqwest;

/// Back-compat alias: the reqwest-backed concrete client also answers to
/// `matomo::MatomoClient`, but the ergonomic entry point most code reaches for
/// is here as `matomo::reqwest::MatomoClient`.
#[cfg(feature = "reqwest")]
pub use reqwest::{Cursor, MatomoClient, MatomoClientError, VisitStream};

#[cfg(feature = "chrono")]
impl From<chrono::NaiveDate> for Date {
    fn from(d: chrono::NaiveDate) -> Self {
        use chrono::Datelike;
        Date::Ymd(d.year() as u16, d.month() as u8, d.day() as u8)
    }
}

#[cfg(feature = "time")]
impl From<time::Date> for Date {
    fn from(d: time::Date) -> Self {
        Date::Ymd(d.year() as u16, u8::from(d.month()), d.day())
    }
}