Example #1
0
    def get_person(self,
                   id,
                   id_type='vanid',
                   fields=[
                       'emails', 'phones', 'custom_fields', 'external_ids',
                       'addresses', 'recorded_addresses', 'preferences',
                       'suppressions', 'reported_demographics',
                       'disclosure_field_values'
                   ]):
        """
        Returns a single person record using their VANID or external id.

        `Args:`
            id: str
                A valid id
            id_type: str
                A known person identifier type available on this VAN instance
                such as ``dwid``
            fields: The fields to return. Leave as default for all available fields
        `Returns:`
            A person dict
        """

        # Change end point based on id type
        if id_type == 'vanid':
            url = f'people/{id}'
        else:
            url = f'people/{id_type}:{id}'

        fields = ','.join([json_format.arg_format(f) for f in fields])

        logger.info(f'Getting person with {id_type} of {id}')
        return self.connection.get_request(url, params={'$expand': fields})
Example #2
0
    def get_person(self,
                   id,
                   id_type='vanid',
                   expand_fields=[
                       'contribution_history', 'addresses', 'phones', 'emails',
                       'codes', 'custom_fields', 'external_ids', 'preferences',
                       'recorded_addresses', 'reported_demographics',
                       'suppressions', 'cases', 'custom_properties',
                       'districts', 'election_records', 'membership_statuses',
                       'notes', 'organization_roles', 'disclosure_field_values'
                   ]):
        """
        Returns a single person record using their VANID or external id.

        `Args:`
            id: str
                A valid id
            id_type: str
                A known person identifier type available on this VAN instance
                such as ``dwid``. Defaults to ``vanid``.
            expand_fields: list
                A list of fields for which to include data. If a field is omitted,
                ``None`` will be returned for that field. Can be ``contribution_history``,
                ``addresses``, ``phones``, ``emails``, ``codes``, ``custom_fields``,
                ``external_ids``, ``preferences``, ``recorded_addresses``,
                ``reported_demographics``, ``suppressions``, ``cases``, ``custom_properties``,
                ``districts``, ``election_records``, ``membership_statuses``, ``notes``,
                ``organization_roles``, ``scores``, ``disclosure_field_values``.
        `Returns:`
            A person dict
        """

        # Change end point based on id type
        url = 'people/'

        id_type = '' if id_type in ('vanid', None) else f"{id_type}:"
        url += id_type + str(id)

        # Removing the fields that are not returned in MyVoters
        NOT_IN_MYVOTERS = [
            'codes', 'contribution_history', 'organization_roles'
        ]

        if self.connection.db_code == 0:
            expand_fields = [
                v for v in expand_fields if v not in NOT_IN_MYVOTERS
            ]

        expand_fields = ','.join(
            [json_format.arg_format(f) for f in expand_fields])

        logger.info(
            f'Getting person with {id_type or "vanid"} of {id} at url {url}')
        return self.connection.get_request(url,
                                           params={'$expand': expand_fields})
Example #3
0
def test_json_format():
    assert json_format.arg_format('my_arg') == 'myArg'