VideoPress: Add endpoint for returning today's video stats
Relates to #26479.
Changes proposed in this Pull Request:
- Register
videopress/v1/statsendpoint to return general video stats - Return the counter of plays for today, using the information provided by the WPCOM REST API
- The plan was to add a counter for all-time plays, but we still need to sort out how to request it, so it's not included here
Pending issues:
- which capability the user needs to have to see this data?
- how to make this work inside WPCOM / make sure the class got loaded (similar to #26406)
Other information:
- [ ] Have you written new tests for your changes, if applicable?
- [ ] Have you checked the E2E test CI results, and verified that your changes do not break them?
Jetpack product discussion
N/A.
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
- Use a site with VideoPress installed
- Do a
GETrequest toyoursite.com/wp-json/videopress/v1/stats, for example:
curl -X GET -u "user:pass" http://yoursite.com/wp-json/videopress/v1/stats | jq
- The expected response is similar to this:
{
"plays": {
"today": 1
}
}
- It's useful to have some media available on the site with usage information, so make sure you uploaded at least one video, put it on a post and do at least one play on it
Are you an Automattician? You can now test your Pull Request on WordPress.com. On your sandbox, run bin/jetpack-downloader test jetpack add/videopress-stats-endpoint to get started. More details: p9dueE-5Nn-p2
Thank you for your PR!
When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
- :white_check_mark: Include a description of your PR changes.
- :white_check_mark: All commits were linted before commit.
- :white_check_mark: Add a "[Status]" label (In Progress, Needs Team Review, ...).
- :white_check_mark: Add testing instructions.
- :white_check_mark: Specify whether this PR includes any changes to data or privacy.
- :white_check_mark: Add changelog entries to affected projects
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation :robot:
The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.
Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Then, add the "[Status] Needs Team review" label and ask someone from your team review the code. Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.
we'd probably like to extract a method to get the stats to get it in the backend size without the need to hit the endpoint from the client
@retrofox I refactored the code to move the stats requesting to a new Stats class. Let me know what you think :+1: