Launchpad PHP library

A while ago there was a really nice session at #ubuntu-classroom during the UbuntuDeveloperWeek about the Launchpad API(LaunchpadWebService). During this session I said that I started with a implementation in PHP, which at first I meant to be used for the Ubuntu Wanted site. However, I postponed this because it wasn’t necessary anymore for UW and because of the lack of a WADL (dynamic) implementation for PHP, which means that every time a new version of the API is released a lot of changes are needed.

Other things that made me stop were rumours about a Drupal 5 module and a lack of time. I did want to share the small stub I had, though. I uploaded the single file to lp:~qense/+junk/liblp-php. Don’t expect much of it though. All it currently should be able to do is to authenticate itself using OAuth. I just tested it a tiny bit, so there could be a lot of bugs.

I’ll explain how you can authenticate yourself. It’s possible that I’ve made some bad design decissions, but please remember this isn’t even pre-alpha. I didn’t safe OAuth keys, so reusing authentication could be problematic.

You start with calling the contructor by creating a new class. You need at least to pass on two things: the key you want to use, which is used to identify your site and generate the OAuth key and if you’ve got a token from earlier sessions you should pass it as the second argument. A username can be passed as the third argument, although the only thing the class currently does with it, is saving it.

After that you need to call the method auth(), which checks if the user already has given permission to the page to use Launchpad on his/her behalf. If (s)he hasn’t the URL the user needs to surf to is returned, if the user already was authenticated it returns true and when you get the tokens for the first time the tokens are returned. That is probably a very bad practise, but I wanted to get something working quicly so I could test it.

That’s currently all it can do, although I did write two functions which can do GET and POST requests usin cURL. The idea is to let bugs, people and other things be represented by classes, which members can used to manipulate the data. When you do echo classname_of_e.g._bug you should get the link to its page.

Well, that’s just the idea. I’m not sure if it will ever be finished. If anyone is interested in continuing with this I’d be glad to help if (s)he needs me. People don’t have to use it, I just though that I should share it, so people who could be interested would be able to find it.

Feedback is welcome, as always. However, please keep in mind that this code is written in one afternoon and didn’t got any reviews afterwards. This means it can be dangerous to use. ONLY use it on staging.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.