EllisLab text mark
Advanced Search
     
Basecamp API library
Posted: 25 September 2010 06:49 AM   [ Ignore ]
Joined: 2009-07-08
8 posts

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

 
Posted: 21 October 2010 10:08 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2010-09-30
10 posts

Cool!

I’ve tried it, but stumpled into a problem.

When trying to do this:
$projects = $this->basecamp->->getProjects();
print_r($projects);

It tries to redirect me to
https://[mycompany].basecamphq.com/projects.xml

And the php doesn’t seem to understand what’s happening.
Did you have any similar problem?

 
Posted: 21 October 2010 10:22 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-09-30
10 posts

Ooops, I was calling http instead of https

Now it’s working.

 
Posted: 21 October 2010 10:35 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2009-07-08
8 posts

smile

 
Posted: 19 November 2010 09:37 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-10-25
1 posts

Just curious if there are any simplexml libraries out there that are useful in accessing/manipulating the data?

 
Posted: 24 November 2010 06:48 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2009-07-08
8 posts

Hi leetaylordoes,

I’m not sure if I get your question correct. But the functions return XML unless you tell it to use SimpleXML.

Usually I would do the following to examine the structure of the returned value:

echo '<pre>';
print_r($returned_value);
echo 
'</pre>'

For in depth questions about the Basecamp API or the Basecamp library I would have to point you to the links I provided at the bottom of my post since that is where the real documentation is.

 
Posted: 24 November 2010 07:15 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-07
93 posts

Wrong thread smile Ignore this

 Signature 

Gfxtub.com - Image Hosting site built on CodeIgniter (Work in progress but fully operational).
Dmail v0.2 - A rewrote/updated email class for CI2 w/ PHP5
- Kris

 
Posted: 08 March 2012 08:34 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2011-02-17
23 posts

hein,
seems like your Basecamp.zip is removed, you mind resharing?
dave

 
Posted: 09 October 2012 05:31 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-09
1 posts

can any body please upload again Basecamp.zip ...

 Signature 

PHP Developer