Location: PHPKode > scripts > WhoCalledUs > whocalledus/whocalledus.class.php
<?php

class WhoCalledUs
{
	public $user;
	public $pass;
	
	public function __construct($user, $pass)
	{
		$this->user = $user;
		$this->pass = $pass;
	}
	
	public function getWho($phoneNumber)
	{
		$params = "phoneNumber=$phoneNumber";

		$data = $this->callAction('getWho', $params);

		$splitdata = split('&', $data);
		$successdata = split('=', $splitdata[0]);
		$success = $successdata[1];
		$whodata = split('=', $splitdata[1]);
		$who = $whodata[1];

		if ($success == 1) return $who;
		else return -1;
	}
	
	public function getScore($phoneNumber)
	{
		$params = "phoneNumber=$phoneNumber";

		$data = $this->callAction('getScore', $params);

		$splitdata = split('&', $data);
		$successdata = split('=', $splitdata[0]);
		$success = $successdata[1];
		$scoredata = split('=', $splitdata[1]);
		$score = $scoredata[1];

		if ($success == 1) return $score;
		else return -1;
	}
	
	public function comment($phoneNumber, $message)
	{
		$message = urlencode($message);
		$params = "phoneNumber=$phoneNumber&message=$message";
		
		$data = $this->callAction('report', $params);
		
		$successdata = split('=', $data);
		$success = $successdata[1];
		
		return $success;
	}

	public function report($phoneNumber, $id, $identity, $postalCode, $date = 0)
	{
		if ($date == 0) $date = date('Y-m-d'); // (YYYY-MM-DD)
		
		$params = "phoneNumber=$phoneNumber&id=$id&identity=$identity&postalCode=$postalCode";
		
		$data = $this->callAction('report', $params);
		
		$successdata = split('=', $data);
		$success = $successdata[1];
		
		return $success;
	}
	
	public function callAction($action, $params)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, "http://whocalled.us/do?action=$action&name={$this->user}&pass={$this->pass}&" . $params);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$data = curl_exec($ch);
		curl_close($ch);
		
		return $data;
	}
}

?>
Return current item: WhoCalledUs