ElectionTonight API key
ElectionTonight election event ID
Winston Logger instance
import { ElectionTonightClient } from 'election-tonight-client';
const client = new ElectionTonightClient('APIKEY', 'EVENTID');
You can use environment variables to change the API root the client uses for requests.
ELECTION_TONIGHT_CLIENT_BACKUP_API=True
Use Edison's backup APIELECTION_TONIGHT_CLIENT_API_ROOT=https://...
Set a custom API rootPrivate
apiElectionTonight API key
Private
eventElectionTonight election event ID
Private
loggerWinston Logger instance
Private
checkChecks if the election event has been setup, which can be used to verify if results methods can be called.
This is likely necessary to call before running any direct database queries during a simulated test with TestSchedule.getTestTime.
Log a warning when event is not setup
const eventIsSetup = await client.checkEventSetup();
if (!eventIsSetup) return;
client.db // Query models only if the event is setup...
Filters events and results.
Filter options
client.filter({ states: ['TX'] });
Resets filters passed to events and results.
client.resetFilter();
Fetches metadata for an election event such as race and candidate definitions and sets up the database.
You should run it then whenever you're setting up a fresh database before you start getting results. You can then continue running it periodically to make sure metadata is up-to-date.
await client.setupEvent();
Gets the latest county vote documents from the results endpoint (results/county-vote
).
A vote document sends vote results for a single, unique contest.
Calling it will also update the streams position for the county votes doc type, so you can use it concurrently with the streams county vote endpoint.
await client.getCountyVotes();
Gets county vote documents from the streams endpoint (streams/county-vote
), which is the fastest way to get just the latest updated vote documents.
Updates the stream position for the county vote doc type if all votes are successfully commited to the database.
Maximum number of requests to make for documents.
const updated = await client.getStreamedCountyVotes();
// Pass a maximum number of requests to make to the API.
const updated = await client.getStreamedCountyVotes(10);
Gets the latest electoral vote documents from the results endpoint (results/electoral-vote
).
A vote document sends vote results for a single, unique contest.
Calling it will also update the streams position for the electoral votes doc type, so you can use it concurrently with the streams electoral vote endpoint.
await client.getElectoralVotes();
Gets electoral vote documents from the streams endpoint (streams/electoral-vote
), which is the fastest way to get just the latest updated vote documents.
Updates the stream position for the electoral vote doc type if all votes are successfully commited to the database.
Maximum number of requests to make for documents.
const updated = await client.getStreamedElectoralVotes();
// Pass a maximum number of requests to make to the API.
const updated = await client.getStreamedElectoralVotes(10);
Gets the latest estimate documents from the results endpoint (results/est
).
An estimate document contains ENS race calls for a single, unique contest.
Calling it will also update the streams position for the estimate doc type, so you can use it concurrently with the streams estimate endpoint.
await client.getCalls();
Gets estimate documents from the streams endpoint (streams/est
), which is the fastest way to get just the latest updated estimate documents.
Updates the stream position for the estimate doc type if all calls are successfully commited to the database.
Maximum number of requests to make for documents.
const updated = await client.getStreamedCalls();
// Pass a maximum number of requests to make to the API.
const updated = await client.getStreamedCalls(10);
Gets the latest message documents from the results endpoint (results/msg
).
A message document contains an election message from the EAS. It is used to commumicate important information such as an increase in total expected vote or a weather problem that is delaying vote count collection.
Calling it will also update the streams position for the message doc type, so you can use it concurrently with the streams message endpoint.
await client.getMessages();
Ges message documents from the streams endpoint (streams/msg
), which is the fastest way to get just the latest updated message documents.
Updates the stream position for the message doc type if all calls are successfully commited to the database.
Maximum number of requests to make for documents.
const updated = await client.getStreamedMessages();
// Pass a maximum number of requests to make to the API.
const updated = await client.getStreamedMessages(10);
Gets the latest editorial turnout documents from the results endpoint (results/editorial-turnout
).
A editorial turnout document contains the voting eligible population and optionally turnout as a percentage of the voting age population.
Calling it will also update the streams position for the editorial turnout doc type, so you can use it concurrently with the streams editorial turnout endpoint.
await client.updateEditorialTurnouts();
Gets editorial turnout documents from the streams endpoint (streams/editorial-turnout
), which is the fastest way to get just the latest updated editorial turnout documents.
Updates the stream position for the editorial turnout doc type if all calls are successfully commited to the database.
Maximum number of requests to make for documents.
const updated = await client.getStreamedEditorialTurnout();
// Pass a maximum number of requests to make to the API.
const updated = await client.getStreamedEditorialTurnout(10);
Gets the latest total expected vote documents from the results endpoint (results/total-expected-vote
).
A total expected vote document contains total expected vote estimate for a county and election. Also contains other information regarding the status of that counties total vote count.
Calling it will also update the streams position for the total expected vote doc type, so you can use it concurrently with the streams total expected vote endpoint.
await client.getTotalExpectedVote();
Gets total expected vote documents from the streams endpoint (streams/total-expected-vote
), which is the fastest way to get just the latest update total expected vote documents.
Updates the stream position for the total expected vote doc type if all calls are successfully commited to the database.
Maximum number of requests to make for documents.
const updated = await client.getStreamedTotalExpectedVote();
// Pass a maximum number of requests to make to the API.
const updated = await client.getStreamedTotalExpectedVote(10);
Generated using TypeDoc
Creates an instance of ElectionTonightClient class.