Beispiel #1
0
    def _build_json_args(field_data=None, entity_type=None):
        # HP Alm is very particular about JSON ordering - we must craft it in a specific way
        args = []

        if field_data:
            fields_values = []
            for key, value in field_data:
                if type(value) is not ListType:
                    value = [value]

                values = [dict(value=v) for v in value]
                fields_values.append('{"Name": %s, "values": %s}' % (json.dumps(key), json.dumps(values)))
            args.append('"Fields": [%s]' % ','.join(fields_values))
        if entity_type:
            args.append('"Type": %s' % json.dumps(entity_type))

        return '{%s}' % ','.join(args)
Beispiel #2
0
    def handle(self):
        all_funcs = self.list_functions()
        if self.config['api_func'] not in all_funcs:
            raise UsageError('Invalid function: %s\nAvailable choices are:\n  %s\n' % 
                    (self.config['api_func'], '\n  '.join(all_funcs)))
        
        try:
            args = urlparse.parse_qs(self.config['api_args'])
        except:
            raise UsageError('Unable to URL Dcode value: %s' % (self.config['api_args'][:200]))
        for key in args:
            args[key] = ''.join(args[key])
            
        ret = getattr(self.api, self.config['api_func'])(**args)

        print json.dumps(ret)
        return
 def encode_post_args(self, args, call_headers):
     if 'Content-type' in call_headers and 'json' in call_headers['Content-type']:
         return json.dumps(args)
     return args