Skip to content

Commit

Permalink
Added v5 and apiCall to "options" (#10)
Browse files Browse the repository at this point in the history
* Added v5 and apiCall to "options"

* Remove debug line
  • Loading branch information
danidomen authored and JoeZ99 committed Apr 15, 2016
1 parent cfbc803 commit 3411d23
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/doofinder_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function __construct($hashid, $api_key, $fromParams=false, $init_options = array
{
throw new DoofinderException("Wrong hashid");
}
if(!in_array($this->apiVersion, array('4', '3.0','1.0')))
if(!in_array($this->apiVersion, array('5', '4', '3.0','1.0')))
{
throw new DoofinderException('Wrong API');
}
Expand Down Expand Up @@ -155,10 +155,15 @@ private function reqHeaders(){
return $headers;
}

private function apiCall($params){
private function apiCall($params,$method='search'){
$params['hashid'] = $this->hashid;
$args = http_build_query($this->sanitize($params)); // remove any null value from the array
$url = $this -> url . '/' . $this->apiVersion . '/search?' . $args;
switch($method){
case 'search': $url = $this -> url . '/' . $this->apiVersion . '/search?' . $args;break;
case 'options': $url = $this -> url . '/' . $this->apiVersion . '/options/' . $this->hashid; break;
default: $url = $this -> url . '/' . $this->apiVersion . '/search?' . $args; break;
}

$session = curl_init($url);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($session, CURLOPT_HEADER, false); // Tell curl not to return headers
Expand All @@ -169,10 +174,17 @@ private function apiCall($params){
curl_close($session);

if (floor($httpCode / 100) == 2) {
if($method=='options'){
return $response;
}
return new DoofinderResults($response);
}
throw new DoofinderException($httpCode.' - '.$response, $httpCode);
}

public function getOptions(){
return $this->apiCall('', 'options');
}

/**
* query. makes the query to the doofinder search server.
Expand Down

0 comments on commit 3411d23

Please sign in to comment.