Skip to content

Commit

Permalink
Removed non-essential constants and refactored a bit.
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Escribano <[email protected]>
  • Loading branch information
carlosescri committed Feb 13, 2017
1 parent 8a53bc7 commit b2eb47b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Search/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
* Basic client to perform requests to Doofinder search servers.
*/
class Client {
const URL_SUFFIX = '-search.doofinder.com';
const DEFAULT_TIMEOUT = 10000;
const DEFAULT_RPP = 10;
const DEFAULT_PARAMS_PREFIX = 'dfParam_';
const DEFAULT_API_VERSION = '5';
const VERSION = '5.4.3';

private $api_key = null; // Authentication
private $hashid = null; // ID of the Search Engine
Expand Down Expand Up @@ -84,7 +82,6 @@ public function __construct($hashid, $api_key, $fromParams = false, $init_option
if (2 === count($zone_key_array)) {
$this->api_key = $zone_key_array[1];
$this->zone = $zone_key_array[0];
$this->url = "https://" . $this->zone . self::URL_SUFFIX;
} else {
throw new Error("API Key is no properly set.");
}
Expand Down Expand Up @@ -133,6 +130,14 @@ public function __construct($hashid, $api_key, $fromParams = false, $init_option
}
}

private function getSearchUrl($entryPoint = 'search', $params = array()) {
return sprintf("https://%s-search.doofinder.com/%s/%s?%s",
$this->zone,
$this->apiVersion,
$entryPoint,
http_build_query($this->sanitize($params)));
}

private function addPrefix($value) {
return $this->paramsPrefix.$value;
}
Expand All @@ -146,13 +151,10 @@ private function getRequestHeaders(){
return $headers;
}

private function apiCall($entry_point = 'search', $params = array()){
private function apiCall($entryPoint = 'search', $params = array()){
$params['hashid'] = $this->hashid;

$session = curl_init(sprintf("%s/%s/%s?%s", $this->url,
$this->apiVersion,
$entry_point,
http_build_query($this->sanitize($params))));
$session = curl_init($this->getSearchUrl($entryPoint, $params));

// Configure cURL to return response but not headers
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'GET');
Expand Down

0 comments on commit b2eb47b

Please sign in to comment.