public function fire($msg, $params = array()) { if ($this->isEmpty()) { return false; } include_once 'lib/Notifo_API.php'; $notifo = new Notifo_API($this->getUsername(), $this->getKey()); $payload = array('label' => 'Cintient', 'msg' => $msg); if (!empty($params['uri'])) { $payload['uri'] = $params['uri']; } if (!empty($params['title'])) { $payload['title'] = $params['title']; } $response = $notifo->send_notification($payload); // If notifo.com is unreachable (happened before), response is null if (is_null($response) || empty($response)) { // TODO: Persist these notifications for later retry? Or for // showing them to the user on the web page? SystemEvent::raise(SystemEvent::INFO, "Notifo seems to be unreachable. [TITLE={$params['title']}] [MSG={$msg}]", __METHOD__); return false; } $response = json_decode($response, true); // // Check out: https://api.notifo.com/docs/responses // if (!empty($response['response_code']) && $response['response_code'] == '2201') { return true; } else { SystemEvent::raise(SystemEvent::INFO, "Notifo notification returned error. [RSP_CODE={$response['response_code']}] [RSP_MSG={$response['response_message']}]", __METHOD__); return false; } }
<?php /* include the Notifo_API PHP library */ include "Notifo_API.php"; /* create a new "notifo" object */ $notifo = new Notifo_API("username", "apisecret"); /* set the notification parameters */ $params = array("to" => "username", "label" => "Dictionary", "title" => "Word of the Day", "msg" => "chuffed: delighted; pleased; satisfied.", "uri" => "http://dictionary.com"); /* send the notification! */ $response = $notifo->send_notification($params); /* handle response below */ /* ... */