This commit is contained in:
Laurent Destailleur 2019-02-28 11:00:40 +01:00
parent b91a458af4
commit c444521abc
2 changed files with 28 additions and 1 deletions

View File

@ -78,6 +78,11 @@ function getURLContent($url, $postorget = 'GET', $param = '', $followlocation =
curl_setopt($ch, CURLOPT_POST, 1); // POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields
}
elseif ($postorget == 'POSTALREADYFORMATED')
{
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // HTTP request is 'POST' but param string is taken as it is
curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string
}
elseif ($postorget == 'PUT')
{
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'

View File

@ -115,8 +115,30 @@ class InterfaceIFTTT extends DolibarrTriggers
case 'THIRDPARTY_CREATED':
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
// TODO
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
// See https://platform.ifttt.com/docs/api_reference#realtime-api
$arrayofdata=array();
$arrayofdata['user_id']=$conf->global->IFTTT_USER_ID;
$arrayofdata['trigger_identity']=$conf->global->IFTTT_TRIGGER_IDENTITY;
$arrayofdata['name']='testabcdef';
$arrayofdata['email']='testemailabcdef';
$url = 'https://realtime.ifttt.com/v1/notifications';
$addheaders=array(
'IFTTT-Service-Key'=>'123',
'Accept'=>'application/json',
'Accept-Charset'=>'utf-8',
'Accept-Encoding'=>'gzip, deflate',
'Content-Type'=>'application/json',
'X-Request-ID'=>getRandomPassword(true, null)
)
$result = getURLContent($url, 'POSTALREADYFORMATED', '', 1, $addheaders);
$ok = 1;
break;
}