mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-12 06:30:49 +02:00
Initial commit
Functional, without SSO
This commit is contained in:
67
sources/lib/Message/Adapter/Pushover.php
Normal file
67
sources/lib/Message/Adapter/Pushover.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Message\Adapter;
|
||||
|
||||
class Pushover extends AdapterAbstract
|
||||
{
|
||||
protected $notify_url = "https://api.pushover.net/1/messages.json";
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $user_key;
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send($message, array $options = array())
|
||||
{
|
||||
$this->setOptions($options);
|
||||
$message = trim($message);
|
||||
if (!$this->token || !$this->user_key) {
|
||||
throw new \Exception("Un des paramètres obligatoires est manquant", 400);
|
||||
}
|
||||
$curl = $this->getCurl(array(
|
||||
CURLOPT_POSTFIELDS => array(
|
||||
"token" => $this->getToken(),
|
||||
"user" => $this->getUserkey(),
|
||||
"message" => $message,
|
||||
"title" => $this->getTitle(),
|
||||
"url" => $this->getUrl(),
|
||||
)
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if ($response === false) {
|
||||
throw new \Exception("cURL Error: " . curl_error($curl));
|
||||
}
|
||||
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if (200 !== $code) {
|
||||
$response = json_decode($response, true);
|
||||
throw new \Exception("Errors:\n" . implode("\n", $response["errors"]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userkey
|
||||
* @return Pushover
|
||||
*/
|
||||
public function setUserkey($userkey)
|
||||
{
|
||||
$this->user_key = $userkey;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUserkey()
|
||||
{
|
||||
return $this->user_key;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user