public function onEvent($event, $data)
 {
     foreach ((array) $this->getClass('PushbulletManager')->find() as $Token) {
         $bulletHandler = new PushbulletHandler($Token->get('token'));
         $bulletHandler->pushNote('', $data['HostName'] . ' Failed', 'This host has failed to image');
     }
 }
 public function add_post()
 {
     try {
         $token = trim($_REQUEST['apiToken']);
         if ($this->getClass('PushbulletManager')->exists(trim($_REQUEST['apiToken']))) {
             throw new Exception('Account already linked');
         }
         if (!$token) {
             throw new Exception('Please enter an access token');
         }
         $bulletHandler = new PushbulletHandler($token);
         $userInfo = $bulletHandler->getUserInformation();
         $Bullet = new Pushbullet(array('token' => $token, 'name' => $userInfo->name, 'email' => $userInfo->email));
         if ($Bullet->save()) {
             $bulletHandler->pushNote('', 'FOG', 'Account linked');
             $this->FOGCore->setMessage('Account Added!');
             $this->FOGCore->redirect('?node=pushbullet&sub=list');
         }
     } catch (Exception $e) {
         $this->FOGCore->setMessage($e->getMessage());
         $this->FOGCore->redirect($this->formAction);
     }
 }
 /**
  * Push a file.
  *
  * @param string $recipient   Recipient. Can be device_iden, email or channel #tagname.
  * @param string $filePath    The path of the file to push.
  * @param string $mimeType    The MIME type of the file. If null, we'll try to guess it.
  * @param string $title       The title of the push notification.
  * @param string $body        The body of the push notification.
  * @param string $altFileName Alternative file name to use instead of the original one.
  *                            For example, you might want to push 'someFile.tmp' as 'image.jpg'.
  *
  * @return object Response.
  * @throws PushbulletException
  */
 public function pushFile($recipient, $filePath, $mimeType = null, $title = null, $body = null, $altFileName = null)
 {
     $data = array();
     $fullFilePath = realpath($filePath);
     if (!is_readable($fullFilePath)) {
         throw new PushbulletException('File: File does not exist or is unreadable.');
     }
     if (filesize($fullFilePath) > 25 * 1024 * 1024) {
         throw new PushbulletException('File: File size exceeds 25 MB.');
     }
     $data['file_name'] = $altFileName === null ? basename($fullFilePath) : $altFileName;
     // Try to guess the MIME type if the argument is NULL
     $data['file_type'] = $mimeType === null ? mime_content_type($fullFilePath) : $mimeType;
     // Request authorization to upload the file
     $response = $this->_curlRequest(self::URL_UPLOAD_REQUEST, 'GET', $data);
     $data['file_url'] = $response->file_url;
     if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
         $response->data->file = new CURLFile($fullFilePath);
     } else {
         $response->data->file = '@' . $fullFilePath;
     }
     // Upload the file
     $this->_curlRequest($response->upload_url, 'POST', $response->data, false, false);
     PushbulletHandler::_parseRecipient($recipient, $data);
     $data['type'] = 'file';
     $data['title'] = $title;
     $data['body'] = $body;
     return $this->_curlRequest(self::URL_PUSHES, 'POST', $data);
 }