Exemple #1
0
 def _build_url(self, entity_name, action=None):
     url = '%s/%s/%s' % (self._api_endpoint, self.API_VERSION,
                         simple_pluralize(entity_name))
     if action:
         url += '/' + action
     url += '.json'
     return url
Exemple #2
0
 def get_entity_flow(self, entity_name, entity_id):
     """
     Return the entity list of updates loaded from Pipedrive.
     :param entity_name: The entity name (should be the same as the class name)
     :param entity_id: The entity id
     :return: A list of updates.
     """
     return self._fetch_data(simple_pluralize(entity_name),
                             '%s/flow' % entity_id)
Exemple #3
0
 def put_entity_data(self, entity_name, entity_data, entity_id=None):
     """
     Dump an entity data to Pipedrive.
     :param entity_name: The entity name (should be the same as the class name)
     :param entity_data: The entity data
     :param entity_id: The entity id (update only)
     :return: A dictionary of field keys mapped against their value for the entity
     """
     return self._push_data(simple_pluralize(entity_name), entity_data,
                            entity_id)
Exemple #4
0
 def get_entity_data(self, entity_name, entity_id, entity_fields=None):
     """
     Return an entity data loaded from Pipedrive.
     :param entity_name: The entity name (should be the same as the class name)
     :param entity_id: The entity id
     :param entity_fields: The entity fields to return, default if not specified
     :return: A dictionary of field keys mapped against their value for the entity
     """
     return self._fetch_data(simple_pluralize(entity_name), entity_id,
                             entity_fields)
Exemple #5
0
    def delete_entity(self, entity_name, id_):
        """
        Delete an entity from Pipedrive.
        :param entity_name: The entity name (should be the same as the class name)
        :param id_: The entity id
        :return: A dictionary of field keys mapped against their value for the entity
        """
        return_data = {}

        if id_:
            self._logger.warning('Deleting entity=%s with id=%s', entity_name,
                                 str(id_))

            url = self._build_url(simple_pluralize(entity_name), id_)

            r = self._session.delete(url)
            self._logger.info('Called url=%s', r.url)
            try:
                r.raise_for_status()
            except HTTPError as e:
                if e.response.status_code != 410:  # Pipedrive seems to raise a 410 error during deletion
                    raise e

            data = r.json()

            if 'success' in data:
                if data['success']:
                    return_data = data['data']
                else:
                    self._logger.error('Error=%s', data['error'])
        else:
            self._logger.warning(
                'Cannot delete entity=%s: invalid id (null or empty)',
                entity_name)

        return return_data