use serde_json::Value;
use crate::models::{
ActionPage, Download, Outlink, ReferrerAll, ReferrerType, Visit, VisitsSummary,
};
use crate::params::{IdSite, Period, Segment};
use crate::request::Params;
use crate::transport::Endpoint;
fn base(id_site: IdSite, period: Period, segment: Option<Segment>) -> Params {
let mut params = Params::new().id_site(id_site).period(period);
if let Some(s) = segment {
params = params.segment(s);
}
params
}
pub struct VisitsSummaryGet {
pub id_site: IdSite,
pub period: Period,
pub segment: Option<Segment>,
}
impl Endpoint for VisitsSummaryGet {
type Response = VisitsSummary;
fn method(&self) -> &'static str {
"VisitsSummary.get"
}
fn params(&self) -> Params {
base(self.id_site.clone(), self.period, self.segment.clone())
}
}
pub struct LiveGetLastVisitsDetails {
pub params: Params,
}
impl Endpoint for LiveGetLastVisitsDetails {
type Response = Vec<Visit>;
fn method(&self) -> &'static str {
"Live.getLastVisitsDetails"
}
fn params(&self) -> Params {
self.params.clone()
}
}
macro_rules! actions_endpoint {
($name:ident, $method:literal, $resp:ty) => {
pub struct $name {
pub id_site: IdSite,
pub period: Period,
pub segment: Option<Segment>,
}
impl Endpoint for $name {
type Response = $resp;
fn method(&self) -> &'static str {
$method
}
fn params(&self) -> Params {
base(self.id_site.clone(), self.period, self.segment.clone())
}
}
};
}
actions_endpoint!(ActionsGetPageUrls, "Actions.getPageUrls", Vec<ActionPage>);
actions_endpoint!(
ActionsGetPageTitles,
"Actions.getPageTitles",
Vec<ActionPage>
);
actions_endpoint!(ActionsGetDownloads, "Actions.getDownloads", Vec<Download>);
actions_endpoint!(ActionsGetOutlinks, "Actions.getOutlinks", Vec<Outlink>);
actions_endpoint!(
ReferrersGetReferrerType,
"Referrers.getReferrerType",
Vec<ReferrerType>
);
actions_endpoint!(ReferrersGetAll, "Referrers.getAll", Vec<ReferrerAll>);
pub struct ApiGetMatomoVersion;
impl Endpoint for ApiGetMatomoVersion {
type Response = Value;
fn method(&self) -> &'static str {
"API.getMatomoVersion"
}
fn params(&self) -> Params {
Params::new()
}
}
pub struct ApiGetReportMetadata {
pub params: Params,
}
impl Endpoint for ApiGetReportMetadata {
type Response = Value;
fn method(&self) -> &'static str {
"API.getReportMetadata"
}
fn params(&self) -> Params {
self.params.clone()
}
}
pub struct ApiGetBulkRequest {
pub params: Params,
}
impl Endpoint for ApiGetBulkRequest {
type Response = Value;
fn method(&self) -> &'static str {
"API.getBulkRequest"
}
fn params(&self) -> Params {
self.params.clone()
}
}