public function renderSingleStream()
 {
     $freezbiApi = new FreezbiApi();
     $freezbiApi->TemporaryFolder = $this->TemporaryFolder;
     $freezbiApi->Delay = $this->Delay;
     $notification = new SingleStreamNotification($this->UniqueName);
     $notification->setUrl($this->FeedUrl);
     $freezbiApi->prepare($notification);
     $this->setDateLastCheck($freezbiApi->getLastCheck());
     // Save a "this" reference for the closure
     $self = $this;
     // Result processing
     $notification->Action = function ($htmlContent) use($freezbiApi, $self) {
         // Prepare a response
         $response = new ResponseList();
         $reader = $self->getRssReaderService();
         $newElements = array();
         $feed = $reader->getFeedContent($self->getFeedUrl(), $self->getDateLastCheck());
         foreach ($feed->getItems() as $item) {
             $newElements[] = array('title' => $item->getTitle(), 'data' => $item->getLink());
         }
         if (!empty($newElements)) {
             // Update the response with new data
             $response->SendNotification = true;
             $response->Title = $self->getNotificationTitle();
             $response->Message = $newElements;
         }
         // Return the response
         return $response;
     };
     try {
         return $freezbiApi->execute();
     } catch (\Debril\RssAtomBundle\Driver\DriverUnreachableResourceException $e) {
         return $freezbiApi->renderEmptyResponseList();
     }
 }
Example #2
0
 public function renderSingleStream(SingleStreamNotification $notification)
 {
     // Get remote url data
     $content = $notification->execute();
     // Call process on the body response
     $response = $notification->Action->__invoke($content);
     // Check and render the response
     if (!$response instanceof Response) {
         throw new \InvalidArgumentException('Callback must return a Freezbi\\Response object.');
     }
     $this->closeLog();
     return $response->renderJson();
 }