Пример #1
0
    def __init__(self, node, **attributes):
        """
        Initialize a customer in a node with the specified attributes.

        :param node: the node of the customer supposed to be associated with this event
        :param attributes: key-value arguments for generating the structure of Event's attributes
        """
        convert_properties_obj_in_prop(properties=attributes, properties_class=Properties)
        self.attributes = attributes
        self.node = node
        self.event_api_manager = _EventAPIManager(node=self.node)
Пример #2
0
    def add_customer(self, force_update=False, **attributes):
        """
        Add a new customer in contacthub. If the customer already exist and force update is true, this method will update
        the entire customer with new data

        :param attributes: the attributes for inserting the customer in the node
        :param force_update: a flag for update an already present customer
        :return: the customer added or updated
        """
        convert_properties_obj_in_prop(properties=attributes,
                                       properties_class=Properties)
        return Customer(node=self,
                        **self.customer_api_manager.post(
                            body=attributes, force_update=force_update))
Пример #3
0
    def add_event(self, **attributes):
        """
        Add an event in this node. For adding it and associate with a known customer, specify the customer id in the
        attributes of the Event. For associate it to an external Id or a session id of a customer, specify in the
        bringBackProperties object like:
        {'type':'EXTERNAL_ID',
        'value':'value',
        'nodeId':'nodeId'
        }

        :param attributes: the attributes of the event to add in the node
        :return: a new Event object representing the event added in this node
        """
        convert_properties_obj_in_prop(properties=attributes,
                                       properties_class=Properties)
        self.event_api_manager.post(body=attributes)
        return Event(node=self, **attributes)
    def __init__(self, parent=None, parent_attr=None, **attributes):
        """
        :param parent: the parent that generate this Properties object
        :param parent_attr: the parent attribute for compiling the mutation tracker dictionary
        :param attributes: key-value arguments for generating the structure of the Properties's attributes
        """
        self.parent = parent
        self.mute = {}
        self.parent_attr = parent_attr
        if self.parent:
            try:
                self.mute = parent.mute
            except AttributeError:
                self.mute = parent.customer.mute

        convert_properties_obj_in_prop(properties=attributes,
                                       properties_class=Properties)
        self.attributes = attributes
    def __init__(self, node, default_attributes=None, **attributes):
        """
        Initialize a customer in a node with the specified attributes.

        :param node: the node of the customer
        :param default_attributes: the attributes schema. By default is the following dictionary:
            {
            'base':
                    {
                    'contacts': {}
                    },
            'extended': {},
            'tags': {
                    'manual': [],
                    'auto': []
                    }
            }
        :param attributes: key-value arguments for generating the structure of Customer's attributes
        """

        convert_properties_obj_in_prop(properties=attributes,
                                       properties_class=Properties)
        if default_attributes is None:
            if 'base' not in attributes:
                attributes['base'] = {}

            if 'contacts' not in attributes['base']:
                attributes['base']['contacts'] = {}

            if 'extended' not in attributes or attributes['extended'] is None:
                attributes['extended'] = {}

            if 'tags' not in attributes or attributes['tags'] is None:
                attributes['tags'] = {'auto': [], 'manual': []}
            self.attributes = attributes
        else:
            default_attributes.update(attributes)
            self.attributes = default_attributes

        self.node = node
        self.customer_api_manager = _CustomerAPIManager(node=self.node)
        self.event_api_manager = _EventAPIManager(node=self.node)
        self.mute = {}
Пример #6
0
    def update_customer(self, id, full_update=False, **attributes):
        """
        Update a customer in contacthub with new data. If full_update is true, this method will update the full customer (PUT)
        and not only the changed data (PATCH)

        :param id: the customer ID for updating the customer with new attributes
        :param full_update: a flag for execute a full update to the customer
        :param attributes: the attributes to patch or put in the customer
        :return: the customer updated
        """
        convert_properties_obj_in_prop(properties=attributes,
                                       properties_class=Properties)
        if full_update:
            attributes['id'] = id
            return Customer(node=self,
                            **self.customer_api_manager.put(_id=id,
                                                            body=attributes))
        else:
            return Customer(node=self,
                            **self.customer_api_manager.patch(_id=id,
                                                              body=attributes))