Exemple #1
0
 def get_response(self, request, **values):
     """
     Get a single response from a single request.
     """
     block = {}
     counter = 0
     try:
         reader = YamlReader(values['spec'])
     except IOError:
         pass
     else:
         endpoints = reader.get_calls()
         if 'id' in values and values.get('id', 0) > 0:
             try:
                 endpoint = endpoints[values['id'] - 1]
             except IndexError:
                 pass
             else:
                 block = self.process_call(endpoint)
         elif 'alias' in values:
             while counter < len(endpoints):
                 endpoint = endpoints[counter]
                 if endpoint['alias'] == values['alias']:
                     block = self.process_call(endpoint)
                     break
                 counter += 1
         
     return Response(json.dumps(block))
Exemple #2
0
    def get_batch_of_responses(self, request, **values):
        """
        Get a batch of responses from the respective requests.
        """
        cube = []
        limit = None
        try:
            reader = YamlReader(values['spec'])
        except IOError:
            pass
        else:
            endpoints = reader.get_calls()
            if 'limit' in dict(request.args).keys():
                limit = int(request.args['limit'])
            for endpoint in endpoints:
                if limit != None:
                    limit = limit - 1
                    if limit == -1:
                        break
                cube.append(self.process_call(endpoint))

        return Response(json.dumps(cube))