<?php require_once './Freezbi/FreezbiApi.php'; use Freezbi\Response\Response; // Init the Freezbi Api $freezbiApi = new Freezbi\FreezbiApi(); $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;
<?php require_once './Freezbi/FreezbiApi.php'; use Freezbi\Response\Response; // Init the Freezbi Api $freezbiApi = new Freezbi\FreezbiApi(); $freezbiApi->TemporaryFolder = './temp/'; // Create a new Notification with its name, posted data (many only), url, and body type $notification = new \Freezbi\Notification\ManyStreamNotification('youtube', $_POST); $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;
<?php require_once './Freezbi/FreezbiApi.php'; use Freezbi\Response\Response; // Init the Freezbi Api $freezbiApi = new Freezbi\FreezbiApi(); $freezbiApi->TemporaryFolder = 'temp/'; $freezbiApi->Delay = 3600 * 24; // Each remote check will be separated by 24 hours // Create a new Notification with its name, url, and body type $notification = new \Freezbi\Notification\SingleStreamNotification('alan_turing_birthday'); // Prepare the api for that SingleStreamNotification $freezbiApi->prepare($notification); $notification->Action = function () use($freezbiApi) { // Prepare a response $response = new Response(); $datetime = new \DateTime(); if ($datetime->format('m-d') == '06-23') { $response->SendNotification = true; $response->Title = 'Birthday'; $response->Message = 'This is Alan Turing\'s birthday'; $response->Data = 'https://fr.wikipedia.org/wiki/Alan_Turing'; } return $response; }; // Your script must return the output of the execute method echo $freezbiApi->execute();