Welcome Guest, Not a member yet? Register   Sign In
Basecamp API library
#1

[eluser]Hein[/eluser]
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
Code:
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
Code:
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
Code:
$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)
Code:
// iterate the projects
    foreach($response as $milestone) {
          echo '<pre>';
        print_r($milestone);
        echo '</pre>';
    }

References
- Basecamp PHP methods
- Basecamp API
#2

[eluser]Nekluh[/eluser]
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?
#3

[eluser]Nekluh[/eluser]
Ooops, I was calling http instead of https

Now it's working.
#4

[eluser]Hein[/eluser]
Smile
#5

[eluser]Unknown[/eluser]
Just curious if there are any simplexml libraries out there that are useful in accessing/manipulating the data?
#6

[eluser]Hein[/eluser]
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:
Code:
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.
#7

[eluser]dudeami0[/eluser]
Wrong thread Smile Ignore this
#8

[eluser]davedriesmans[/eluser]
hein,
seems like your Basecamp.zip is removed, you mind resharing?
dave
#9

[eluser]Unknown[/eluser]
can any body please upload again Basecamp.zip ...




Theme © iAndrew 2016 - Forum software by © MyBB