Skip to content

Commit

Permalink
Enable email dict to be passed to VAN.upsert_person()
Browse files Browse the repository at this point in the history
This allows for greater configurability of email data when upserting
person records in EveryAction. This change is backwards compatible,
but allows, for example, setting emails to not be subscribed by
default when loading into EveryAction.
  • Loading branch information
austinweisgrau committed Jan 31, 2024
1 parent e515096 commit 0334c36
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions parsons/ngpvan/people.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from parsons.utilities import json_format
from typing import Union, List, Dict
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -197,7 +198,7 @@ def upsert_person(
first_name=None,
last_name=None,
date_of_birth=None,
email=None,
email: Union[str, List[Dict[str, Union[str, bool]]], None] = None,
phone=None,
phone_type=None,
street_number=None,
Expand Down Expand Up @@ -227,8 +228,10 @@ def upsert_person(
The person's last name
dob: str
ISO 8601 formatted date of birth (e.g. ``1981-02-01``)
email: str
The person's email address
email: Union[str, List[Dict[str, Union[str, bool]]], None]
The person's email address or a list of email dicts.
e.g. [{'email': 'abcd@gmail.com', 'isSubscribed': False}]
See https://docs.everyaction.com/reference/people-common-models#email
phone: str
Phone number of any type (Work, Cell, Home)
phone_type: str
Expand Down Expand Up @@ -298,7 +301,7 @@ def _people_search(
first_name=None,
last_name=None,
date_of_birth=None,
email=None,
email: Union[str, List[Dict[str, Union[str, bool]]], None] = None,
phone=None,
phone_type="H",
street_number=None,
Expand All @@ -320,7 +323,14 @@ def _people_search(

# Will fail if empty dicts are provided, hence needed to add if exist
if email:
json["emails"] = [{"email": email}]
if isinstance(email, str):
json["emails"] = [{"email": email}]
elif isinstance(email, list):
json["emails"] = email
else:
raise ValueError(
f"Unexpected data type for email argument: {type(email)}"
)
if phone: # To Do: Strip out non-integers from phone
json["phones"] = [{"phoneNumber": phone, "phoneType": phone_type}]
if date_of_birth:
Expand Down

0 comments on commit 0334c36

Please sign in to comment.