$notification->Url = 'https://www.googleapis.com/youtube/v3/search?channelId={channel}&part=snippet&order=date&maxResults=1'; $notification->Format = 'json'; // Prepare the api for that ManyStreamNotification $freezbiApi->prepare($notification); // Update fetch urls for each configurations foreach ($notification->Configurations as $identifier => $configuration) { $customUrl = str_replace('{channel}', $configuration['channel'], $notification->Url); $notification->Urls[$identifier] = $customUrl; } // Result processing $notification->Action = function ($identifier, $configuration, $jsonContent) use($freezbiApi) { // Prepare a response $response = new Response(); // Extract data from body $video = $jsonContent->items[0]->snippet; $title = $video->title; $channelName = $video->channelTitle; // Check if the title is same as the previous call if (!empty($title) && !$freezbiApi->testSameAsBefore($title, array('identifier' => $identifier))) { // testSameAsBefore needs the identifier to store data for that configuration // Update the response with new data $response->SendNotification = true; $response->Title = 'Youtube - ' . $channelName; $response->Message = $title; $response->Data = 'http://www.youtube.com/channel/' . $configuration['channel']; } // Return the response return $response; }; // Your script must return the output of the execute method echo $freezbiApi->execute();
$freezbiApi->TemporaryFolder = 'temp/'; $freezbiApi->Delay = 300; // Each remote check will be separated by 300 seconds // Create a new Notification with its name, url, and body type $notification = new \Freezbi\Notification\SingleStreamNotification('freezbiblog', 'http://freezbi.com/blog/posts', 'html'); // Prepare the api for that SingleStreamNotification $freezbiApi->prepare($notification); $notification->Action = function ($content) use($freezbiApi) { // Prepare a response $response = new Response(); // Use phpQuery lib for dirty crawling $freezbiApi->initPhpQueryOn($content); $article = pq('.blog article')->eq(0); // Extract a title and a link $data = $article->find('a')->attr('href'); $title = trim($article->find('h1')->text()); $title = trim(preg_replace("#(.+)\n(.+)#", "\$1", $title)); // Check if the title is same as the previous call if (!empty($title) && !$freezbiApi->testSameAsBefore($title, array('keep_history' => true))) { // keep_history option store data history instead of "switch A<=>B" verification // Update the response with new data $response->SendNotification = true; $response->Title = 'Clubic'; $response->Message = utf8_encode($title); $response->Data = 'freezbi.com/' . $data; } // Return the response return $response; }; // Your script must return the output of the execute method echo $freezbiApi->execute();