Constructors

  • Creates an instance of ElectionTonightClient class.

    Parameters

    • apiKey: string

      ElectionTonight API key

    • eventId: string

      ElectionTonight election event ID

    • logger: Logger = defaultLogger

      Winston Logger instance

    Returns ElectionTonightClient

    Example

    import { ElectionTonightClient } from 'election-tonight-client';

    const client = new ElectionTonightClient('APIKEY', 'EVENTID');

    Backup API

    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 API
    • ELECTION_TONIGHT_CLIENT_API_ROOT=https://... Set a custom API root

Properties

apiKey: string

ElectionTonight API key

eventId: string

ElectionTonight election event ID

logger: Logger = defaultLogger

Winston Logger instance

Methods

  • Parameters

    • pgUri: string
    • pgOptions: {} = {}

      Returns void

    • Checks if the clent has been connected.

      Returns void

    • Checks 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.

      Parameters

      • warnWhenNotSetup: boolean = true

        Log a warning when event is not setup

      Returns Promise<boolean>

      Example

      const eventIsSetup = await client.checkEventSetup();

      if (!eventIsSetup) return;

      client.db // Query models only if the event is setup...
    • 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.

      Returns Promise<void>

      Example

      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.

      Returns Promise<void>

      Example

      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.

      Parameters

      • maxRequests: number = Infinity

        Maximum number of requests to make for documents.

      Returns Promise<{
          maxed: boolean;
          updated: {
              state: number;
              county: string;
              jurisdiction: string;
              office: string;
          }[];
      }>

      Example

      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.

      Returns Promise<void>

      Example

      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.

      Parameters

      • maxRequests: number = Infinity

        Maximum number of requests to make for documents.

      Returns Promise<{
          maxed: boolean;
          updated: {
              state: number;
              jurisdiction: string;
              office: string;
          }[];
      }>

      Example

      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.

      Returns Promise<void>

      Example

      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.

      Parameters

      • maxRequests: number = Infinity

        Maximum number of requests to make for documents.

      Returns Promise<{
          maxed: boolean;
          updated: {
              state: number;
              jurisdiction: string;
              office: string;
          }[];
      }>

      Example

      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.

      Returns Promise<void>

      Example

      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.

      Parameters

      • maxRequests: number = Infinity

        Maximum number of requests to make for documents.

      Returns Promise<{
          maxed: boolean;
          updated: {
              uid: string;
              transmissionSource: string;
              timestamp: Date;
              content: string;
              type: string;
              priority: number;
              securityLevel: number;
              jurisdiction: string;
              state: number;
              jurisdictionRace: string;
          }[];
      }>

      Example

      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.

      Returns Promise<void>

      Example

      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.

      Parameters

      • maxRequests: number = Infinity

        Maximum number of requests to make for documents.

      Returns Promise<{
          maxed: boolean;
          updated: {
              state: number;
              jurisdiction: string;
          }[];
      }>

      Example

      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.

      Returns Promise<void>

      Example

      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.

      Parameters

      • maxRequests: number = Infinity

        Maximum number of requests to make for documents.

      Returns Promise<{
          maxed: boolean;
          updated: {
              uid: string;
              electionType: string;
              jurisdiction: string;
              jurisdictionRace: string;
              state: number;
              county: string;
              totalExpectedAbsenteeVote: number;
              totalExpectedEarlyByMailVote: number;
              totalExpectedEarlyInPersonVote: number;
              totalExpectedElectionDayVote: number;
              totalExpectedVote: number;
              timestamp: Date;
              absenteeVoteProgress: string;
              cancelled: boolean;
              complete: boolean;
              final: boolean;
              precinctReportType: string;
              voteTabulationProgress: string;
              reportingSource: string;
              verified: boolean;
              countyOutstandingBallot: number;
              outstandingVoteType: string;
              totalExpectedVoteMode: string;
              turnoutStage: number;
          }[];
      }>

      Example

      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