Examples

This page contains some basic examples to help you get started. Your feedback on these examples will benefit everyone, and we’re eager for input on improvements. We’d also appreciate help translating the samples into more languages.

Please don’t hesitate to contact us at info@ohloh.net.

BASH

This example uses curl to pull an Account from Ohloh. A simple sed hack parses the XML response into name:value pairs.

Download account_sample.sh

The example demonstrates data retrieval using email address lookup. Pass your API key and the email address of the Account you are requsting as parameters to the script:

./account_sample.sh YOUR_API_KEY_HERE robin@ohloh.net 

The script isn’t very robust — sed is not the world’s best XML parser — but it does return a non-zero exit code if the record is not found or some other problem occurs.

Ruby

Using Ruby with the REXML library, you can build a more robust interface to the Ohloh API. This example performs the same email-based account lookup, but uses more rigorous error handling and parsing to create a structured XML document object.

Download account_sample.rb

Execute the script by passing your API key and an email address as parameters:

ruby account_sample.rb YOUR_API_KEY_HERE robin@ohloh.net 
Python

This Python code sample performs a similar account lookup on Ohloh. It requires urllib, hashlib and elementtree.

Download account_sample.py

Execute the script by passing your API key and an email address as parameters:

./account_sample.py YOUR_API_KEY_HERE robin@ohloh.net 

Many thanks to Thijs Triemstra for contributing this sample.

Perl

This Perl code sample uses performs a similar account lookup on Ohloh. It requires the LWP::Simple, Digest::MD5, and XML::Simple libraries.

Download account_sample.pl

Execute the script by passing your API key and an email address as parameters:

./account_sample.pl YOUR_API_KEY_HERE robin@ohloh.net 

Many thanks to Yanick Champoux for contributing this sample.

Java

This example uses Java’s networking capabilities to pull an Account from Ohloh. It demonstrates how to generate an MD5 hash of an email address to use as a lookup key, then uses DOM to parse the XML response.

Download ApiExample.java

Pass your API key and the email address of the Account you are requesting as parameters:

javac ApiExample.java java ApiExample YOUR_API_KEY_HERE robin@ohloh.net 
C++

The C++ example is a bit more involved, because it must include code for networking, MD5 hashing, and XML parsing. This example includes source for some small libraries to create a self-contained program.

Download ApiExample.cpp.zip

The code was written for Visual Studio 2005, but it also compiles and runs on Mac OS X, and should work on Linux. Let us know if you encounter trouble on your platform.

To build with Visual Studio 2005:
* Open solution file build/vs2005/OhlohApiExample.sln
* Right-click the solution and choose Build.

To build on Linux or Mac OS X, expand the zip file and run the build script:

./compile.sh 

You can then run the executable called ApiExample and pass it your API key and an email address:

./bin/ApiExample YOUR_API_KEY_HERE robin@ohloh.net 

Many thanks to Lars ‘Levia’ Wesselius for providing the sample code in both C++ and Java!

PHP

Paul Scott has created a full-featured PHP class for accessing the Ohloh API, complete with documentation. You can find it at the PHP Classes website.