Skip to content

Commit

Permalink
moved $apiKey and $endpoint as properties of the class
Browse files Browse the repository at this point in the history
  • Loading branch information
mamatharao05 committed Aug 5, 2024
1 parent d625256 commit a0df499
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions includes/MultiSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ class MultiSearchController extends \WP_REST_Controller {
*/
protected $rest_base = 'multi_search';

/**
* The API key for the multi-search service
*
* @var string
*/
protected $apiKey;

/**
* The endpoint for the multi-search service
*
* @var string
*/
protected $endpoint;

/**
* Constructor to initialize the API key and endpoint
*/
public function __construct() {
$this->apiKey = 'B9wvYIokTPPgXEM3isTqsxbDOva21igT';
$this->endpoint = 'https://search.hiive.cloud/multi_search?x-typesense-api-key=' . $this->apiKey;
}

/**
* Register the routes for this objects of the controller
*/
Expand All @@ -47,8 +69,6 @@ public function register_routes() {
public function get_multi_search_result( \WP_REST_Request $request ) {
$brand = sanitize_text_field( $request->get_param( 'brand' ) );
$query = sanitize_text_field( $request->get_param( 'query' ) );
$apiKey = 'B9wvYIokTPPgXEM3isTqsxbDOva21igT';
$endpoint = 'https://search.hiive.cloud/multi_search?x-typesense-api-key='.$apiKey;

$params = [
'searches' => [
Expand Down Expand Up @@ -97,13 +117,14 @@ public function get_multi_search_result( \WP_REST_Request $request ) {
* @return \WP_Error
*/
public function check_permission() {
if ( ! current_user_can( 'read' ) ) {
if ( ! current_user_can( 'manage_option' ) ) {
return new \WP_Error(
'rest_forbidden',
__( 'You must be authenticated to make this call' ),
array( 'status' => 401 )
);
}
return true;
}

}

0 comments on commit a0df499

Please sign in to comment.