예제 #1
0
    def __call__(self):
        if not self._contacts_by_page:
            return []

        api_calls = self._available_properties_simulator()

        for batch_contacts in self._contacts_by_page:
            request_body_deserialization = format_contacts_data_for_saving(
                batch_contacts, self._property_type_by_property_name
            )
            api_call = SuccessfulAPICall(
                CONTACTS_API_SCRIPT_NAME + "/contact/batch/",
                "POST",
                request_body_deserialization=request_body_deserialization,
                response_body_deserialization=None,
            )
            api_calls.append(api_call)

        return api_calls
예제 #2
0
    def __call__(self):
        if not self._contacts_by_page:
            return []

        api_calls = self._available_properties_simulator()

        for batch_contacts in self._contacts_by_page:
            request_body_deserialization = format_contacts_data_for_saving(
                batch_contacts,
                self._property_type_by_property_name,
            )
            api_call = SuccessfulAPICall(
                CONTACTS_API_SCRIPT_NAME + '/contact/batch/',
                'POST',
                request_body_deserialization=request_body_deserialization,
                response_body_deserialization=None,
            )
            api_calls.append(api_call)

        return api_calls
예제 #3
0
def save_contacts(contacts, connection):
    """
    Request the creation and/or update of the ``contacts``.
    
    :param iterable contacts: The contacts to be created/updated
    :return: ``None``
    :raises hubspot.connection.exc.HubspotException:
    :raises hubspot.contacts.exc.HubspotPropertyValueError: If one of the
        property values on a contact is invalid.
    
    For each contact, only its email address and properties are passed to
    HubSpot. Any other datum (e.g., the VID) is ignored.
    
    As at this writing, this end-point does not process the requested changes
    immediately. Instead, it **partially** validates the input and, if it's all
    correct, the requested changes are queued.
    
    End-point documentation:
    http://developers.hubspot.com/docs/methods/contacts/batch_create_or_update
    
    """
    contacts_batches = ipaginate(contacts, BATCH_SAVING_SIZE_LIMIT)

    contacts_first_batch = next(contacts_batches, None)
    if not contacts_first_batch:
        return

    property_type_by_property_name = \
        get_property_type_by_property_name(connection)

    for contacts_batch in chain([contacts_first_batch], contacts_batches):
        contacts_batch_data = format_contacts_data_for_saving(
            contacts_batch,
            property_type_by_property_name,
            )
        connection.send_post_request(
            _CONTACTS_SAVING_URL_PATH,
            contacts_batch_data,
            )
예제 #4
0
def save_contacts(contacts, connection):
    """
    Request the creation and/or update of the ``contacts``.
    
    :param iterable contacts: The contacts to be created/updated
    :return: ``None``
    :raises hubspot.connection.exc.HubspotException:
    :raises hubspot.contacts.exc.HubspotPropertyValueError: If one of the
        property values on a contact is invalid.
    
    For each contact, only its email address and properties are passed to
    HubSpot. Any other datum (e.g., the VID) is ignored.
    
    As at this writing, this end-point does not process the requested changes
    immediately. Instead, it **partially** validates the input and, if it's all
    correct, the requested changes are queued.
    
    End-point documentation:
    http://developers.hubspot.com/docs/methods/contacts/batch_create_or_update
    
    """
    contacts_batches = ipaginate(contacts, BATCH_SAVING_SIZE_LIMIT)

    contacts_first_batch = next(contacts_batches, None)
    if not contacts_first_batch:
        return

    property_type_by_property_name = \
        get_property_type_by_property_name(connection)

    for contacts_batch in chain([contacts_first_batch], contacts_batches):
        contacts_batch_data = format_contacts_data_for_saving(
            contacts_batch,
            property_type_by_property_name,
        )
        connection.send_post_request(
            _CONTACTS_SAVING_URL_PATH,
            contacts_batch_data,
        )