def create_contact(self, *args, **kwargs): """Creates a contact""" url = 'contacts' data = { 'view_all_tickets': False, 'description': 'Freshdesk Contact' } data.update(kwargs) return Contact(**self._api._post(url, data=json.dumps(data)))
def list_contacts(self, **kwargs): """ List all contacts, optionally filtered by a query. Specify filters as query keyword argument, such as: [email protected], mobile=1234567890, phone=1234567890, contacts can be filtered by state and company_id such as: state=[blocked/deleted/unverified/verified] company_id=1234 contacts updated after a timestamp can be filtered such as; _updated_since=2018-01-19T02:00:00Z Passing None means that no named filter will be passed to Freshdesk, which returns list of all contacts """ url = "contacts?" page = 1 if not "page" in kwargs else kwargs["page"] per_page = 100 if not "per_page" in kwargs else kwargs["per_page"] contacts = [] # Skip pagination by looping over each page and adding tickets if 'page' key is not in kwargs. # else return the requested page and break the loop while True: this_page = self._api._get( url + "page=%d&per_page=%d" % (page, per_page), kwargs) contacts += this_page if len(this_page) < per_page or "page" in kwargs: break page += 1 return [Contact(**c) for c in contacts]
def update_contact(self, contact_id, **data): url = "contacts/%d" % contact_id return Contact(**self._api._put(url, data=json.dumps(data)))
def get_contact(self, contact_id): url = "contacts/%d" % contact_id return Contact(**self._api._get(url))
def create_contact(self, *args, **kwargs): """Creates a contact""" url = "contacts" data = {"view_all_tickets": False, "description": "Freshdesk Contact"} data.update(kwargs) return Contact(**self._api._post(url, data=json.dumps(data)))