Skip to content

Instantly share code, notes, and snippets.

@richcaudle
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richcaudle/f2ade6e4e53e5a8f5ed0 to your computer and use it in GitHub Desktop.
Save richcaudle/f2ade6e4e53e5a8f5ed0 to your computer and use it in GitHub Desktop.
<?php
// Declare event handling object for stream consumption
class EventHandler implements DataSift_IStreamConsumerEventHandler
{
public function onInteraction($consumer, $interaction, $hash)
{
echo "INTERACTION: ".json_encode($interaction).PHP_EOL.PHP_EOL;
}
// Triggered when a connection is successfully setup
public function onConnect($consumer)
{
echo "Connected to DataSift".PHP_EOL;
}
// Triggered when an error message is received from DataSift
public function onError($consumer, $message)
{
echo 'ERROR: '.$message.PHP_EOL;
}
// Triggered when an interaction is marked as deleted. For sources such as Twitter you must delete this interaction in your application to meet Ts&Cs.
public function onDeleted($consumer, $interaction, $hash)
{
echo 'DELETE: Interaction '.$interaction['interaction']['id'].PHP_EOL;
}
// Ignore other events for quickstart example
public function onStatus($consumer, $type, $info) {}
public function onWarning($consumer, $message) {}
public function onDisconnect($consumer) {}
public function onStopped($consumer, $reason) {}
}
// Get an HTTP stream consumer for the filter, providing the event handler
$consumer = $filter->getConsumer(DataSift_StreamConsumer::TYPE_HTTP, new EventHandler());
// Consume the stream - this will not return unless the stream gets disconnected
$consumer->consume();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment