mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-27 05:37:33 +02:00
Upgrade LBCAlerte to version 3.3
Add upgrade script
This commit is contained in:
73
sources/lib/Message/Adapter/Joaoappsjoin.php
Normal file
73
sources/lib/Message/Adapter/Joaoappsjoin.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Message\Adapter;
|
||||
|
||||
class Joaoappsjoin extends AdapterAbstract
|
||||
{
|
||||
protected $notify_url = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush";
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $device_ids;
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send($message, array $options = array())
|
||||
{
|
||||
$this->setOptions($options);
|
||||
$message = trim($message);
|
||||
if (!$this->device_ids) {
|
||||
throw new \Exception("Un des paramètres obligatoires est manquant", 400);
|
||||
}
|
||||
$params = array(
|
||||
"apikey" => $this->getToken(),
|
||||
"title" => $this->getTitle(),
|
||||
"text" => $message,
|
||||
"url" => $this->getUrl(),
|
||||
);
|
||||
$deviceIds = $this->getDeviceIds();
|
||||
if (0 === strpos($deviceIds, "group.")) {
|
||||
$params["deviceId"] = $deviceIds;
|
||||
} else {
|
||||
$params["deviceIds"] = $deviceIds;
|
||||
}
|
||||
$curl = $this->getCurl(array(
|
||||
CURLOPT_POST => false,
|
||||
CURLOPT_URL => $this->notify_url."?".http_build_query($params),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if ($response === false) {
|
||||
throw new \Exception("cURL Error: " . curl_error($curl));
|
||||
}
|
||||
|
||||
$response = json_decode($response, true);
|
||||
if (!empty($response["errorMessage"])) {
|
||||
throw new \Exception("Errors:\n" . $response["errorMessage"]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $device_ids
|
||||
* @return Joaoappsjoin
|
||||
*/
|
||||
public function setDeviceIds($device_ids)
|
||||
{
|
||||
$this->device_ids = $device_ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDeviceIds()
|
||||
{
|
||||
return $this->device_ids;
|
||||
}
|
||||
}
|
67
sources/lib/Message/Adapter/Slack.php
Normal file
67
sources/lib/Message/Adapter/Slack.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Message\Adapter;
|
||||
|
||||
class Slack extends AdapterAbstract
|
||||
{
|
||||
protected $hookurl = "";
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send($message, array $options = array())
|
||||
{
|
||||
$this->setOptions($options);
|
||||
$message = trim($message);
|
||||
if (!$this->hookurl) {
|
||||
throw new \Exception("Un des paramètres obligatoires est manquant", 400);
|
||||
}
|
||||
|
||||
if ($url = $this->getUrl()) {
|
||||
$message = "<".$url."|".$message.">";
|
||||
}
|
||||
$params = array(
|
||||
"text" => $message,
|
||||
);
|
||||
|
||||
$curl = $this->getCurl(array(
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_URL => $this->hookurl,
|
||||
CURLOPT_POSTFIELDS => array(
|
||||
"payload" => json_encode($params),
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if ($response === false) {
|
||||
throw new \Exception("cURL Error: " . curl_error($curl));
|
||||
}
|
||||
|
||||
$response = json_decode($response, true);
|
||||
if (!empty($response["errorMessage"])) {
|
||||
throw new \Exception("Errors:\n" . $response["errorMessage"]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $device_ids
|
||||
* @return Slack
|
||||
*/
|
||||
public function setHookurl($hookurl)
|
||||
{
|
||||
$this->hookurl = $hookurl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHookurl()
|
||||
{
|
||||
return $this->hookurl;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user