Open replacements for Twitter and more importantly, Tinyurl

Posted on July 8, 2008

3


I hope that you all already know about http://identi.ca and the software stack laconi.ca that it runs – in short, it’s a Twitter-like micro-blogging service, that is geared to be open. It provides the possibility of a distributed micro-blogging set of services that can talk to each other. Pretty cool.

But the less well known release, was that of the lilurl service, a Tinyurl replacement, again, geared to be very open. For example, the database of links the service holds can be downloaded by any user! BUT it lacks an API to create these links on the fly…

I think you’ve already guessed the end of that statement, I’ve made an API for it as the base code for the service is open source. Hearty thanks to Evan Prodromou!

So, changes from the source (which is at: http://ur1.ca/ur1-source.tar.gz)

Firstly, change the .htaccess rewrite rules:

From:

  • RewriteRule (.*) index.php

To:

  • RewriteRule s/(.*) index.php

This requires a few cosmetic changes to the index.php to serve correct lil’urls:

Line 41 in index.php:
From:

  • $url = ‘http://’.$_SERVER['SERVER_NAME'].’/’.$lilurl->get_id($longurl);

To:

  • $url = ‘http://’.$_SERVER['SERVER_NAME'].’/s/‘.$lilurl->get_id($longurl);

And then, in the root directory for the app, add in api.php, which is currently pastebinned:

http://pastebin.com/f29465399 – api.php

How it works – Creating lilurls:

POST to /api.php with parameters of longurl=desired url

This will be the response:

HTTP/1.1 201 Created
Date: Tue, 08 Jul 2008 16:51:13 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/5.1.4
Content-Length: 36
Connection: close
Content-Type: text/html; charset=utf-8

http://somehost.com/s/1

The message body of the response will contain the URL. Similarly, you can lookup a given lilurl, by GET /api.php?id=lilurl_id

GET /api.php?id=1 HTTP/1.1
Host: somehost.com
content-type: text/plain
accept-encoding: compress, gzip
user-agent: Basic Agent

HTTP/1.1 200 OK
Date: Tue, 08 Jul 2008 16:55:00 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/5.1.4
Content-Length: 24
Connection: close
Content-Type: text/html; charset=utf-8

http://ora.ouls.ox.ac.uk

So… er, yeah. Job done ;)

About these ads
Posted in: Uncategorized