Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions parsons/etl/table.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import logging
import pickle
from enum import Enum
Expand Down Expand Up @@ -50,6 +51,10 @@ def __init__(
):
self.table = None

#
if inspect.isgenerator(lst):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's very convenient to write pagination code as a generator as i've done in this PR, and imo parsons should support that. #1529

lst = tuple(lst)

# Normally we would use None as the default argument here
# Instead of using None, we use a sentinal
# This allows us to maintain the existing behavior
Expand Down
6 changes: 3 additions & 3 deletions parsons/ngpvan/activist_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_activist_codes(self):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request("activistCodes"))
tbl = Table(self.connection.items("activistCodes"))
logger.info(f"Found {tbl.num_rows} activist codes.")
return tbl

Expand All @@ -37,7 +37,7 @@ def get_activist_code(self, activist_code_id):
The activist code
"""

r = self.connection.get_request(f"activistCodes/{activist_code_id}")
r = self.connection.data(f"activistCodes/{activist_code_id}")
logger.info(f"Found activist code {activist_code_id}.")
return r

Expand All @@ -60,7 +60,7 @@ def toggle_activist_code(
f"{id_type.upper()} {id} {action.capitalize()} " + f"activist code {activist_code_id}"
)

return r
return r.status_code

def apply_activist_code(self, id, activist_code_id, id_type="vanid", omit_contact=True):
"""
Expand Down
12 changes: 6 additions & 6 deletions parsons/ngpvan/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_bulk_import_resources(self):
A list of resources.
"""

r = self.connection.get_request("bulkImportJobs/resources")
r = self.connection.data("bulkImportJobs/resources")
logger.info(f"Found {len(r)} bulk import resources.")
return r

Expand All @@ -41,7 +41,7 @@ def get_bulk_import_job(self, job_id):
The bulk import job
"""

r = self.connection.get_request(f"bulkImportJobs/{job_id}")
r = self.connection.data(f"bulkImportJobs/{job_id}")
logger.info(f"Found bulk import job {job_id}.")
return r

Expand Down Expand Up @@ -77,7 +77,7 @@ def get_bulk_import_mapping_types(self):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request("bulkImportMappingTypes"))
tbl = Table(self.connection.data("bulkImportMappingTypes"))
logger.info(f"Found {tbl.num_rows} bulk import mapping types.")
return tbl

Expand All @@ -92,7 +92,7 @@ def get_bulk_import_mapping_type(self, type_name):
A mapping type json
"""

r = self.connection.get_request(f"bulkImportMappingTypes/{type_name}")
r = self.connection.data(f"bulkImportMappingTypes/{type_name}")
logger.info(f"Found {type_name} bulk import mapping type.")
return r

Expand All @@ -110,7 +110,7 @@ def get_bulk_import_mapping_type_fields(self, type_name, field_name):
A mapping type fields json
"""

r = self.connection.get_request(f"bulkImportMappingTypes/{type_name}/{field_name}/values")
r = self.connection.data(f"bulkImportMappingTypes/{type_name}/{field_name}/values")
logger.info(f"Found {type_name} bulk import mapping type field values.")
return r

Expand Down Expand Up @@ -162,7 +162,7 @@ def post_bulk_import(
result_fields = [{"name": c} for c in result_fields]
json["actions"][0]["columnsToIncludeInResultsFile"] = result_fields

r = self.connection.post_request("bulkImportJobs", json=json)
r = self.connection.post_request("bulkImportJobs", json=json).json()
logger.info(f"Bulk upload {r['jobId']} created.")
return r["jobId"]

Expand Down
6 changes: 3 additions & 3 deletions parsons/ngpvan/canvass_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_canvass_responses_contact_types(self):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request("canvassResponses/contactTypes"))
tbl = Table(self.connection.data("canvassResponses/contactTypes"))
logger.info(f"Found {tbl.num_rows} canvass response contact types.")
return tbl

Expand All @@ -33,7 +33,7 @@ def get_canvass_responses_input_types(self):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request("canvassResponses/inputTypes"))
tbl = Table(self.connection.data("canvassResponses/inputTypes"))
logger.info(f"Found {tbl.num_rows} canvass response input types.")
return tbl

Expand All @@ -46,6 +46,6 @@ def get_canvass_responses_result_codes(self):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request("canvassResponses/resultCodes"))
tbl = Table(self.connection.data("canvassResponses/resultCodes"))
logger.info(f"Found {tbl.num_rows} canvass response result codes.")
return tbl
8 changes: 4 additions & 4 deletions parsons/ngpvan/changed_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_changed_entity_resources(self):
list
"""

r = self.connection.get_request("changedEntityExportJobs/resources")
r = self.connection.data("changedEntityExportJobs/resources")
logger.info(f"Found {len(r)} changed entity resources.")
return r

Expand All @@ -37,7 +37,7 @@ def get_changed_entity_resource_fields(self, resource_type):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request(f"changedEntityExportJobs/fields/{resource_type}"))
tbl = Table(self.connection.data(f"changedEntityExportJobs/fields/{resource_type}"))
logger.info(f"Found {tbl.num_rows} fields for {resource_type}.")
return tbl

Expand Down Expand Up @@ -87,7 +87,7 @@ def get_changed_entities(
"includeInactive": include_inactive,
}

r = self.connection.post_request("changedEntityExportJobs", json=json)
r = self.connection.post_request("changedEntityExportJobs", json=json).json()

while True:
status = self._get_changed_entity_job(r["exportJobId"])
Expand All @@ -100,5 +100,5 @@ def get_changed_entities(
raise ValueError(status["message"])

def _get_changed_entity_job(self, job_id):
r = self.connection.get_request(f"changedEntityExportJobs/{job_id}")
r = self.connection.data(f"changedEntityExportJobs/{job_id}")
return r
10 changes: 5 additions & 5 deletions parsons/ngpvan/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_codes(self, name=None, supported_entities=None, parent_code_id=None, cod
"$top": 200,
}

tbl = Table(self.connection.get_request("codes", params=params))
tbl = Table(self.connection.items("codes", params=params))
logger.info(f"Found {tbl.num_rows} codes.")
return tbl

Expand All @@ -53,7 +53,7 @@ def get_code(self, code_id):
See :ref:`parsons-table` for output options.
"""

c = self.connection.get_request(f"codes/{code_id}")
c = self.connection.data(f"codes/{code_id}")
logger.debug(c)
logger.info(f"Found code {code_id}.")
return c
Expand All @@ -67,7 +67,7 @@ def get_code_types(self):
A list of code types.
"""

lst = self.connection.get_request("codeTypes")
lst = self.connection.data("codeTypes")
logger.info(f"Found {len(lst)} code types.")
return lst

Expand Down Expand Up @@ -131,7 +131,7 @@ def create_code(

json["supportedEntities"] = se

r = self.connection.post_request("codes", json=json)
r = self.connection.post_request("codes", json=json).json()
logger.info(f"Code {r} created.")
return r

Expand Down Expand Up @@ -229,6 +229,6 @@ def get_code_supported_entities(self):
A list of code supported entities.
"""

lst = self.connection.get_request("codes/supportedEntities")
lst = self.connection.data("codes/supportedEntities")
logger.info(f"Found {len(lst)} code supported entities.")
return lst
2 changes: 1 addition & 1 deletion parsons/ngpvan/contact_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_contact_notes(self, van_id):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request(f"people/{van_id}/notes"))
tbl = Table(self.connection.data(f"people/{van_id}/notes"))
logger.info(f"Found {tbl.num_rows} custom fields.")
return tbl

Expand Down
4 changes: 2 additions & 2 deletions parsons/ngpvan/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_custom_fields(self, field_type="contacts"):

params = {"customFieldsGroupType": field_type.capitalize()}

tbl = Table(self.connection.get_request("customFields", params=params))
tbl = Table(self.connection.data("customFields", params=params))
logger.info(f"Found {tbl.num_rows} custom fields.")
return tbl

Expand Down Expand Up @@ -73,6 +73,6 @@ def get_custom_field(self, custom_field_id):
A json.
"""

r = self.connection.get_request(f"customFields/{custom_field_id}")
r = self.connection.data(f"customFields/{custom_field_id}")
logger.info(f"Found custom field {custom_field_id}.")
return r
4 changes: 2 additions & 2 deletions parsons/ngpvan/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_emails(self, ascending: bool = True) -> Table:
"$orderby": "dateModified desc",
}

tbl = Table(self.connection.get_request("email/messages", params=params))
tbl = Table(self.connection.data("email/messages", params=params))
logger.debug(f"Found {tbl.num_rows} emails.")
return tbl

Expand Down Expand Up @@ -66,7 +66,7 @@ def get_email(self, email_id: int, expand: bool = True) -> Table:
),
}

r = self.connection.get_request(f"email/message/{email_id}", params=params)
r = self.connection.data(f"email/message/{email_id}", params=params)
logger.debug(f"Found email {email_id}.")
return r

Expand Down
8 changes: 4 additions & 4 deletions parsons/ngpvan/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_events(
"$expand": expand_fields,
}

tbl = Table(self.connection.get_request("events", params=params))
tbl = Table(self.connection.items("events", params=params))
logger.info(f"Found {tbl.num_rows} events.")
return tbl

Expand Down Expand Up @@ -107,7 +107,7 @@ def get_event(
if expand_fields:
expand_fields = ",".join(expand_fields)

r = self.connection.get_request(f"events/{event_id}", params={"$expand": expand_fields})
r = self.connection.data(f"events/{event_id}", params={"$expand": expand_fields})
logger.info(f"Found event {event_id}.")
return r

Expand Down Expand Up @@ -219,7 +219,7 @@ def create_event(
if code_ids:
event["codes"] = [{"codeID": c} for c in code_ids]

r = self.connection.post_request("events", json=event)
r = self.connection.post_request("events", json=event).json()
logger.info(f"Event {r} created.")
return r

Expand Down Expand Up @@ -271,6 +271,6 @@ def get_event_types(self):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request("events/types"))
tbl = Table(self.connection.data("events/types"))
logger.info(f"Found {tbl.num_rows} events.")
return tbl
4 changes: 2 additions & 2 deletions parsons/ngpvan/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def get_apikeyprofiles(self):
JSON response
"""

response = self.connection.get_request("apiKeyProfiles")
logger.info(f"Returned {len(response[0])} API key profiles.")
response = tuple(self.connection.items("apiKeyProfiles"))
logger.info(f"Returned {len(response)} API key profiles. Returning the first one.")
return response[0]
6 changes: 3 additions & 3 deletions parsons/ngpvan/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_locations(self, name=None):
See :ref:`parsons-table` for output options.
"""

tbl = Table(self.connection.get_request("locations", params={"name": name}))
tbl = Table(self.connection.items("locations", params={"name": name}))
logger.info(f"Found {tbl.num_rows} locations.")
return self._unpack_loc(tbl)

Expand All @@ -38,7 +38,7 @@ def get_location(self, location_id):
dict
"""

r = self.connection.get_request(f"locations/{location_id}")
r = self.connection.data(f"locations/{location_id}")
logger.info(f"Found location {location_id}.")
return r

Expand Down Expand Up @@ -83,7 +83,7 @@ def create_location(
},
}

r = self.connection.post_request("locations/findOrCreate", json=location)
r = self.connection.post_request("locations/findOrCreate", json=location).json()
logger.info(f"Location {r} created.")
return r

Expand Down
10 changes: 5 additions & 5 deletions parsons/ngpvan/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def _people_search(
json_flat = json_format.flatten_json(json)
self._valid_search(**json_flat)

return self.connection.post_request(url, json=json)
return self.connection.post_request(url, json=json).json()

def _valid_search(
self,
Expand Down Expand Up @@ -457,13 +457,13 @@ def get_person(
# Removing the fields that are not returned in MyVoters
NOT_IN_MYVOTERS = ["codes", "contribution_history", "organization_roles"]

if self.connection.db_code == 0:
if self.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})
return self.connection.data(url, params={"$expand": expand_fields})

def delete_person(self, vanid):
"""
Expand All @@ -476,7 +476,7 @@ def delete_person(self, vanid):
Success or error.
"""
url = f"people/{vanid}"
r = self.connection.delete_request(url)
r = self.connection.delete_request(url).json()
logger.info(f"Van ID {vanid} suppressed.")
return r

Expand Down Expand Up @@ -750,5 +750,5 @@ def merge_contacts(self, primary_vanid, source_vanid):
url = f"people/{source_vanid}/mergeInto"
json = {"vanId": primary_vanid}

r = self.connection.put_request(url, json=json)
r = self.connection.put_request(url, json=json).json()
return r
4 changes: 2 additions & 2 deletions parsons/ngpvan/printed_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_printed_lists(

params = {key: value for key, value in params.items() if value is not None}

tbl = Table(self.connection.get_request("printedLists", params=params))
tbl = Table(self.connection.data("printedLists", params=params))

logger.info(f"Found {tbl.num_rows} printed lists.")
return tbl
Expand All @@ -57,6 +57,6 @@ def get_printed_list(self, printed_list_number):
dict
"""

r = self.connection.get_request(f"printedLists/{printed_list_number}")
r = self.connection.data(f"printedLists/{printed_list_number}")
logger.info(f"Found printed list {printed_list_number}.")
return r
Loading
Loading