Skip to content

Commit

Permalink
Enable passing identifiers to ActionNetwork upsert_person() (move…
Browse files Browse the repository at this point in the history
…-coop#861)

* Enable passing `identifiers` to ActionNetwork upsert_person

* Remove unused arguments from method

self.get_page method doesn't exist and that method call doesn't return
anything. The return statement works fine as-is to return all tags and
handles pagination on its own.

* Include deprecated per_page argument for backwards compatibility

Emit a deprecation warning if this argument is used

* Include examples in docstring for `identifiers` argument

* Expand documentation on ActionNetwork identifiers
  • Loading branch information
austinweisgrau authored Aug 10, 2023
1 parent de15142 commit 77ead60
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions parsons/action_network/action_network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import re
import warnings

from parsons import Table
from parsons.utilities import check_env
Expand Down Expand Up @@ -100,6 +101,7 @@ def upsert_person(
mobile_number=None,
mobile_status="subscribed",
background_processing=False,
identifiers=None,
**kwargs,
):
"""
Expand Down Expand Up @@ -153,6 +155,16 @@ def upsert_person(
an immediate success, with an empty JSON body, and send your request to the
background queue for eventual processing.
https://actionnetwork.org/docs/v2/#background-processing
identifiers:
List of strings to be used as globally unique
identifiers. Can be useful for matching contacts back
to other platforms and systems. If the identifier
provided is not globally unique in ActionNetwork, it will
simply be ignored and not added to the object. Action Network
also creates its own identifier for each new resouce.
https://actionnetwork.org/docs/v2/#resources
e.g.: ["foreign_system:1", "other_system:12345abcd"]
**kwargs:
Any additional fields to store about the person. Action Network allows
any custom field.
Expand Down Expand Up @@ -217,7 +229,8 @@ def upsert_person(
data["person"]["postal_addresses"] = postal_addresses
if tags is not None:
data["add_tags"] = tags

if identifiers:
data["person"]["identifiers"] = identifiers
data["person"]["custom_fields"] = {**kwargs}
url = f"{self.api_url}/people"
if background_processing:
Expand Down Expand Up @@ -321,21 +334,23 @@ def update_person(self, entry_id, background_processing=False, **kwargs):
logger.info(f"Person {entry_id} successfully updated")
return response

def get_tags(self, limit=None, per_page=25, page=None):
def get_tags(self, limit=None, per_page=None):
"""
`Args:`
limit:
The number of entries to return. When None, returns all entries.
per_page
The number of entries per page to return. 25 maximum.
page
Which page of results to return
per_page:
This is a deprecated argument.
`Returns:`
A list of JSONs of tags in Action Network.
"""
if page:
self.get_page("tags", page, per_page)
return self._get_entry_list("tags", limit, per_page)
if per_page:
warnings.warn(
"per_page is a deprecated argument on get_tags()",
DeprecationWarning,
stacklevel=2,
)
return self._get_entry_list("tags", limit)

def get_tag(self, tag_id):
"""
Expand Down

0 comments on commit 77ead60

Please sign in to comment.