From MWWiki
Back to Main Project Page
<?php
class Update {
private static $UPDATEURL = 'http://twitter.com/statuses/update.xml?status=';
private static $PUBLICURL = 'http://twitter.com/statuses/public_timeline.json';
private static $AUTH = 'USERNAME:PASSWORD';
private static $DEBUG = true;
private $cHandle;
private $options;
public function __construct() {
$this->cHandle = curl_init();
}
public function __destruct() {
curl_close($this->cHandle);
}
/**
* Hits the public timeline the specified number of times.
* NOTE: This may be subject to API limitations!
*
* @param $num Number of times to hit the public timeline.
*/
public function getPublicTimeline($num) {
$this->options = array(
CURLOPT_URL => Update::$PUBLICURL,
CURLOPT_RETURNTRANSFER => 1,
);
curl_setopt_array($this->cHandle, $this->options);
$retval = array();
for ($i = 0; $i < $num; $i++) {
$retval[$i] = json_decode(curl_exec($this->cHandle));
}
return $retval;
}
public function postUpdate($update) {
$this->options = array(
CURLOPT_USERPWD => Update::$AUTH,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => Update::$UPDATEURL . urlencode($update),
);
curl_setopt_array($this->cHandle, $this->options);
return curl_exec($this->cHandle);
}
}
?>