getData_ functions check return false if no data
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
class Linky{
|
||||
|
||||
public $_version = '0.11';
|
||||
public $_version = '0.12';
|
||||
|
||||
public function getData_perhour($date)
|
||||
{
|
||||
@@ -22,6 +22,8 @@ class Linky{
|
||||
$resource_id = 'urlCdcHeure';
|
||||
$result = $this->getData($resource_id, $startDate, $endDate);
|
||||
|
||||
if (!isset($result['graphe']['data'])) return false;
|
||||
|
||||
//format this correctly:
|
||||
$returnData = array();
|
||||
$startHour = new DateTime('23:30');
|
||||
@@ -56,6 +58,8 @@ class Linky{
|
||||
$resource_id = 'urlCdcJour';
|
||||
$result = $this->getData($resource_id, $startDate, $endDate);
|
||||
|
||||
if (!isset($result['graphe']['data'])) return false;
|
||||
|
||||
//format this correctly:
|
||||
$returnData = array();
|
||||
|
||||
@@ -81,6 +85,8 @@ class Linky{
|
||||
$resource_id = 'urlCdcMois';
|
||||
$result = $this->getData($resource_id, $startDate, $endDate);
|
||||
|
||||
if (!isset($result['graphe']['data'])) return false;
|
||||
|
||||
//format this correctly:
|
||||
$fromMonth = DateTime::createFromFormat('d/m/Y', $startDate);
|
||||
$returnData = array();
|
||||
@@ -108,6 +114,8 @@ class Linky{
|
||||
$resource_id = 'urlCdcAn';
|
||||
$result = $this->getData($resource_id, null, null);
|
||||
|
||||
if (!isset($result['graphe']['data'])) return false;
|
||||
|
||||
//format this correctly:
|
||||
$fromYear = new DateTime();
|
||||
$returnData = array();
|
||||
@@ -166,7 +174,7 @@ class Linky{
|
||||
//______________________calling functions
|
||||
protected function _request($method, $url, $postdata=null) //standard function handling all get/post request with curl | return string
|
||||
{
|
||||
if (!isset($this->_curlHdl))
|
||||
if (!isset($this->_curlHdl))
|
||||
{
|
||||
$this->_curlHdl = curl_init();
|
||||
curl_setopt($this->_curlHdl, CURLOPT_COOKIEJAR, $this->_cookFile);
|
||||
@@ -262,41 +270,41 @@ class Linky{
|
||||
protected $_cookFile = '';
|
||||
|
||||
protected $_loginBaseUrl = 'https://espace-client-connexion.enedis.fr';
|
||||
protected $_APIBaseUrl = 'https://espace-client-particuliers.enedis.fr/group/espace-particuliers';
|
||||
protected $_APILoginUrl = '/auth/UI/Login';
|
||||
protected $_APIHomeUrl = '/home';
|
||||
protected $_APIDataUrl = '/suivi-de-consommation';
|
||||
protected $_APIBaseUrl = 'https://espace-client-particuliers.enedis.fr/group/espace-particuliers';
|
||||
protected $_APILoginUrl = '/auth/UI/Login';
|
||||
protected $_APIHomeUrl = '/home';
|
||||
protected $_APIDataUrl = '/suivi-de-consommation';
|
||||
|
||||
protected $_curlHdl = null;
|
||||
protected $_curlHdl = null;
|
||||
|
||||
protected function auth()
|
||||
protected function auth()
|
||||
{
|
||||
$postdata = http_build_query(
|
||||
array(
|
||||
'IDToken1' => $this->_login,
|
||||
'IDToken2' => $this->_password,
|
||||
'SunQueryParamsString' => base64_encode('realm=particuliers'),
|
||||
'encoded' => 'true',
|
||||
'gx_charset' => 'UTF-8'
|
||||
)
|
||||
);
|
||||
$postdata = http_build_query(
|
||||
array(
|
||||
'IDToken1' => $this->_login,
|
||||
'IDToken2' => $this->_password,
|
||||
'SunQueryParamsString' => base64_encode('realm=particuliers'),
|
||||
'encoded' => 'true',
|
||||
'gx_charset' => 'UTF-8'
|
||||
)
|
||||
);
|
||||
|
||||
$url = $this->_loginBaseUrl.$this->_APILoginUrl;
|
||||
$response = $this->_request('POST', $url, $postdata);
|
||||
$url = $this->_loginBaseUrl.$this->_APILoginUrl;
|
||||
$response = $this->_request('POST', $url, $postdata);
|
||||
|
||||
//connected ?
|
||||
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $response, $matches);
|
||||
$cookies = array();
|
||||
foreach($matches[1] as $item)
|
||||
{
|
||||
parse_str($item, $cookie);
|
||||
$cookies = array_merge($cookies, $cookie);
|
||||
}
|
||||
if (!array_key_exists('iPlanetDirectoryPro', $cookies))
|
||||
{
|
||||
$this->error = 'Sorry, could not connect. Check your credentials.';
|
||||
return false;
|
||||
}
|
||||
//connected ?
|
||||
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $response, $matches);
|
||||
$cookies = array();
|
||||
foreach($matches[1] as $item)
|
||||
{
|
||||
parse_str($item, $cookie);
|
||||
$cookies = array_merge($cookies, $cookie);
|
||||
}
|
||||
if (!array_key_exists('iPlanetDirectoryPro', $cookies))
|
||||
{
|
||||
$this->error = 'Sorry, could not connect. Check your credentials.';
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_isAuth = true;
|
||||
|
||||
@@ -313,7 +321,7 @@ class Linky{
|
||||
|
||||
if ($this->auth() == false)
|
||||
{
|
||||
return $this->error;
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
if ($getAll)
|
||||
@@ -325,4 +333,4 @@ class Linky{
|
||||
//Linky end
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
Reference in New Issue
Block a user