Skip to content

Commit

Permalink
adding basic lib classes
Browse files Browse the repository at this point in the history
  • Loading branch information
igorclark committed Nov 30, 2010
1 parent 3c898c6 commit 2ac6f17
Show file tree
Hide file tree
Showing 5 changed files with 490 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/StatusDumper.class.php
@@ -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";
}
}
?>
9 changes: 9 additions & 0 deletions lib/StatusQueuer.interface.php
@@ -0,0 +1,9 @@
<?
/*
* Implement StatusQueuer to plug status-queueing
* classes into the UserstreamPhirehose class.
*/
interface StatusQueuer {
public function enqueueStatus($statusJson);
}
?>
41 changes: 41 additions & 0 deletions lib/TwitterOAuthUtility.class.php
@@ -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;
}

}
?>

0 comments on commit 2ac6f17

Please sign in to comment.