Skip to content

Instantly share code, notes, and snippets.

@stianeklund
Last active August 29, 2015 14:02
Show Gist options
  • Save stianeklund/e9d7541161d7c205d6b8 to your computer and use it in GitHub Desktop.
Save stianeklund/e9d7541161d7c205d6b8 to your computer and use it in GitHub Desktop.
Death
<?php
/*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
* CapsuleCRM Rest API Caller ID Lookup
*
* Written by Stian Eklund
*
*
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***/
class CapsuleCRM extends superfecta_base {
public $description = "CapsuleCRM lookups";
public $version_requirement = "2.11";
function get_caller_id($thenumber, $run_param=array()) {
$caller_id = null;
$name = "";
$spam = "";
$this->DebugPrint("Searching Capsule - {$this->thenumber} ... ");
// Search Capsule
$url = "https://stianeklund.capsulecrm.com/api/party?q=$thenumber";
$this->DebugPrint($url); // for debug
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($crl, CURLOPT_USERPWD, '[937680bd55b27297ad85b2441a9ada60]:[x]');
curl_setopt ($crl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt ($crl, CURLOPT_HEADER, true);
$result = (array)json_decode($url, true);
// echo $result;
$ret = curl_exec($crl);
curl_close($crl);
// return $ret;
// $value = $this->get_url_contents($url);
// $result = (array)json_decode($value,true);
if (isset($result['phone']['company'])) {
if ($result['phone']['company'] == 'Not Found') {
//record not found
} else {
$name = trim($result['phone']['company']);
}
}
// If we found a match, return it
if (strlen($name) > 1) {
$caller_id = $name;
} else {
$this->DebugPrint("not found");
}
return($caller_id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment