<?php 
	class Calendarista_WebHookHelper
	{
		public static function postDataToUrl($url, $data){
			if(!$data || !is_array($data)){
				return;
			}
			$postdata = json_encode($data);
			$ch = curl_init();
			$opts = array(
				CURLOPT_URL             => $url,
				CURLOPT_RETURNTRANSFER  => true,
				CURLOPT_CUSTOMREQUEST   => 'POST',
				CURLOPT_POST            => 1,
				CURLOPT_POSTFIELDS      => $postdata, 
				CURLOPT_CAINFO          =>  __DIR__ . "/cert/cacert.pem",
				CURLOPT_HTTPHEADER		=> array('Accept: application/json', 'Content-Type: application/json'),
				CURLOPT_TIMEOUT 		=> 10,
			);
			curl_setopt_array($ch, $opts);		
			if(!$result = curl_exec($ch))
			{
				$message = curl_error($ch);
				Calendarista_ErrorLogHelper::insert($message);
			}
			curl_close($ch);
		}
	}
?>
