コード例 #1
0
ファイル: lists.py プロジェクト: dobadev/hubspot-contacts
def _update_contact_list_membership(endpoint_url_path, contacts, connection):
    updated_contact_vids = []

    contacts_batches = ipaginate(contacts, BATCH_SAVING_SIZE_LIMIT)
    for contacts_batch in contacts_batches:
        contact_vids = [c.vid for c in contacts_batch]
        response_data = connection.send_post_request(
            endpoint_url_path,
            {'vids': contact_vids},
        )
        response_data = CONTACT_LIST_MEMBERSHIP_UPDATE_SCHEMA(response_data)

        updated_contact_vids.extend(response_data['updated'])

    return updated_contact_vids
コード例 #2
0
ファイル: lists.py プロジェクト: 2degrees/hubspot-contacts
def _update_contact_list_membership(endpoint_url_path, contacts, connection):
    updated_contact_vids = []

    contacts_batches = ipaginate(contacts, BATCH_SAVING_SIZE_LIMIT)
    for contacts_batch in contacts_batches:
        contact_vids = [c.vid for c in contacts_batch]
        response_data = connection.send_post_request(
            endpoint_url_path,
            {'vids': contact_vids},
            )
        response_data = CONTACT_LIST_MEMBERSHIP_UPDATE_SCHEMA(response_data)

        updated_contact_vids.extend(response_data['updated'])

    return updated_contact_vids
コード例 #3
0
ファイル: __init__.py プロジェクト: 2degrees/hubspot-contacts
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
ファイル: __init__.py プロジェクト: congvd/hubspot-contacts
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,
        )