def create_hook(self, callback_url, id_model, desc=None, token=None): """ Creates a new webhook. Returns the WebHook object created. There seems to be some sort of bug that makes you unable to create a hook using httplib2, so I'm using urllib2 for that instead. """ token = token or self.resource_owner_key if token is None: raise TokenError( "You need to pass an auth token in to create a hook.") url = "https://trello.com/1/tokens/%s/webhooks/" % token data = { 'callbackURL': callback_url, 'idModel': id_model, 'description': desc } response = requests.post(url, data=data, auth=self.oauth) if response.status_code == 200: hook_id = response.json()['id'] return WebHook(self, token, hook_id, desc, id_model, callback_url, True) else: return False
def create_hook(self, callback_url, id_model, desc=None, token=None): """ Creates a new webhook. Returns the WebHook object created. There seems to be some sort of bug that makes you unable to create a hook using httplib2, so I'm using urllib2 for that instead. """ token = token or self.resource_owner_key or self.api_secret if token is None: raise TokenError("You need to pass an auth token in to create a hook.") url = "https://trello.com/1/tokens/%s/webhooks/" % token data = {'callbackURL': callback_url, 'idModel': id_model, 'description': desc} if self.api_key is not None: data.update({'key': self.api_key}) response = self.http_service.post(url, data=data, auth=self.oauth, proxies=self.proxies) if response.status_code == 200: hook_id = response.json()['id'] return WebHook(self, token, hook_id, desc, id_model, callback_url, True) else: raise Exception("Webhook creating failed: %s" % response.text)
def _existing_hook_objs(self, hooks, token): """ Given a list of hook dicts passed from list_hooks, creates the hook objects """ all_hooks = [] for hook in hooks: new_hook = WebHook(self, token, hook['id'], hook['description'], hook['idModel'], hook['callbackURL'], hook['active']) all_hooks.append(new_hook) return all_hooks