Switch to side-by-side view

--- a
+++ b/osp-api.py
@@ -0,0 +1,80 @@
+"""
+A quick example on how to use the Allura REST API
+"""
+
+
+import requests
+import json
+from urlparse import urljoin
+BASE = 'http://opensourceprojects.eu/rest/'
+
+class ApiException(Exception):
+    pass
+
+class Api:
+    "A quick helper class to call the api"
+
+    def __init__(self, baseurl=BASE):
+        self._baseurl = baseurl
+
+    def project(self, projname, neigh='p'):
+        """
+        Retrieve project info
+        """
+
+        url = urljoin(self._baseurl, '%s/%s' % (neigh, projname))
+        r = requests.get(url)
+        if r.status_code != 200:
+            raise ApiException('Error making API call to %s' %url)
+        if r.headers.get('content-type', '') != 'application/json; charset=utf-8':
+            raise ApiException('Expecting a json document but failed at %s' %url)
+
+        return r.json()
+
+    def fetch(self, projname, mount, neigh='p'):
+        """
+        A helper method to fetch from a tool in a
+        certain mount point(path)
+        """
+        url = urljoin(self._baseurl, '%s/%s/%s' % (neigh, projname,mount))
+        r = requests.get(url)
+        if r.status_code != 200:
+            raise ApiException('Error making API call to %s' % url)
+        if r.headers.get('content-type', '') != 'application/json; charset=utf-8':
+            raise ApiException('Expecting a json document but failed at %s' %url)
+        return r.json()
+
+if __name__ == '__main__':
+
+    api = Api()
+    resp = api.project('osp')
+    print('Project Name: ' + resp['name'])
+    print('Tools in this project:')
+
+    for t in resp['tools']:
+        print( '    %s:%s' % (t['name'], t['label']))
+
+        try:
+            toolinfo = api.fetch(resp['name'], t['mount_point'] )
+        except ApiException:
+            print('        Unable to retrieve data for this tool')
+            continue
+            
+        if t['name'] == 'wiki':
+            # If the tool is wiki, we can
+            # fetch the page list
+            if 'pages' in toolinfo:
+                print('        ' + ','.join(toolinfo['pages']))
+        elif t['name'] == 'tickets':
+            # The ticket tool provides a list of tickets
+            # I'm just going to print a ticket count
+            print('        Ticket count: %d' % toolinfo['count'])
+        elif t['name'] == 'git':
+            print('        Commit count: %d' % toolinfo['commit_count'])
+        else:
+            #
+            # I don't know the details for the the other tools
+            #
+            print('        ' + toolinfo)
+
+