-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Pull] Add Track Events to the Auth API responses #2452
Merged
jorgemd24
merged 8 commits into
feature/google-api-project
from
add/track-event-auth-wpcom
Jul 8, 2024
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
009ec0d
Add track evens when revoking token
jorgemd24 5388e06
Add tests when revoking token
jorgemd24 db27c06
Add track evens when updating Auth status
jorgemd24 792ef21
Adjust test
jorgemd24 be2876d
Add blog_id tracking
jorgemd24 fb8b49c
Add event property directives and descriptions
jorgemd24 2171ce6
Adjust event properties
jorgemd24 e7be1ca
Adjust event property
jorgemd24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,16 +159,72 @@ public function revoke_wpcom_api_auth(): string { | |
$request = $this->container->get( Jetpack::class )->remote_request( $args ); | ||
|
||
if ( is_wp_error( $request ) ) { | ||
|
||
/** | ||
* When the WPCOM token has been revoked with errors. | ||
* | ||
* @event revoke_wpcom_api_authorization | ||
* @property int status The status of the request. | ||
* @property string error The error message. | ||
* @property int|null blog_id The blog ID. | ||
*/ | ||
do_action( | ||
'woocommerce_gla_track_event', | ||
'revoke_wpcom_api_authorization', | ||
[ | ||
'status' => 400, | ||
'error' => $request->get_error_message(), | ||
'blog_id' => Jetpack_Options::get_option( 'id' ), | ||
] | ||
); | ||
|
||
throw new Exception( $request->get_error_message(), 400 ); | ||
} else { | ||
$body = wp_remote_retrieve_body( $request ); | ||
$status = wp_remote_retrieve_response_code( $request ); | ||
|
||
if ( ! $status || $status !== 200 ) { | ||
$data = json_decode( $body, true ); | ||
throw new Exception( $data['message'] ?? 'Error revoking access to WPCOM.', $status ); | ||
$data = json_decode( $body, true ); | ||
$message = $data['message'] ?? 'Error revoking access to WPCOM.'; | ||
|
||
/** | ||
* | ||
* When the WPCOM token has been revoked with errors. | ||
* | ||
* @event revoke_wpcom_api_authorization | ||
* @property int status The status of the request. | ||
* @property string error The error message. | ||
* @property int|null blog_id The blog ID. | ||
*/ | ||
do_action( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
'woocommerce_gla_track_event', | ||
'revoke_wpcom_api_authorization', | ||
[ | ||
'status' => $status, | ||
'error' => $message, | ||
'blog_id' => Jetpack_Options::get_option( 'id' ), | ||
] | ||
); | ||
|
||
throw new Exception( $message, $status ); | ||
} | ||
|
||
/** | ||
* When the WPCOM token has been revoked successfully. | ||
* | ||
* @event revoke_wpcom_api_authorization | ||
* @property string status The status of the request. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing to refactor the status, is also int here. |
||
* @property int|null blog_id The blog ID. | ||
*/ | ||
do_action( | ||
'woocommerce_gla_track_event', | ||
'revoke_wpcom_api_authorization', | ||
[ | ||
'status' => 200, | ||
'blog_id' => Jetpack_Options::get_option( 'id' ), | ||
] | ||
); | ||
|
||
$this->container->get( AccountService::class )->reset_wpcom_api_authorization_data(); | ||
return $body; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add here the property directives? Also, I miss the event description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I add them here: fb8b49c