| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Reviews\Classes; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use ImageOptimization\Classes\Utils; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Feedback_Handler |
| 14 |
* |
| 15 |
* Class to post feedback |
| 16 |
*/ |
| 17 |
class Feedback_Handler { |
| 18 |
|
| 19 |
const SERVICE_ENDPOINT = 'feedback/reviews'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Send request to the service to submit the feedback. |
| 23 |
* |
| 24 |
* @param $params |
| 25 |
* |
| 26 |
* @return string |
| 27 |
* @throws Exception |
| 28 |
*/ |
| 29 |
public static function post_feedback( $params ) { |
| 30 |
$response = Utils::get_api_client()->make_request( |
| 31 |
'POST', |
| 32 |
self::SERVICE_ENDPOINT, |
| 33 |
$params |
| 34 |
); |
| 35 |
|
| 36 |
if ( empty( $response ) || is_wp_error( $response ) ) { |
| 37 |
throw new Exception( 'Failed to add the feedback.' ); |
| 38 |
} |
| 39 |
|
| 40 |
return $response; |
| 41 |
} |
| 42 |
} |
| 43 |
|