Created
March 26, 2009 04:44
-
-
Save snelson/85891 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
class CampfireAPI | |
{ | |
//Campfire API variables | |
//MODIFY THESE FOR YOUR ACCOUNT | |
public $url = ''; //The full URL to your account. ex: http://[account].campfirenow.com | |
public $username = ''; //The Campfire user you want to log messages as. (usually an email address) | |
public $password = ''; //The users Campfire password | |
public $roomid; | |
private $_cookiefile; | |
public function __construct($url, $username, $password) | |
{ | |
$this->url = $url; | |
$this->username = $username; | |
$this->password = $password; | |
//Campfire cookie file, where the login cookie is stored | |
$this->_cookiefile = (ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir()) . '/campfire_cookie.txt'; | |
$this->login(); | |
} | |
public function login() | |
{ | |
$this->_request($this->url . '/login', array( | |
'email_address' => $this->username, | |
'password' => $this->password, | |
)); | |
} | |
public function speak($roomid, $message) | |
{ | |
$this->_request($this->url . '/room/' . $roomid . '/speak', array( | |
'message' => $message, | |
)); | |
} | |
public function paste($roomid, $message, $paste = FALSE) | |
{ | |
$this->_request($this->url . '/room/' . $roomid . '/speak', array( | |
'message' => $message, | |
'paste' => 'true', | |
)); | |
} | |
private function _request($url, $fields = array()) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookiefile); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); | |
curl_exec($ch); | |
curl_close($ch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment