Hi All,
For a project of mine I needed to work with the Basecamp API (new version). So after some searching I stumbled upon this Basecamp API class: http://code.google.com/p/basecamp-php-api/
It works really nice and has a lot of methods to work with the Basecamp API (just check the readme url at the end of this post).
Since there was no CodeIgniter library of this class yet (or any Basecamp API library in general) I decided to convert this class into one. Not much work, but I think helpful enough to share with you.
What you need to know
- The main Basecamp.php class includes the RestRequest.class.php. So both need to be in the library folder. (I couldn’t find any information about not being allowed ‘include’ within a library class, so I just left it like it was. But if you have suggestions on a better/more elegant way, please let me know).
- I had to change the contruct method to fit the CodeIgniter standard
Old constructer method
public function __construct ($baseurl,$username=null,$password=null,$format='xml') {
$this->setBaseurl($baseurl);
$this->setFormat($format);
$this->setUsername($username);
$this->setPassword($password);
$this->setFormat($format);
}
New constructer method
public function Basecamp ($params) {
$baseurl = $params['baseurl'];
$username = ($params['username'] == '') ? null : $params['username'];
$password = ($params['password'] == '') ? null : $params['password'];
$format = ($params['format'] == '') ? 'xml' : $params['format'];
$this->setBaseurl($baseurl);
$this->setFormat($format);
$this->setUsername($username);
$this->setPassword($password);
}
Using the library in CodeIgniter
In your controller
$params = array('baseurl' => 'https://YOUR-COMPANY.basecamphq.com/','username' => 'YOUR_API_TOKEN','password' => 'x','format' => 'simplexml');
$this->load->library('basecamp', $params);
$data['response'] = $this->basecamp->getMilestonesForProject('PROJECT-ID',$filter_type='all');
In your view (ugly example)
// iterate the projects
foreach($response as $milestone) {
echo '<pre>';
print_r($milestone);
echo '</pre>';
}
References
- Basecamp PHP methods
- Basecamp API
