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:
69
sources/lib/Message/Adapter/NotifyMyAndroid.php
Normal file
69
sources/lib/Message/Adapter/NotifyMyAndroid.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Message\Adapter;
|
||||
|
||||
class NotifyMyAndroid extends AdapterAbstract
|
||||
{
|
||||
protected $notify_url = "https://www.notifymyandroid.com/publicapi/notify";
|
||||
|
||||
/**
|
||||
* Envoi un message.
|
||||
* @param string $msg
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send($message, array $options = array())
|
||||
{
|
||||
$message = trim($message);
|
||||
$this->setOptions($options);
|
||||
if (!$this->token || !$this->title) {
|
||||
throw new \Exception("Un des paramètres obligatoires est manquant", 400);
|
||||
}
|
||||
|
||||
$params = array(
|
||||
"apikey" => $this->getToken(),
|
||||
"application" => $this->getTitle(),
|
||||
"event" => $this->getDescription(),
|
||||
"description" => $message,
|
||||
);
|
||||
if ($url = $this->getUrl()) {
|
||||
$params["url"] = $url;
|
||||
}
|
||||
|
||||
$curl = $this->getCurl(array(
|
||||
CURLOPT_POSTFIELDS => http_build_query($params)
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if ($response === false) {
|
||||
throw new \Exception("cURL Error: " . curl_error($curl));
|
||||
}
|
||||
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code == 200) {
|
||||
// find error through content
|
||||
|
||||
}
|
||||
if ($code != 200) {
|
||||
switch ($code) {
|
||||
case 400:
|
||||
$msg = "The data supplied is in the wrong format, invalid length or null.";
|
||||
break;
|
||||
case 401:
|
||||
$msg = "None of the API keys provided were valid.";
|
||||
break;
|
||||
case 402:
|
||||
$msg = "Maximum number of API calls per hour exceeded.";
|
||||
break;
|
||||
case 500:
|
||||
$msg = "Internal server error. Please contact our support if the problem persists.";
|
||||
break;
|
||||
default:
|
||||
$msg = "Unknow error.";
|
||||
}
|
||||
throw new \Exception($msg, $code);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user