def get_object(object_type, id=None, **kwargs): """ Returns a object using either id or name. """ # Build our endpoint either direct or filter. if id: endpoint = '%s/%s/?format=json' % (object_type, id) else: args = urllib.urlencode(kwargs) endpoint = '%s/?format=json&%s' % (object_type, args) # Make the HTTP request url = urlparse.urljoin(api, endpoint) response = get(url, username=username, password=password) json = response.json() # If the endpoint was a list view (many results) if json.get('count'): if json.get('count') == 1: return json['results'][0] # if the endpoint was a direct object reference if json.get('id'): return json
def get_latest_builds(branches=None): """ Returns the results of build_latest """ if branches: params = '&'.join([ 'branch=%s' % i for i in branches ]) endpoint = 'build_latest/?format=json&%s' % params else: endpoint = 'build_latest/?format=json' url = urlparse.urljoin(api, endpoint) response = get(url, username=username, password=password) return response.json()