/**
  * Abstract sender method
  *
  * @param User $user The recipient user
  * @param Notification $notification the notification to be sent
  * @param NotificationContent $content the content
  * @return mixed
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $query = ParseInstallation::query();
     $query->equalTo('user_id', $user->id);
     $data = ['alert' => $content->render('push_message', $notification)];
     $result = ParsePush::send(array('where' => $query, 'data' => $data));
     return is_array($result) && isset($result['result']) && $result['result'];
 }
 /**
  * Create a HipChat instance and send the notification
  *
  * @param  User                $user
  * @param  Notification        $notification
  * @param  NotificationContent $content
  * @return bool
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $hipChat = new HipChat($this->_config['api_key'], $this->_config['endpoint']);
     $message = $content->render('hipchat_message', $notification);
     $room = isset($notification->transport_config['room']) ? $notification->transport_config['room'] : $this->_config['defaultRoom'];
     $sentFrom = isset($notification->transport_config['sentFrom']) ? $notification->transport_config['sentFrom'] : $this->_config['defaultSentFrom'];
     $messageFormat = isset($notification->transport_config['messageFormat']) ? $notification->transport_config['messageFormat'] : HipChat::FORMAT_TEXT;
     $textColor = isset($notification->transport_config['textColor']) ? $notification->transport_config['textColor'] : HipChat::COLOR_YELLOW;
     return $hipChat->message_room($room, $sentFrom, $message, false, $textColor, $messageFormat);
 }
 /**
  * Abstract sender method
  *
  * @param User $user The recipient user
  * @param Notification $notification the notification to be sent
  * @param NotificationContent $content the content
  * @return mixed
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $query = ParseInstallation::query();
     $query->equalTo('user_id', $user->id);
     $alert = $content->render('push_message', $notification);
     if (empty($alert) && !empty($notification->config['content_fallback_transport'])) {
         $alert = $content->render($notification->config['content_fallback_transport'], $notification);
     }
     $data = ['alert' => $alert, 'badge' => 'Increment'];
     $result = ParsePush::send(array('where' => $query, 'data' => $data));
     return is_array($result) && isset($result['result']) && $result['result'];
 }
 /**
  * Abstract sender method
  *
  * @param User $user The recipient user
  * @param Notification $notification the notification to be sent
  * @param NotificationContent $content the content
  * @return mixed
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $user = TableRegistry::get('Users')->getUser($user->id);
     $phone = !empty($notification->transport_config['phoneNumberOverride']) ? $notification->transport_config['phoneNumberOverride'] : $user->phone;
     if (!empty($phone)) {
         if (substr($phone, 0, 2) === '00') {
             $phone = substr($phone, 2);
         }
         $maxSmsPerMessage = isset($notification->transport_config['maxSmsPerMessage']) ? $notification->transport_config['maxSmsPerMessage'] : $this->_config['defaultMaxSmsPerMessage'];
         $test = Configure::read('debug');
         // if you need to send SMS in development, uncomment next line
         // $test = false;
         $text = $content->render('sms', $notification);
         $message = new \WebSmsCom_TextMessage([$phone], $text);
         if (empty($text)) {
             return false;
         }
         try {
             $response = $this->_smsClient->send($message, $maxSmsPerMessage, $test);
         } catch (\WebSmsCom_ParameterValidationException $e) {
             echo "ParameterValidationException caught: " . $e->getMessage() . "\n";
             return false;
         } catch (\WebSmsCom_AuthorizationFailedException $e) {
             echo "AuthorizationFailedException caught: " . $e->getMessage() . "\n";
             return false;
         } catch (\WebSmsCom_ApiException $e) {
             #echo $e; // possibility to handle API status codes $e->getCode()
             echo "ApiException Exception: " . $e->getCode() . "\n";
             return false;
         } catch (\WebSmsCom_HttpConnectionException $e) {
             echo "HttpConnectionException caught: " . $e->getMessage() . "HTTP Status: " . $e->getCode() . "\n";
             return false;
         } catch (\WebSmsCom_UnknownResponseException $e) {
             echo "UnknownResponseException caught: " . $e->getMessage() . "\n";
             return false;
         } catch (\Exception $e) {
             echo "Exception caught: " . $e->getMessage() . "\n";
             return false;
         }
         return $response->getStatusCode() === 2000;
     }
 }
 /**
  * Abstract sender method
  *
  * @param User $user The recipient user
  * @param Notification $notification the notification to be sent
  * @param NotificationContent $content the content
  * @return mixed
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $subject = $content->render('email_subject', $notification);
     $htmlBody = $content->render('email_html', $notification);
     $textBody = $content->render('email_text', $notification);
     $email = new Email($this->_config['profile']);
     $email->transport($this->_config['emailTransport']);
     $email->emailFormat('html');
     if (!empty($notification->config['attachments'])) {
         $email->attachments($notification->config['attachments']);
     }
     $email->to([$user->email => $user->firstname . ' ' . $user->lastname]);
     $email->subject($subject);
     if (!empty($this->_config['templated']) && !empty($this->_config['template']) && !empty($this->_config['layout'])) {
         $email->template($this->_config['template'], $this->_config['layout']);
         $email->viewVars(['content' => $htmlBody]);
         return $email->send();
     }
     return $email->send($htmlBody);
 }