Kevin Veroneau avatar Kevin Veroneau committed fa0d7c0

Added ability to retrieve changesets as a set of a Python objects.

Comments (0)

Files changed (1)

 import base64
 import json
 from urllib import urlencode
+import datetime
+class BBFile(object):
+    # Additional functionality will be added to this class in the future.  For now it is a placeholder class.
+    def __init__(self, data):
+        # Python variables "type" and "file" are reserved, and incompatible with the BB API ones.
+        # Any suggestions on other names are welcome, but I believe "action" and "filename" suit it well.
+        self.action = data['type']
+        self.filename = data['file']
+    def __repr__(self):
+        return "<BBFile: %s>" % self.filename
+class Changeset(object):
+    def __init__(self, data):
+        for i in data:
+	    if i is not ['files', 'timestamp']:
+	        setattr(self, i, data[i])
+	self.timestamp = datetime.datetime.strptime(data['timestamp'], "%Y-%m-%d %H:%M:%S")
+	self.files = []
+	for f in data['files']:
+	    self.files.append(BBFile(f))
+    def __repr__(self):
+        return "<Changeset: %s>" % self.node
 class Issue(object):
     title = ""
     def new_issue(self, username, repository):
         return Issue(self, username, repository)
+    def get_changesets(self, username, repository, limit=15):
+        json = self.get('repositories/%s/%s/changesets?limit=%s' % (username, repository, limit))
+        changesets = []
+        for i in json['changesets']:
+	    changesets.append(Changeset(i))
+	return changesets
+    def get_changeset(self, username, repository, changeset):
+        json = self.get('repositories/%s/%s/changesets/%s' % (username, repository, changeset))
+        return Changeset(json)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.