Skip to content

Conversation

@fgregg
Copy link
Contributor

@fgregg fgregg commented Jun 19, 2025

This is an experimental refactor of the API Connector class, applied to the NGP Van code.

It adds

  • automatic retries
  • header management

through using the scraplib's scraper as a drop in replacement for the request session object.

this makes the API connector class much simpler. really just handling URI building and setting up headers. pagination and data unrolling are moved to the van connector class.

despite this PR not being marked as a draft, it should not be merged until more discussion. it is not in draft mode right now in order to allow for comments.

relates to #1456 and #736

@fgregg fgregg marked this pull request as draft June 19, 2025 18:02
@shaunagm shaunagm moved this to In Progress in Parsons Contributor Community Jul 10, 2025
@github-actions
Copy link

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  parsons/etl
  table.py
  parsons/ngpvan
  activist_codes.py
  bulk_import.py 113
  canvass_responses.py
  changed_entities.py
  codes.py
  contact_notes.py
  custom_fields.py
  email.py
  events.py
  introspection.py
  locations.py
  people.py
  printed_lists.py
  saved_lists.py
  scores.py
  signups.py
  supporter_groups.py
  survey_questions.py 64
  targets.py
  van.py 76
  van_connector.py 20-25, 51
  parsons/utilities
  api_connector.py
  api_connector_next.py 31-32, 36-37
Project Total  

This report was generated by python-coverage-comment-action

@fgregg fgregg marked this pull request as ready for review July 14, 2025 20:00
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

URI = "https://api.securevan.com/v4/"
SOAP_URI = "https://api.securevan.com/Services/V3/ListService.asmx?WSDL"

class VANConnector(APIConnector):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the van connector class is the one that knows about pagination and data unboxing.

session = Scraper()
session.auth = ("default", api_key + "|" + str(self.db_code))

self.connection = VANConnector(session=session, uri="https://api.securevan.com/v4/")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

with this pattern we don't need to keep a handle of the api key in this class.

" MyVoters, MyCampaign, MyMembers, EveryAction."
)

session = Scraper()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i like the idea of late binding the sessions object, but i'm not sure this the right pattern.

@fgregg
Copy link
Contributor Author

fgregg commented Jul 14, 2025

this is ready for an initial look and discussion @shaunagm @KasiaHinkson @sharinef1

@shaunagm
Copy link
Collaborator

Great, thanks @fgregg. @KasiaHinkson and @sharinef1 - maybe we could all try to take at least a quick look before the contributor meeting Thursday, so we can talk about it then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants