Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created December 5, 2011 16:01
Show Gist options
  • Save uppfinnarjohnny/1434079 to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/1434079 to your computer and use it in GitHub Desktop.
Simple API wrapper for ActiveCollab
<?php
class ActiveCollab {
protected $base_url;
protected $api_key;
public function __construct($base_url, $api_key) {
$this->base_url = $base_url;
$this->api_key = $api_key;
}
public function call($path, $data = array()) {
if($data)
$data['submitted'] = 'submitted';
$opts = array(
'http' => array(
'method' => $data ? 'POST' : 'GET',
'header' => 'Accept: application/json',
'content' => http_build_query($data)
)
);
$path = $this->base_url.'?path_info='.$path.'&token='.$this->api_key;
return json_decode(file_get_contents($path, FALSE, stream_context_create($opts)));
}
public function create_project($name, $leader_id) {
return $this->call('/projects/add', array('project' => array('name' => $name, 'leader_id' => $leader_id)));
}
public function add_ticket($project_id, $name) {
return $this->call("/projects/{$project_id}/tickets/add", array('ticket' => array('name' => $name)));
}
public function projects() {
return $this->call('/projects');
}
public function info() {
return $this->call('/info');
}
}
$ac = new ActiveCollab('http://example.com/api.php', 'your-api-key');
$projects = $ac->projects();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment