refactor to use fulcrm_apiv2_prevent_loop

master
Marek Isalski 9 years ago
parent fbf21bdbb8
commit 29d6810bb3

@ -49,22 +49,30 @@ function fulcrm_webhook_webhook( $uuid ) {
$payload_error_msg = json_last_error_msg(); $payload_error_msg = json_last_error_msg();
} }
switch ( $method ) { $client_id = variable_get( 'fulcrm_apiv2_client_id' );
case 'GET':
drupal_json_output( array( "status" => "error", "info" => "GET requests do nothing; webhooks must be POST, PATCH, PUT, or DELETE" ) ); if ( fulcrm_apiv2_prevent_loop( $headers ) ) {
break; switch ( $method ) {
case 'DELETE': case 'GET':
case 'POST': drupal_json_output( array( "status" => "error", "info" => "GET requests do nothing; webhooks must be POST, PATCH, PUT, or DELETE" ) );
case 'PATCH': break;
case 'PUT': case 'DELETE':
if ( $payload === null ) { case 'POST':
// actually do something :) case 'PATCH':
drupal_json_output( array( 'status' => 'error', 'info' => $payload_error_msg ) ); case 'PUT':
} else { if ( $payload === null ) {
drupal_json_output( array( 'status' => 'ok', 'headers' => $headers, 'method' => $method ) ); 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;
} }
break; } else {
default: drupal_json_output( array( 'status' => 'ok', 'info' => 'loop prevention' ) );
} }
} else { } else {
drupal_access_denied(); drupal_access_denied();

Loading…
Cancel
Save