CMM-1177/CMM-1178 create the top post and referrers endpoints#1119
CMM-1177/CMM-1178 create the top post and referrers endpoints#1119
Conversation
jkmassel
left a comment
There was a problem hiding this comment.
Good start – this properly parsed both https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/stats/referrers and https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/stats/top-posts (with summarize=1).
Left some inline suggestions.
|
|
||
| /// Parameters for the stats referrers endpoint. | ||
| #[derive(Debug, Default, PartialEq, Eq, uniffi::Record)] | ||
| pub struct StatsReferrersParams { |
There was a problem hiding this comment.
This needs to take a locale param – that's used to translate the response's strings (for example "Search Engines").
It should probably be an enum that matches WP.com locales - @crazytonyli wdyt about using WPComLanguage from #1011?
There was a problem hiding this comment.
wdyt about using WPComLanguage?
That makes sense to me. I presume the local argument in this request is treated as the same as WPComLanguage.slug in the backend.
wp_api/src/wp_com/stats_referrers.rs
Outdated
| #[rstest] | ||
| #[case("tests/wpcom/stats_referrers/referrers-01.json")] | ||
| #[case("tests/wpcom/stats_referrers/referrers-03-follow-data-false.json")] | ||
| #[case("tests/wpcom/stats_referrers/referrers-04-real-response.json")] |
There was a problem hiding this comment.
This is a good parameterized test, but should include all of the test cases you've defined. Even if they're used for a more specific test, running every valid json test case you have through the generic deserialization test is more likely to catch issues.
Said another way – you have the data anyway, might as well use it :)
There was a problem hiding this comment.
You are right. The problem is that because of the endpoint specifications, some JSON files are different.
For instance, referrers-02-days.json has no period field. So, it cannot be included in this general test.
However, there's a specific test for it.
Note: I've added referrers-05-with-nulls.json, though, and an extra check.
Done here: 2c589f4
There was a problem hiding this comment.
For instance,
referrers-02-days.jsonhas no period field
This seems odd – https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/stats/referrers?summarize=1&period=day has a period field, but https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/stats/referrers?period=day does not. Should we be using the former?
2c589f4 to
8f31d58
Compare
8f31d58 to
d0ec9a0
Compare
|
To help land this quicker, I've:
Still to do – if we really need both |
Thank you!!
We are already supporting both outputs. In tests, we can parse both as well (but in different tests). I've tried to follow your suggestion about "baking it into the test definition". So, let me know if you think this is a good approach: fde295e |
* Add WP.com e2e tests fx * Use `WPComLanguage` for locale * Explicitly specify `summarize` for for all requests
…om:Automattic/wordpress-rs into task/CMM-1177-create-the-top-post-endpoint
|
Tests renaming 6a1917f |
Summary
/rest/v1.1/sites/<site_id>/stats/top-posts) - Returns most viewed posts/pages/rest/v1.1/sites/<site_id>/stats/referrers) - Returns traffic referrer sourcesImplementation Details
New Files
Top Posts Endpoint:
wp_api/src/wp_com/stats_top_posts.rs- Types, parameters, response structures, and helper functionswp_api/src/wp_com/endpoint/stats_top_posts_endpoint.rs- Endpoint definitionwp_api/tests/wpcom/stats_top_posts/top-posts-01.json- Test data fixtureReferrers Endpoint:
wp_api/src/wp_com/stats_referrers.rs- Types, parameters, response structures, and helper functionswp_api/src/wp_com/endpoint/stats_referrers_endpoint.rs- Endpoint definitionwp_api/tests/wpcom/stats_referrers/referrers-01.json- Test data fixtureModified Files
wp_api/src/wp_com/mod.rs- Module registrationwp_api/src/wp_com/endpoint.rs- Endpoint module registrationwp_api/src/wp_com/client.rs- Request builder and executor integrationAPI Parameters
Top Posts:
periodStatsTopPostsPeriodstart_dateStringdateStringmaxu32Referrers:
periodStatsReferrersPerioddateStringstart_dateStringmaxu32Helper Functions
Top Posts:
get_stats_top_posts_all_post_views()- Returns all post views from all daysget_stats_top_posts_for_date()- Returns post views for a specific dateget_stats_top_posts_total_views()- Returns total views across all daysReferrers:
get_stats_referrers_all_groups()- Returns all referrer groups from all daysget_stats_referrers_for_date()- Returns referrer data for a specific dateget_stats_referrers_total_views()- Returns total views across all daysNotable Implementation Details
The referrers endpoint has a polymorphic
resultsfield that can be either:{"views": 12}[{"name": "Google Search", ...}]This is handled using
#[serde(untagged)]enum (StatsReferrersResults).