refactor to use fulcrm_apiv2_prevent_loop

master
Marek Isalski 9 years ago
parent fbf21bdbb8
commit 29d6810bb3

@ -49,6 +49,9 @@ function fulcrm_webhook_webhook( $uuid ) {
$payload_error_msg = json_last_error_msg();
}
$client_id = variable_get( 'fulcrm_apiv2_client_id' );
if ( fulcrm_apiv2_prevent_loop( $headers ) ) {
switch ( $method ) {
case 'GET':
drupal_json_output( array( "status" => "error", "info" => "GET requests do nothing; webhooks must be POST, PATCH, PUT, or DELETE" ) );
@ -58,13 +61,18 @@ function fulcrm_webhook_webhook( $uuid ) {
case 'PATCH':
case 'PUT':
if ( $payload === null ) {
// actually do something :)
drupal_json_output( array( 'status' => 'error', 'info' => $payload_error_msg ) );
} else {
// actually do something :)
drupal_json_output( array( 'status' => 'ok', 'headers' => $headers, 'method' => $method ) );
}
break;
default:
drupal_json_output( array( 'status' => 'error', 'info' => 'unsupported method' ) );
break;
}
} else {
drupal_json_output( array( 'status' => 'ok', 'info' => 'loop prevention' ) );
}
} else {
drupal_access_denied();

Loading…
Cancel
Save