This class represents a single message to be send by the connector.
Exemplo n.º 1
0
 protected function send(MessageInterface $message, RecipientInterface $recipient)
 {
     $oProwl = new Connector();
     $oMsg = new Message();
     try {
         $oProwl->setIsPostRequest(true);
         $oMsg->setPriority(0);
         $oProwl->setFilterCallback(function ($sText) {
             return $sText;
         });
         $oMsg->addApiKey($recipient->getInfo('prowl_app.api_key'));
         $oMsg->setEvent($message->getSubject());
         $oMsg->setDescription($message->getContent());
         $oMsg->setApplication($this->appName);
         $oResponse = $oProwl->push($oMsg);
         if ($oResponse->isError()) {
             $this->errors[] = $oResponse->getErrorAsString();
         }
     } catch (\InvalidArgumentException $oIAE) {
         $this->errors[] = $oIAE->getMessage();
     } catch (\OutOfRangeException $oOORE) {
         $this->errors[] = $oOORE->getMessage();
     }
 }
Exemplo n.º 2
0
 /**
  * Send the message through the Prowl API
  *
  * @param $message
  *
  * @throws \Talkback\Exception\ChannelTargetException
  * @throws \Talkback\Exception\InvalidArgumentException
  */
 private function sendProwlMessage($message)
 {
     // We can only send a message if we have at least on API key
     if (count($this->aApiKey) == 0) {
         throw new ChannelTargetException("Prowl requires you add at least one ApiKey");
     }
     // We need an eventName
     if (!isset($this->eventName)) {
         throw new ChannelTargetException("Prowl requires you set an eventName up to 1024 chars");
     }
     // Use \Prowl\SecureConnector to make cUrl use SSL
     $oProwl = new Connector();
     $oMsg = new Message();
     try {
         // You can choose to pass a callback
         $oProwl->setFilterCallback(function ($sText) {
             return $sText;
         });
         $oProwl->setIsPostRequest(true);
         $oMsg->setPriority(0);
         foreach ($this->aApiKey as $apiKey) {
             $oMsg->addApiKey($apiKey);
         }
         $oMsg->setEvent($this->eventName);
         $oMsg->setDescription($message);
         $oMsg->setApplication($this->applicationName);
         $oResponse = $oProwl->push($oMsg);
         if ($oResponse->isError()) {
             //                @todo make this work properly
             //                Debug::log($oResponse->getErrorAsString(), Debug::NOTICE);
         }
     } catch (\InvalidArgumentException $oIAE) {
         throw new InvalidArgumentException($oIAE->getMessage());
     } catch (\OutOfRangeException $oOORE) {
         throw new ChannelTargetException($oOORE->getMessage());
     }
 }
Exemplo n.º 3
0
 /**
  * Decides based on the presence of a closure or a filter
  * which way to go for filtering.
  *
  * @throws \RuntimeException
  * @param \Prowl\Message $oMessage
  * @param string $sContent
  * @return string
  */
 private function filter(\Prowl\Message $oMessage, $sContent)
 {
     if ($oMessage->getFilterCallback() != null) {
         $cFilter = $oMessage->getFilterCallback();
         return $cFilter($sContent);
     } elseif ($oMessage->getFilter() != null) {
         $oFilter = $oMessage->getFilter();
         return $oFilter->filter($sContent);
     } else {
         throw new \RuntimeException("No filter set, abort.");
     }
 }