mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-20 02:10:50 +02:00
Initial commit
Functional, without SSO
This commit is contained in:
57
sources/lib/Message/Adapter/Pushbullet.php
Normal file
57
sources/lib/Message/Adapter/Pushbullet.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Message\Adapter;
|
||||
|
||||
class Pushbullet extends AdapterAbstract
|
||||
{
|
||||
protected $notify_url = "https://api.pushbullet.com/v2/pushes";
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function send($message, array $options = array())
|
||||
{
|
||||
$this->setOptions($options);
|
||||
$message = trim($message);
|
||||
if (!$this->token) {
|
||||
throw new \Exception("Un des paramètres obligatoires est manquant", 400);
|
||||
}
|
||||
|
||||
$params = array(
|
||||
"type" => "note",
|
||||
"title" => $this->getTitle(),
|
||||
"body" => $message
|
||||
);
|
||||
if ($url = $this->getUrl()) {
|
||||
$params["type"] = "link";
|
||||
$params["url"] = $url;
|
||||
}
|
||||
|
||||
$params = json_encode($params);
|
||||
|
||||
$curl = $this->getCurl(array(
|
||||
CURLOPT_USERPWD => $this->getToken(),
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Content-Type: application/json ",
|
||||
"Content-Length: ".strlen($params)
|
||||
),
|
||||
CURLOPT_POSTFIELDS => $params,
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if ($response === false) {
|
||||
throw new \Exceptions("cURL Error: " . curl_error($curl));
|
||||
}
|
||||
|
||||
$json = json_decode($response, true);
|
||||
|
||||
if (400 <= $code = curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
|
||||
throw new \Exception($json["error"]["message"], $code);
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user