Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
490 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<? | ||
tusc_lib_require("StatusQueuer.interface.php"); | ||
|
||
/* | ||
* Example status-queuing class prints | ||
* stringified JSON read from the wire | ||
* straight to stdout. | ||
*/ | ||
class StatusDumper implements StatusQueuer { | ||
private static $instance; | ||
|
||
public static function defaultInstance() { | ||
if(!isset(self::$instance)) { | ||
$class = __CLASS__; | ||
self::$instance = new $class; | ||
} | ||
return self::$instance; | ||
} | ||
|
||
public function enqueueStatus($statusJson) { | ||
print "### In " . __CLASS__ . "::enqueueStatus() - got status of length " . strlen($statusJson) . "\n"; | ||
print "---$statusJson---\n\n"; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<? | ||
/* | ||
* Implement StatusQueuer to plug status-queueing | ||
* classes into the UserstreamPhirehose class. | ||
*/ | ||
interface StatusQueuer { | ||
public function enqueueStatus($statusJson); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<? | ||
/* | ||
* Ensure we have TwitterOAuth class to inherit from. | ||
* TwitterOAuth must be in the include_path. | ||
*/ | ||
require_once("twitteroauth/twitteroauth/twitteroauth.php"); | ||
|
||
/* | ||
* Utility class to construct OAuth-signed URLs. | ||
*/ | ||
class TwitterOAuthUtility extends TwitterOAuth { | ||
|
||
protected $buffer; | ||
|
||
/* | ||
* Allow overriding API host URL. | ||
* This is actually the URL root - e.g. | ||
* http://api.twitter.com/1/, or | ||
* https://userstream.twitter.com/2/ | ||
* as in the user stream. | ||
*/ | ||
function setHost($newHost) { | ||
$this->host = $newHost; | ||
} | ||
|
||
function getOAuthUrl($url, $method, $parameters = array()) { | ||
$request = $this->createOAuthRequest($url, $method, $parameters); | ||
return $request->to_url(); | ||
} | ||
|
||
function createOAuthRequest($url, $method, $parameters) { | ||
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) { | ||
$url = "{$this->host}{$url}.{$this->format}"; | ||
} | ||
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters); | ||
$request->sign_request($this->sha1_method, $this->consumer, $this->token); | ||
return $request; | ||
} | ||
|
||
} | ||
?> |
Oops, something went wrong.