<?php

use CodePunch\Base\Util as UTIL;

function get_estibot_apraisal_data($domain, $apikey, $options=array()) {
	$callstatus = array('data'=>array(), 'status'=>'', 'error'=>'');
	$url = "https://www.estibot.com/api?k=$apikey&a=appraise&d=$domain";
	$retv = UTIL::curl_get_url($url, 20);

	if($retv['status'] == 200) {
		$data = json_decode($retv['result'], true);
		//$callstatus['raw'] = $data;
		if(intval($data['success']) == 1 && isset($data['results']['data'])) {
			$ebdata = $data['results']['data'];
			$callstatus['status'] = 'ok';
			$callstatus['not_found'] = $data['not_found'];
			$callstatus['result_count'] = $data['result_count'];
			$callstatus['item_count'] = $data['item_count'];
		}
		else {
			$ebdata = array();
			$callstatus['message'] = $data['message'];
		}
		$callstatus['data'] = $ebdata;
	}
	else {
		$callstatus['error'] = isset($retv['error']) ? $retv['error'] : $retv['status'];
	}
	return $callstatus;
}
