Learn design decisions that lead Cloudant to rewrite the supporting API layer to all its backend systems in Python using the Flask microframework to create a unified, RESTFUL API.
is an interface into our support system. It allows users to query open tickets and create new tickets via a RESTful API. """ decorators = [utils.user_required] def __init__(self): """ 'Connect' to fogbugz, wither the real one or a mock object. """ user = current_app.config['FB_USER'] passw = current_app.config['FB_PASS'] if current_app.config['BACKEND'] == "Mock": import mock.fogbugz as fogbugz assert fogbugz # silence pyflakes else: import fogbugz self.fogbugz = fogbugz.FogBugz("https://cloudant.fogbugz.com") self.fogbugz.logon(user, passw)
def get(self): """ List open tickets for the user. Response is a json structure like: {"tickets":[{"id": TICKET_ID, 'title': TICKET_TITLE}, ...]} User name is taken from the session, there must be a valid session to call the api. """ query = '%s status:active OrderBy:Opened' % session['username'], resp = self.fogbugz.search(q=query, cols='ixBug,sTitle') cases = resp.cases.childGenerator() tickets = {'tickets': []} limit = int(request.args.get('limit', 5)) current_app.logger.debug(limit) for case in itertools.islice(cases, limit): tickets['tickets'].append({'id': int(case['ixbug']), 'title': case.stitle.string}) return jsonify(tickets)