1.0.14 ā€¢ Published 1 month ago

election-tonight-client v1.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

npm.io

šŸ—³ļø election-tonight-client

NPM Version Reuters open source software

Client for the ElectionTonight API, an API for retrieving U.S. election results and exit polls conducted by Edison Research.

šŸ“š API docs

āš™ļø GitHub Repo

Features

  • āœØ Easy and full-featured API to efficiently retrieve data from the ElectionTonight API in whatever way best suits you.
  • šŸ‡ Fast, efficient and fully typed database queries with Drizzle and Postgres.js.
  • āœ… Tested across multiple elections.
  • šŸ“† Simulates your own election night tests.

Install

npm install election-tonight-client

Quickstart

Initialise the client.

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

// ElectionTonight API key
const API_KEY = 'SECRET';
// ElectionTonight event ID
const EVENT_ID = '20221108';

const client = new ElectionTonightClient(API_KEY, EVENT_ID);

Connect to your PostgreSQL database, using Postgres.js.

const databaseUrl = 'postgresql://localhost:5432/yourdb';

client.connect(databaseUrl);

Setup the event with all its metadata.

await client.setupEvent();

Get all election data in a "sweep" ...

await client.getCountyVotes();
await client.getCalls();
await client.getEditorialTurnout();
await client.getTotalExpectedVote();
await client.getMessages();

... or get just the latest in a "stream."

let updatedEntities = await client.getStreamedCountyVotes();

// Now, do something with the updated entites -- states,
// offices, etc. -- returned from the stream.
for (const updatedEntity of updatedEntites.updated) {
  console.log(`New votes for state: ${updatedEntity.state}`);
}

updatedEntities = await client.getStreamedCalls();
updatedEntities = await client.getStreamedEditorialTurnout();
updatedEntities = await client.getStreamedTotalExpectedVote();
updatedEntities = await client.getStreamedMessages();

Filter requests to only get the county vote data you want.

client.filter({
  states: ['TX', 'KS', 'MO'],
  summary: true,
});

await client.getCountyVotes();

After you've gotten election data from the API, use Drizzle queries to retrieve records from your database.

const states = await client.db.query.state.findMany();

Close the PostgreSQL connection when you're done.

await client.disconnect();

Read more in the client's API docs.

API coverage

Current coverage of ElectionTonight API endpoints. All others are planned by 2024.

Events

endpoint
āœ…event list
āœ…absentee-method
āœ…county-by-elect
āœ…county-by-state
ā­•delegate-district
ā­•delegate-district-type
āœ…election
āœ…election/race
āœ…party-by-office
āœ…party-lookup
ā­•past-county-data
ā­•xtab-setup

Results/streams

endpoint
āœ…county-vote
ā­•delegate-allocation
ā­•delegate-vote
āœ…editorial-turnout
āœ…electoral-vote
āœ…est
āœ…msg
āœ…national-delegate-summary
āœ…total-expected-vote
ā­•xtab

Development

Testing

Setup

Export a DATABASE_URL environment variable or use the built-in ephemeral PostgreSQL testcontainer.

If using testcontainers, you must have a Docker client installed, e.g., Docker Desktop.

Running tests

npm run test

Run specific tests by passing a substring or regular expression to the --grep filter:

npm run test -- --grep 'your-substring'

ā˜‚ļø Code coverage

See coverage report.

1.0.14

1 month ago

1.0.13

2 months ago

1.0.12

2 months ago

1.0.11

2 months ago

1.0.10

2 months ago

1.0.9

2 months ago

1.0.8

2 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago

1.0.4

3 months ago

1.0.3

3 months ago

0.1.10

4 months ago

0.1.9

4 months ago

0.1.8

4 months ago

0.1.7

4 months ago

0.1.4

4 months ago

0.1.3

4 months ago

0.1.6

4 months ago

0.1.5

4 months ago

0.1.0

4 months ago

0.1.2

4 months ago

0.1.1

4 months ago

0.0.4-alpha.5

7 months ago

0.0.4-alpha.6

7 months ago

0.0.4-alpha.7

7 months ago

0.0.4-alpha.8

7 months ago

0.0.4-alpha.1

7 months ago

0.0.4-alpha.2

7 months ago

0.0.4-alpha.3

7 months ago

0.0.4-alpha.4

7 months ago

0.0.1-alpha.120

2 years ago

0.0.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1-alpha.109

2 years ago

0.0.1-alpha.107

2 years ago

0.0.1-alpha.112

2 years ago

0.0.1-alpha.113

2 years ago

0.0.1-alpha.110

2 years ago

0.0.1-alpha.111

2 years ago

0.0.1-alpha.116

2 years ago

0.0.1-alpha.117

2 years ago

0.0.1-alpha.114

2 years ago

0.0.1-alpha.115

2 years ago

0.0.1-alpha.118

2 years ago

0.0.1-alpha.119

2 years ago

0.0.1-alpha.101

2 years ago

0.0.1-alpha.102

2 years ago

0.0.1-alpha.100

2 years ago

0.0.1-alpha.105

2 years ago

0.0.1-alpha.106

2 years ago

0.0.1-alpha.103

2 years ago

0.0.1-alpha.104

2 years ago

0.0.1-alpha.99

2 years ago

0.0.1-alpha.92

2 years ago

0.0.1-alpha.94

2 years ago

0.0.1-alpha.93

2 years ago

0.0.1-alpha.96

2 years ago

0.0.1-alpha.95

2 years ago

0.0.1-alpha.98

2 years ago

0.0.1-alpha.97

2 years ago

0.0.1-alpha.89

2 years ago

0.0.1-alpha.88

2 years ago

0.0.1-alpha.85

2 years ago

0.0.1-alpha.84

2 years ago

0.0.1-alpha.87

2 years ago

0.0.1-alpha.86

2 years ago

0.0.1-alpha.90

2 years ago

0.0.1-alpha.81

2 years ago

0.0.1-alpha.80

2 years ago

0.0.1-alpha.83

2 years ago

0.0.1-alpha.82

2 years ago

0.0.1-alpha.78

2 years ago

0.0.1-alpha.79

2 years ago

0.0.1-alpha.67

2 years ago

0.0.1-alpha.23

2 years ago

0.0.1-alpha.66

2 years ago

0.0.1-alpha.22

2 years ago

0.0.1-alpha.69

2 years ago

0.0.1-alpha.25

2 years ago

0.0.1-alpha.68

2 years ago

0.0.1-alpha.24

2 years ago

0.0.1-alpha.27

2 years ago

0.0.1-alpha.26

2 years ago

0.0.1-alpha.29

2 years ago

0.0.1-alpha.28

2 years ago

0.0.1-alpha.61

2 years ago

0.0.1-alpha.60

2 years ago

0.0.1-alpha.63

2 years ago

0.0.1-alpha.62

2 years ago

0.0.1-alpha.65

2 years ago

0.0.1-alpha.64

2 years ago

0.0.1-alpha.56

2 years ago

0.0.1-alpha.55

2 years ago

0.0.1-alpha.58

2 years ago

0.0.1-alpha.57

2 years ago

0.0.1-alpha.59

2 years ago

0.0.1-alpha.50

2 years ago

0.0.1-alpha.52

2 years ago

0.0.1-alpha.51

2 years ago

0.0.1-alpha.54

2 years ago

0.0.1-alpha.53

2 years ago

0.0.1-alpha.45

2 years ago

0.0.1-alpha.44

2 years ago

0.0.1-alpha.47

2 years ago

0.0.1-alpha.46

2 years ago

0.0.1-alpha.49

2 years ago

0.0.1-alpha.48

2 years ago

0.0.1-alpha.41

2 years ago

0.0.1-alpha.40

2 years ago

0.0.1-alpha.43

2 years ago

0.0.1-alpha.42

2 years ago

0.0.1-alpha.34

2 years ago

0.0.1-alpha.77

2 years ago

0.0.1-alpha.33

2 years ago

0.0.1-alpha.36

2 years ago

0.0.1-alpha.35

2 years ago

0.0.1-alpha.38

2 years ago

0.0.1-alpha.37

2 years ago

0.0.1-alpha.39

2 years ago

0.0.1-alpha.70

2 years ago

0.0.1-alpha.72

2 years ago

0.0.1-alpha.71

2 years ago

0.0.1-alpha.74

2 years ago

0.0.1-alpha.30

2 years ago

0.0.1-alpha.73

2 years ago

0.0.1-alpha.76

2 years ago

0.0.1-alpha.32

2 years ago

0.0.1-alpha.75

2 years ago

0.0.1-alpha.31

2 years ago

0.0.1-alpha.21

2 years ago

0.0.1-alpha.20

2 years ago

0.0.1-alpha.19

2 years ago

0.0.1-alpha.18

2 years ago

0.0.1-alpha.17

2 years ago

0.0.1-alpha.16

2 years ago

0.0.1-alpha.15

2 years ago

0.0.1-alpha.14

2 years ago

0.0.1-alpha.13

2 years ago

0.0.1-alpha.12

2 years ago

0.0.1-alpha.11

2 years ago

0.0.1-alpha.10

2 years ago

0.0.1-alpha.9

2 years ago

0.0.1-alpha.8

2 years ago

0.0.1-alpha.7

2 years ago

0.0.1-alpha.6

2 years ago

0.0.1-alpha.5

2 years ago

0.0.1-alpha.4

2 years ago

0.0.1-alpha.3

2 years ago

0.0.1-alpha.2

2 years ago

0.0.1-alpha.1

2 years ago