Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved config files into a separate file #108

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.un~
.cache
.cache/*
.idea
Empty file modified Readme.md
100644 → 100755
Empty file.
42 changes: 24 additions & 18 deletions composer.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
{
"name": "fennb/phirehose",
"description": "A PHP interface to the Twitter Streaming API.",
"keywords": ["phirehose", "php", "twitter", "streaming", "api"],
"type": "library",
"homepage": "https://github.com/fennb/phirehose",
"license": "GPL",
"authors": [
{
"name": "Fenn Bailey",
"homepage": "http://fennb.com/"
}
],
"require": {
"php": ">=5.2.0"
"name": "fennb/phirehose",
"description": "A PHP interface to the Twitter Streaming API.",
"keywords": [
"phirehose",
"php",
"twitter",
"streaming",
"api"
],
"type": "library",
"homepage": "https://github.com/fennb/phirehose",
"license": "GPL",
"require": {
"php": ">=5.4.0",
"kreait/firebase-php": "^2.0"
},
"autoload": {
"psr-0": {
"MyApp": "src"
},
"autoload": {
"classmap": ["lib"]
}
}
"classmap": [
"lib"
]
}
}
48 changes: 20 additions & 28 deletions example/filter-oauth.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');
require_once '../lib/Phirehose.php';
require_once '../lib/OauthPhirehose.php';
require_once 'twitter-auth-config.php';

/**
* Example of using Phirehose to display a live filtered stream using track words
* Example of using Phirehose to display a live filtered stream using track words
*/
class FilterTrackConsumer extends OauthPhirehose
{
/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
/**
* Enqueue each status
*
* @param string $status
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
}
}
}
}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "");
define("TWITTER_CONSUMER_SECRET", "");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "");
define("OAUTH_SECRET", "");

// Start streaming
$sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$sc->setTrack(array('morning', 'goodnight', 'hello', 'the'));
$sc->setTrack(['morning', 'goodnight', 'hello', 'the']);
$sc->consume();
72 changes: 31 additions & 41 deletions example/filter-reconfigure.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');
require_once '../lib/Phirehose.php';
require_once '../lib/OauthPhirehose.php';
require_once 'twitter-auth-config.php';

/**
* Example of how to update filter predicates using Phirehose
*/
class DynamicTrackConsumer extends OauthPhirehose
{

/**
* Subclass specific attribs
*/
protected $myTrackWords = array('morning', 'goodnight', 'hello', 'the');

/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
// We won't actually do anything with statuses in this example, see updateFilterPredicates() for important stuff
}

/**
* In this example, we just set the track words to a random 2 words. In a real example, you'd want to check some sort
* of shared medium (ie: memcache, DB, filesystem) to determine if the filter has changed and set appropriately. The
* speed of this method will affect how quickly you can update filters.
*/
public function checkFilterPredicates()
{
// This is all that's required, Phirehose will detect the change and reconnect as soon as possible
$randWord1 = $this->myTrackWords[rand(0, 3)];
$randWord2 = $this->myTrackWords[rand(0, 3)];
$this->setTrack(array($randWord1, $randWord2));
}

/**
* Subclass specific attribs
*/
protected $myTrackWords = ['morning', 'goodnight', 'hello', 'the'];

/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
// We won't actually do anything with statuses in this example, see updateFilterPredicates() for important stuff
}

/**
* In this example, we just set the track words to a random 2 words. In a real example, you'd want to check some sort
* of shared medium (ie: memcache, DB, filesystem) to determine if the filter has changed and set appropriately. The
* speed of this method will affect how quickly you can update filters.
*/
public function checkFilterPredicates()
{
// This is all that's required, Phirehose will detect the change and reconnect as soon as possible
$randWord1 = $this->myTrackWords[rand(0, 3)];
$randWord2 = $this->myTrackWords[rand(0, 3)];
$this->setTrack([$randWord1, $randWord2]);
}
}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "");
define("TWITTER_CONSUMER_SECRET", "");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "");
define("OAUTH_SECRET", "");

// Start streaming
$sc = new DynamicTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$sc->consume();
$sc->consume();
56 changes: 25 additions & 31 deletions example/filter-track-geo.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');
require_once '../lib/Phirehose.php';
require_once '../lib/OauthPhirehose.php';
require_once 'twitter-auth-config.php';

/**
* Example of using Phirehose to display a live filtered stream using geo locations
*/
class FilterTrackConsumer extends OauthPhirehose
{
/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
/**
* Enqueue each status
*
* @param string $status
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
}
}
}
}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "");
define("TWITTER_CONSUMER_SECRET", "");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "");
define("OAUTH_SECRET", "");

// Start streaming
$sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$sc->setLocations(array(
array(-122.75, 36.8, -121.75, 37.8), // San Francisco
array(-74, 40, -73, 41), // New York
));
$sc->consume();
$sc->setLocations(
[
[-122.75, 36.8, -121.75, 37.8], // San Francisco
[-74, 40, -73, 41], // New York
]
);
$sc->consume();
Loading