[eluser]taewoo[/eluser]
I wrote a wrapper for this class if anyone's interested in doing real estate web app.
/system/application/plugin/zillow_pi.php :
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Zillow
{
var $api_key;
function Zillow()
{
$this->CI =& get_instance();
$this->api_key = $this->CI->config->item('Zillow_API_key');
}
function GetZestimate($zpid)
{
return $this->_url_parser("GetZestimate", array("zpid"=>$zpid));
}
function GetSearchResults($address, $citystatezip)
{
return $this->_url_parser("GetSearchResults", array("address"=>$address,
"citystatezip"=>$citystatezip));
}
function GetChart($zpid, $unit_type, $width=NULL, $height=NULL, $chartDuration=NULL)
{
return $this->_url_parser("GetChart", array("zpid"=>$zpid,
"unit_type"=>$unit_type,
"width"=>$width,
"height" =>$height,
"chartDuration"=>$chartDuration));
}
function GetComps($zpid, $count)
{
return $this->_url_parser("GetComps", array("zpid" =>$zpid,
"count" =>$count));
}
function _url_parser($function_name, $arguments)
{
$arguments["zws-id"] = $this->api_key;
$url = "http://www.zillow.com/webservice/".$function_name.".htm?".http_build_query($arguments);
//echo $url;
$handle = @fopen($url, "r");
$xml_string = array();
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$xml_string[] = trim($buffer);
}
fclose($handle);
}
return new SimpleXMLElement(implode("\n", $xml_string));
}
}
?>
In system/application/config/config.php
Code:
$config['Zillow_API_key'] = 'YOUR_ZILLOW_API_KEY';
To use it in your controller:
Code:
$this->load->plugin('zillow');
$zillow = new Zillow();
...