Rock the Vote
Overview
Rock the Vote is an online registration tool. This Parsons connector makes use of Rock the Vote’s Rocky API.
Note
- Authentication
In order to authenticate with the API, users must specify the ID and API key of the RTV partner organization for the data.
QuickStart
To use the RockTheVote
class you can either store the partner ID and API key as an
environmental variable (RTV_PARTNER_ID
and RTV_PARTNER_API_KEY
, respectively), or you can
pass them in as arguments to the class.
from parsons import RockTheVote
# If credentials are specified as environment variables, no need to pass them in
rtv = RockTheVote()
# Pass credentials directly
rtv = RockTheVote(partner_id='123', partner_api_key='supersecretkey')
To fetch a list of registrations submitted for the partner ID, use the run_registration_report method. It is possible to filter the results by providing a parameter to specify a start date for the registrations.
# Get list of registrations
registrants = rtv.run_registration_report(since='2020-01-01')
The run_registration_report will block as the report is being generated and downloaded from the Rocky API. For larger reports, this can take a long time. If you have other things you want to do while the report is running, you can break up the creation of the report from the fetching of the data.
# Create report and get the ID
report_id = rtv.create_registration_report(since='2020-01-01')
# Get registration report
registrants = rtv.get_registration_report(report_id)
API
- class parsons.rockthevote.rtv.RockTheVote(partner_id=None, partner_api_key=None, testing=False)[source]
Instantiate the RockTheVote class
- Args:
- partner_id: str
The RockTheVote partner ID for the RTV account. Not required if the
RTV_PARTNER_ID
environmental variable is set.- partner_api_key: str
The API Key for the partner. Not required if the
RTV_PARTNER_API_KEY
environmental variable is set.- testing: bool
Whether or not to use the staging instance. Defaults to False.
- Returns:
RockTheVote class
- create_registration_report(before=None, since=None, report_type=None)[source]
Create a new registration report.
- Args:
- before: str
Limit to registrations that were started before this date, in ISO format (e.g. 2020-01-01)
- since: str
Limit to registrations that were started since this date, in ISO format (e.g. 2020-01-01)
- report_type: str
The type of report to create. If left as None, it creates the default report. The
extended
report includes additional fields. Currently only acceptsextended
.
- Returns:
- int
The ID of the created report.
- get_registration_report(report_id, block=False, poll_interval_seconds=60, report_timeout_seconds=3600)[source]
Get data from an existing registration report.
- Args:
- report_id: int
The ID of the report to get data from
- block: bool
Whether or not to block execution until the report is complete
- poll_interval_seconds: int
If blocking, how long to pause between attempts to check if the report is done
- report_timeout_seconds: int
If blocking, how long to wait for the report before timing out
- Returns:
- Parsons Table
Parsons table with the report data.
- run_registration_report(before=None, since=None, report_type=None, poll_interval_seconds=60, report_timeout_seconds=3600)[source]
Run a new registration report.
This method will block until the report has finished generating, or until the specified timeout is reached.
- Args:
- before: str
Limit to registrations that were started before this date, in ISO format (e.g. 2020-01-01)
- since: str
Limit to registrations that were started since this date, in ISO format (e.g. 2020-01-01)
- report_type: str
The type of report to run. If left as None, it runs the default report. The
extended
report includes additional fields. Currently only acceptsextended
.- poll_interval_seconds: int
If blocking, how long to pause between attempts to check if the report is done
- report_timeout_seconds: int
If blocking, how long to wait for the report before timing out
- Returns:
- Parsons.Table
The table with the report data.
- get_state_requirements(lang, home_state_id, home_zip_code, date_of_birth=None, callback=None)[source]
Checks state eligibility and provides state specific fields information. Args:
- lang: str
Required. Language. Represented by an abbreviation. ‘en’, ‘es’, etc
- home_state_id: str
Required. 2-character state abbreviation
- home_zip_code: str
Required. ‘zzzzz’ 5 digit zip codes
- date_of_birth: str
Optional. ‘mm-dd-yyyy’
- callback: str
Optional. If used, will change the return value from JSON format to jsonp
- Returns:
- Parsons.Table
A single row table with the response json