Ejemplo n.º 1
0
 def __call__(self, *args, **kwargs):
     json_data = serialize_action_arguments(*args, **kwargs)
     if json_data:
         data = json.dumps(json_data.json)
     else:
         if 'accepts' in self.spec:
             raise SpecError("%s takes arguments" % self.spec['name'])
         data = ""
     url = self.api_url + '/actions/' + self.spec['name']
     headers = { 'Content-Type': 'application/json' }
     res = requests.post(url, data=data, headers=headers)
     if res.status_code != requests.codes.ok:
         if res.json and 'error' in res.json:
             raise APIError(res.json['error'])
         else:
             raise APIError("Call to %s failed with improper error response")
     return res.json
Ejemplo n.º 2
0
 def __call__(self, *args, **kwargs):
     # This seems redundant, but is necessary to make sure local
     # actions behave same as remote ones
     data = serialize_action_arguments(*args, **kwargs)
     return apply_to_action_func(self.raw_func, data)