I needed to import our messages from BaseCamp and slap them into our new project management site which runs Drupal of course. We had to get all of the messages and assign them back to their appropriate users and to their appropriate projects etc... and well REST is always easy and everything but their is no sense in re-inventing the wheel so I used the BaseCamp class provided by Pratthost Developer Zone simple enough it supported almost everything I wanted to do and other things it didn't well I did what every right minded programmer would do... extended it.
<?php include 'class.Basecamp.php'; class AdvomaticBasecamp extends Basecamp { private $post_id; public function get_message_archive() { if (!$this->get_project_id()) { return FALSE; } $messages = $this->get_xml('projects/' . $this->get_project_id() . '/posts/archive.xml'); return $messages->post; } public function get_message() { if (!$this->get_post_id()) { return FALSE; } if (!$this->get_project_id()) { return FALSE; } $message = $this->get_xml('projects/' . $this->get_project_id() . '/posts/' . $this->get_post_id() . '.xml'); return $message; } public function get_comments() { if (!$this->get_post_id()) { return FALSE; } if (!$this->get_project_id()) { return FALSE; } $comments = $this->get_xml('projects/' . $this->get_project_id() . '/posts/' . $this->get_post_id() . '/comments.xml'); return $comments; } public function get_person($pid) { $person = $this->get_xml('/contacts/person/' . $pid); return $person; } public function get_category($category_id) { if (!$category_id) { return FALSE; } if (!$this->get_project_id()) { return FALSE; } $category = $this->get_xml('projects/' . $this->get_project_id() . '/categories/' . $category_id . '.xml'); return $category; } public function set_post_id($id) { $this->post_id = $id; } public function get_post_id() { return $this->post_id; } } ?>
For my Drupal import module integration I had a module that would get the data and then essentially do a node_save for the nodes and put the data in its rightful place w/ making sure that all the API elements of Drupal had a chance to fire.
The key to implementing the class into Drupal was to have a function that could be called to get the BaseCamp object or create a new one if one did not exists.
function example_basecamp() { static $basecamp; if (empty($basecamp)) { include 'lib/class.AdvomaticBasecamp.php'; $basecamp = new AdvomaticBasecamp({'BASECAMP URL'}, '{USERNAME}', '{PASSWORED}'); } return $basecamp; }
function example_import_archive_messages() { // Get the BaseCamp Object so that I can get data. $basecamp = example_basecamp(); $basecamp->set_project_id('123456'); $basecamp->set_post_id('123456'); $message = $basecamp->get_message(); // Save the message as a node... }
Have Fun!