You are here

private function WordStream::callAPI in WordStream Keyword Tools 7

8 calls to WordStream::callAPI()
WordStream::getAPICredits in ./class.wordstream.inc
WordStream::getKeywordNiches in ./class.wordstream.inc
WordStream::getKeywords in ./class.wordstream.inc
WordStream::getKeywordVolumes in ./class.wordstream.inc
WordStream::getQuestionKeywords in ./class.wordstream.inc

... See full list

File

./class.wordstream.inc, line 110

Class

WordStream
A class to aid with accessing the Wordstream API

Code

private function callAPI($apiMethod, $params = null) {
  $paramStr = '';
  if ($params) {
    foreach ($params as $key => $value) {
      $paramStr .= '&' . $key . '=' . urlencode($value);
    }
  }

  //initialize a new curl resource
  $queryStr = "?1=1" . $paramStr;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, self::$apiUrl . $apiMethod . $queryStr);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $content = curl_exec($ch);
  curl_close($ch);
  if ($content === FALSE) {
    return false;

    //Content couldn't be retrieved... Do something
  }
  else {
    return json_decode($content);

    //Content was retrieved do something with it.
  }
}