Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- WordPress.com `GET /sites/<site_id>/purchases` endpoint for listing a site's purchases (plans, domains, and other subscriptions)
- Publish the Kotlin bindings' per-endpoint Markdown API reference as an `ai-docs` Maven classifier zip on `rs.wordpress.api:kotlin`, generated from the UniFFI bindings for agent/tooling consumption
- WordPress.com `POST /sites/<site_id>/domains/primary` endpoint for setting a site's primary domain
- WordPress.com `GET /sites/<site_id>/stats/post/<post_id>` endpoint for a post's view history, like count, comment count, and metadata
- WordPress.com `GET /sites/<site_id>/plans` endpoint for listing the plans a site can buy, priced for that site, with the plan it's currently on flagged.
- `RequestExecutionErrorReason` gained `isSiteUnreachable` and `isDeviceOffline` for distinguishing a site that could not be reached (most reliably, a DNS failure) from a device with no network connection. Previously consumers had to match the `NonExistentSiteError` / `DeviceIsOfflineError` variants themselves. Available on both platforms as properties on the reason, which is reachable from `WpRequestResult.RequestExecutionFailed` and `WpApiException.RequestExecutionFailed` on Kotlin. Swift additionally exposes both as convenience properties on `WpApiError` and `RequestExecutionError`.

Expand Down
2 changes: 1 addition & 1 deletion WPCOM_REST_API_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ investigate the relevant code before making decisions based on this document.
- [ ] `GET /rest/v1.1/sites/$site/stats/comments` — top commenters and most-commented posts
- [ ] `GET /rest/v1.1/sites/$site/stats/followers` — site followers (filterable by type)
- [x] `GET /rest/v1.1/sites/$site/stats/insights` — most popular day/hour, yearly aggregates
- [ ] `GET /rest/v1.1/sites/$site/stats/post/$post_id` — per-post view stats
- [x] `GET /rest/v1.1/sites/$site/stats/post/$post_id` — per-post view stats
- [ ] `GET /rest/v1.1/sites/$site/stats/publicize` — social media follower counts
- [ ] `GET /rest/v1.1/sites/$site/stats/streak` — posting activity/streak data
- [ ] `GET /rest/v1.1/sites/$site/stats/summary` — total likes, comments, followers
Expand Down
6 changes: 6 additions & 0 deletions wp_api/src/wp_com/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use super::endpoint::{
StatsFileDownloadsRequestBuilder, StatsFileDownloadsRequestExecutor,
},
stats_insights_endpoint::{StatsInsightsRequestBuilder, StatsInsightsRequestExecutor},
stats_post_endpoint::{StatsPostRequestBuilder, StatsPostRequestExecutor},
stats_referrers_endpoint::{StatsReferrersRequestBuilder, StatsReferrersRequestExecutor},
stats_region_views_endpoint::{
StatsRegionViewsRequestBuilder, StatsRegionViewsRequestExecutor,
Expand Down Expand Up @@ -96,6 +97,7 @@ pub struct WpComApiRequestBuilder {
stats_emails_summary: Arc<StatsEmailsSummaryRequestBuilder>,
stats_devices_platform: Arc<StatsDevicesPlatformRequestBuilder>,
stats_devices_screensize: Arc<StatsDevicesScreensizeRequestBuilder>,
stats_post: Arc<StatsPostRequestBuilder>,
stats_referrers: Arc<StatsReferrersRequestBuilder>,
stats_subscribers: Arc<StatsSubscribersRequestBuilder>,
stats_region_views: Arc<StatsRegionViewsRequestBuilder>,
Expand Down Expand Up @@ -144,6 +146,7 @@ impl WpComApiRequestBuilder {
stats_emails_summary,
stats_devices_platform,
stats_devices_screensize,
stats_post,
stats_referrers,
stats_subscribers,
stats_region_views,
Expand Down Expand Up @@ -203,6 +206,7 @@ pub struct WpComApiClient {
stats_emails_summary: Arc<StatsEmailsSummaryRequestExecutor>,
stats_devices_platform: Arc<StatsDevicesPlatformRequestExecutor>,
stats_devices_screensize: Arc<StatsDevicesScreensizeRequestExecutor>,
stats_post: Arc<StatsPostRequestExecutor>,
stats_referrers: Arc<StatsReferrersRequestExecutor>,
stats_subscribers: Arc<StatsSubscribersRequestExecutor>,
stats_region_views: Arc<StatsRegionViewsRequestExecutor>,
Expand Down Expand Up @@ -252,6 +256,7 @@ impl WpComApiClient {
stats_emails_summary,
stats_devices_platform,
stats_devices_screensize,
stats_post,
stats_referrers,
stats_subscribers,
stats_region_views,
Expand Down Expand Up @@ -294,6 +299,7 @@ api_client_generate_endpoint_impl!(WpComApi, stats_devices_browser);
api_client_generate_endpoint_impl!(WpComApi, stats_emails_summary);
api_client_generate_endpoint_impl!(WpComApi, stats_devices_platform);
api_client_generate_endpoint_impl!(WpComApi, stats_devices_screensize);
api_client_generate_endpoint_impl!(WpComApi, stats_post);
api_client_generate_endpoint_impl!(WpComApi, stats_referrers);
api_client_generate_endpoint_impl!(WpComApi, stats_subscribers);
api_client_generate_endpoint_impl!(WpComApi, stats_region_views);
Expand Down
1 change: 1 addition & 0 deletions wp_api/src/wp_com/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod stats_devices_screensize_endpoint;
pub mod stats_emails_summary_endpoint;
pub mod stats_file_downloads_endpoint;
pub mod stats_insights_endpoint;
pub mod stats_post_endpoint;
pub mod stats_referrers_endpoint;
pub mod stats_region_views_endpoint;
pub mod stats_search_terms_endpoint;
Expand Down
70 changes: 70 additions & 0 deletions wp_api/src/wp_com/endpoint/stats_post_endpoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use crate::{
request::endpoint::{AsNamespace, DerivedRequest},
wp_com::{
WpComNamespace, WpComSiteId,
stats_post::{StatsPostResponse, StatsPostTarget},
},
};
use wp_derive_request_builder::WpDerivedRequest;

#[derive(WpDerivedRequest)]
enum StatsPostRequest {
#[get(url = "/sites/<wp_com_site_id>/stats/post/<stats_post_target>", output = StatsPostResponse)]
GetStatsPost,
}

impl DerivedRequest for StatsPostRequest {
fn namespace(&self) -> impl AsNamespace {
WpComNamespace::RestV1_1
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{
posts::PostId,
request::endpoint::ApiUrlResolver,
wp_com::endpoint::tests::{
fixture_wp_com_api_url_resolver, validate_wp_com_rest_v1_1_endpoint,
},
};
use rstest::*;
use std::sync::Arc;

#[rstest]
#[case::numeric_id(
WpComSiteId(12345),
StatsPostTarget::Post { id: PostId(2729) },
"/sites/12345/stats/post/2729"
)]
#[case::large_ids(
WpComSiteId(229889220),
StatsPostTarget::Post { id: PostId(9007199254740991) },
"/sites/229889220/stats/post/9007199254740991"
)]
// The API addresses the site's home page as post 0.
#[case::home_page(
WpComSiteId(12345),
StatsPostTarget::HomePage,
"/sites/12345/stats/post/0"
)]
fn get_stats_post(
endpoint: StatsPostRequestEndpoint,
#[case] site_id: WpComSiteId,
#[case] target: StatsPostTarget,
#[case] expected_path: &str,
) {
validate_wp_com_rest_v1_1_endpoint(
endpoint.get_stats_post(&site_id, &target),
expected_path,
);
}

#[fixture]
fn endpoint(
fixture_wp_com_api_url_resolver: Arc<dyn ApiUrlResolver>,
) -> StatsPostRequestEndpoint {
StatsPostRequestEndpoint::new(fixture_wp_com_api_url_resolver)
}
}
1 change: 1 addition & 0 deletions wp_api/src/wp_com/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod stats_devices;
pub mod stats_emails_summary;
pub mod stats_file_downloads;
pub mod stats_insights;
pub mod stats_post;
pub mod stats_referrers;
pub mod stats_region_views;
pub mod stats_search_terms;
Expand Down
Loading