Skip to content

CMM-1202 create the stats country endpoint#1131

Merged
jkmassel merged 12 commits into
trunkfrom
task/CMM-1202-create-the-stats-country-endpoint
Feb 5, 2026
Merged

CMM-1202 create the stats country endpoint#1131
jkmassel merged 12 commits into
trunkfrom
task/CMM-1202-create-the-stats-country-endpoint

Conversation

@adalpari
Copy link
Copy Markdown
Contributor

Summary

  • Add new stats/country-views endpoint for WordPress.com REST API v1.1
  • Returns location/country-based view statistics with support for both summary and per-day breakdown modes
  • All response fields support null values for robust API handling

Changes

New files:

  • wp_api/src/wp_com/stats_country_views.rs - Type definitions and parameters
  • wp_api/src/wp_com/endpoint/stats_country_views_endpoint.rs - Endpoint implementation
  • wp_api/tests/wpcom/stats_country_views/*.json - Test fixtures for parameterized tests

Types added:

  • StatsCountryViewsPeriod - Period enum (day, week, month, year)
  • StatsCountryViewsParams - Query parameters (period, date, start_date, max, num, days, locale, summarize)
  • StatsCountryViewsResponse - Response with summary or days depending on summarize parameter
  • StatsCountryInfo - Country metadata (flag icons, country name, map region)
  • StatsCountryView - Individual country view entry (location, views, country_code)

Response modes:

  • summarize=0 (default): Returns days field with per-day breakdown keyed by date
  • summarize=1: Returns summary field with aggregated country views

Test plan

  • Unit tests for parameter serialization
  • Parameterized tests for JSON deserialization covering summary, days, null values, and empty responses
  • Lint passes (cargo fmt, cargo clippy)

@adalpari adalpari marked this pull request as ready for review January 29, 2026 10:51
@adalpari adalpari requested a review from jkmassel February 4, 2026 18:21
@adalpari
Copy link
Copy Markdown
Contributor Author

adalpari commented Feb 4, 2026

@jkmassel I added the remaining stuff to this endpoint:

  • WPComLanguage
  • Renaming and parametrizing json deserialization tests
  • e2e test

/// - `Some(false)` (summarize=0, default): Response contains `days` field with a per-day
/// breakdown of country views, where each day is keyed by its date string. The `summary`
/// field will be absent.
#[uniffi(default = Some(false))]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should match the endpoints from the last PR – if we think this should be true by default we should have it be default=true and remove the optionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I forgot about this 🤦
Done

@jkmassel jkmassel force-pushed the task/CMM-1202-create-the-stats-country-endpoint branch from 4aa8913 to 9208e76 Compare February 5, 2026 19:04
}

#[test]
fn test_stats_country_views_response_deserialization_summary_01() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be its own test?

It seems to be mostly covered by the test above – should we add more parameters to it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small difference between these tests. The above one is a lightweight sanity check test for general purposes (parameterised), while this one is more about checking the detailed values. Si, it's not only checking the deserialisation, but checking that the expected values are present.
Hence, I think that both tests add value in their way. Plus, I think that having extra tests is harmless.

Does it make sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's not hurting anything, so I'm fine to leave it :)

@jkmassel jkmassel merged commit ceb966c into trunk Feb 5, 2026
23 checks passed
@jkmassel jkmassel deleted the task/CMM-1202-create-the-stats-country-endpoint branch February 5, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants