projectal.entities.webhook
1from projectal import api 2from projectal.entity import Entity 3 4 5class Webhook(Entity): 6 """ 7 Implementation of the [Webhook](https://projectal.com/docs/latest/#tag/Webhook) API. 8 """ 9 _path = 'webhook' 10 _name = 'webhook' 11 12 @classmethod 13 def update(cls, entities): 14 # The webhook API differs from the rest of the system. We need to send some 15 # mandatory fields over even if they haven't changed. Do this by faking 16 # the change history to always include the required fields. 17 if isinstance(entities, dict): 18 e_list = [entities] 19 else: 20 e_list = entities 21 22 for e in e_list: 23 if isinstance(e, Webhook): 24 e._Entity__old.pop('entity', None) 25 e._Entity__old.pop('action', None) 26 e._Entity__old.pop('url', None) 27 return super(Webhook, cls).update(e_list) 28 29 @classmethod 30 def list(cls, start=0, limit=101, ksort='entity', order='asc'): 31 """ 32 Get a list of registered webhooks. 33 34 Optionally specify a range for pagination. 35 """ 36 url = '/api/webhook/list?start={}&limit={}&ksort={}&order={}'.\ 37 format(start, limit, ksort, order) 38 return api.get(url) 39 40 @classmethod 41 def list_events(cls, **kwargs): 42 """ 43 Get a list of webhook events. 44 Use parameter format=False to return eventTime as UTC timestamp. 45 """ 46 47 url = '/api/webhookevent/list' 48 49 params = [f'{k}={v}' for k, v in kwargs.items()] 50 if len(params) > 0: 51 url += '?' + '&'.join(params) 52 response = api.get(url) 53 return response
6class Webhook(Entity): 7 """ 8 Implementation of the [Webhook](https://projectal.com/docs/latest/#tag/Webhook) API. 9 """ 10 _path = 'webhook' 11 _name = 'webhook' 12 13 @classmethod 14 def update(cls, entities): 15 # The webhook API differs from the rest of the system. We need to send some 16 # mandatory fields over even if they haven't changed. Do this by faking 17 # the change history to always include the required fields. 18 if isinstance(entities, dict): 19 e_list = [entities] 20 else: 21 e_list = entities 22 23 for e in e_list: 24 if isinstance(e, Webhook): 25 e._Entity__old.pop('entity', None) 26 e._Entity__old.pop('action', None) 27 e._Entity__old.pop('url', None) 28 return super(Webhook, cls).update(e_list) 29 30 @classmethod 31 def list(cls, start=0, limit=101, ksort='entity', order='asc'): 32 """ 33 Get a list of registered webhooks. 34 35 Optionally specify a range for pagination. 36 """ 37 url = '/api/webhook/list?start={}&limit={}&ksort={}&order={}'.\ 38 format(start, limit, ksort, order) 39 return api.get(url) 40 41 @classmethod 42 def list_events(cls, **kwargs): 43 """ 44 Get a list of webhook events. 45 Use parameter format=False to return eventTime as UTC timestamp. 46 """ 47 48 url = '/api/webhookevent/list' 49 50 params = [f'{k}={v}' for k, v in kwargs.items()] 51 if len(params) > 0: 52 url += '?' + '&'.join(params) 53 response = api.get(url) 54 return response
Implementation of the Webhook API.
13 @classmethod 14 def update(cls, entities): 15 # The webhook API differs from the rest of the system. We need to send some 16 # mandatory fields over even if they haven't changed. Do this by faking 17 # the change history to always include the required fields. 18 if isinstance(entities, dict): 19 e_list = [entities] 20 else: 21 e_list = entities 22 23 for e in e_list: 24 if isinstance(e, Webhook): 25 e._Entity__old.pop('entity', None) 26 e._Entity__old.pop('action', None) 27 e._Entity__old.pop('url', None) 28 return super(Webhook, cls).update(e_list)
Save one or more entities of the same type. The entity type is determined by the subclass calling this method. Only the fields that have been modifier will be sent to the server as part of the request.
entities
: Can be a dict
to update a single entity,
or a list of dict
s to update many entities in bulk.
'batch_linking': Enabled by default, batches any link updates required into composite API requests. If disabled a request will be executed for each link update. Recommended to leave enabled to increase performance.
Returns True
if all entities update successfully.
# Example usage:
rebate = projectal.Rebate.create({'name': 'Rebate2022', 'rebate': 0.2})
rebate['name'] = 'Rebate2024'
projectal.Rebate.update(rebate)
# Returns True. New rebate name has been saved.
30 @classmethod 31 def list(cls, start=0, limit=101, ksort='entity', order='asc'): 32 """ 33 Get a list of registered webhooks. 34 35 Optionally specify a range for pagination. 36 """ 37 url = '/api/webhook/list?start={}&limit={}&ksort={}&order={}'.\ 38 format(start, limit, ksort, order) 39 return api.get(url)
Get a list of registered webhooks.
Optionally specify a range for pagination.
41 @classmethod 42 def list_events(cls, **kwargs): 43 """ 44 Get a list of webhook events. 45 Use parameter format=False to return eventTime as UTC timestamp. 46 """ 47 48 url = '/api/webhookevent/list' 49 50 params = [f'{k}={v}' for k, v in kwargs.items()] 51 if len(params) > 0: 52 url += '?' + '&'.join(params) 53 response = api.get(url) 54 return response
Get a list of webhook events. Use parameter format=False to return eventTime as UTC timestamp.
Inherited Members
- projectal.entity.Entity
- get
- delete
- history
- create
- save
- clone
- match
- match_startswith
- match_endswith
- match_one
- match_startswith_one
- match_endswith_one
- search
- query
- profile_get
- profile_set
- changes
- set_readonly
- get_link_definitions
- entity_name
- builtins.dict
- setdefault
- pop
- popitem
- keys
- items
- values
- fromkeys
- clear
- copy