Skip to content

notioncollective/propublica-congress-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

propublica-congress-node

NPM

Build Status

Big ups to Nick Bottomley (https://github.com/nickb1080), who wrote most of this code. We've just updated it to hit the updated ProPublica endpoints, as the API is now maintained there.

Node wrapper for ProPublica Congress API (formerly NYT). REST API Docs.

Usage

  var Congress = require( 'propublica-congress-node' );
  var client = new Congress( API_KEY );

  client.memberLists({
    congressNumber: '114',
    chamber: 'house'
  }).then(function(res) {
    console.log(res);
  });

This package works in the browser. To generate a version that will provide a Congress browser global, go to the project root and run (assuming you have browserify installed globally):

browserify -s Congress ./ > congress-browser.js

Fair warning: the standalone, browserified pacakage is pretty darn big.

propublica-congress-node is a straight-forward wrapper around the ProPublica Congress API (formerly maintained by the NYT). The ProPublica site has comprehensive documentation as well as example results for each query.

Internally, propublica-congress-node uses string interpolation on the API endpoints detailed in the API documentation. For example, the bill details endpoint has a url structure as follows

https://api.propublica.org/congress/{version}/{congress-number}/{chamber}/members.{response-format}

A valid request needs to fill in this URL with the following parameters: version, congress-number, chamber, and a response-format.

Of these, only chamber is required. The version defaults to 'v1' (the only version, currently), congress-number defaults to 114 (the current congress, in 2017), and response-format defaults to JSON (also the only offering, currently).

Each method takes a parameters object, which it "dasherizes" (turns the keys from camelCase to dash-case), then interpolates these values into the string.

The API key (request one from ProPublica) must be passed to the constructor and is automatically added to every request in the X-API-Key header.

The example at the top

  var Congress = require( 'propublica-congress-node' );
  var client = new Congress( 'API_KEY' );

  client.memberLists({
    chamber: 'house'
  }).then(function(res) {
    console.log(res);
  });

will dispatch a request to the following URL:

https://api.propublica.org/congress/v0/114/house/members.json

Every method returns a ES6 Promise.

API

Bills

.billsRecent()

Endpoint documentation: Recent bills

Parameters:

- congressNumber
- chamber
- billType

.billsByMember()

Endpoint documentation: Bills by member

Parameters:

- memberId
- billType

billDetails()

Endpoint documentation: Bill details

Parameters:

- congressNumber
- billId

billSubjects()

Endpoint documentation: Bill subjects, amendments, and related bills with type set to "subjects"

Parameters:

- congressNumber
- billId

billAmendments()

Endpoint documentation: Bill subjects, amendments, and related bills with type set to "amendment"

Parameters:

- congressNumber
- billId

billRelatedBills()

Endpoint documentation: Bill subjects, amendments, and related bills with type set to "related"

Parameters:

- congressNumber
- billId

billCosponsors()

Endpoint documentation: Bill cosponsors

Parameters:

- congressNumber
- billId

Members

memberLists()

Endpoint documentation: Member lists

Parameters:

- congressNumber
- chamber

memberBioAndRoles()

Endpoint documentation: Member detail, bio and roles

Parameters:

- memberId

membersNew()

Endpoint documentation: New members

Parameters:

- _None_

membersCurrentByStateOrDistrict()

Endpoint documentation: Current members by state/district

Parameters:

- chamber
- state
- district (for house only)

membersLeavingOffice()

Endpoint documentation: Members leaving office

Parameters:

- congressNumber
- chamber

memberVotePositions()

Endpoint documentation: Member vote positions

Parameters:

- memberId

memberVoteComparison()

Endpoint documentation: Member vote comparison

Parameters:

- memberId1
- memberId2
- congressNumber
- chamber

memberSponsorshipComparison()

Endpoint documentation: Member cosponsorship comparison

Parameters:

- memberId1
- memberId2
- congressNumber
- chamber

memberCosponsoredBills()

Endpoint documentation: Bills cosponsored by a member

Parameters:

- memberId
- type ('cosponsored' or 'withdrawn')

memberFloorAppearances()

Endpoint documentation: Member floor appearances Not yet implemented in ProPublica API, but maybe coming soon.

Parameters:

- memberId

Nominees

nomineeLists()

Endpoint documentation: Nominee lists

Parameters:

- congressNumber
- type ('received', 'updated', 'confirmed', 'withdrawn')

nomineeDetails()

Endpoint documentation: Nominee details

Parameters:

- congressNumber
- nomineeId

nomineesByState()

Endpoint documentation: Nominees by state

Parameters:

- congressNumber
- state

Other

statePartyCounts()

Endpoint documentation: State party counts

Parameters:

- _NONE_

committeeList()

Endpoint documentation: Committees and committee members but doesn't accept a committee id

Parameters:

- congressNumber
- chamber

committeeRoster()

Endpoint documentation: Committees and committee members but requires a committee id

Parameters:

- congressNumber
- chamber
- committeeId

Votes

votesRollCall()

Endpoint documentation: Roll-call votes

Parameters:

- congressNumber
- chamber
- sessionNumber
- rollCallNumber

votesByType()

Endpoint documentation: Votes by type

Parameters:

- congressNumber
- chamber
- voteType

votesByDate()

Endpoint documentation: Votes by date

Parameters:

- chamber
- year
- month

votesNominations()

Endpoint documentation: nominationVotes

Parameters:

- congressNumber

Parameter Validation

propublica-congress-node validates all parameters passed to methods. Generally, parameter strings are checked with contains, alphanumeric, numeric, and date. Contains checks if a value is in a pre-set list. Each parameter will also accept the camelCased version of it's key.

'bill-id': alphanumeric
'bill-type': contains // => ['introduced', 'updated', 'passed', 'major']
'chamber': contains // => ['house', 'senate']
'committee-id': alphanumeric,
'congress-number': contains // => [105, 106, 107, 108, 109, 110, 111, 112, 113]
'cosponsor-type': contains // => ['cosponsored', 'withdrawn']
'district': numeric
'end-date': date
'member-id': alphanumeric
'member-id-2': alphanumeric
'member-id-1': alphanumeric
'nomination-category': contains // => ['received', 'updated', 'confirmed', 'withdrawn']
'nominee-id': alphanumeric
'resource': contains // => ['subjects', 'amendments', 'related'] ),
'response-format': contains // => ['.json', '.xml']
'roll-call-number': numeric
'session-number': numeric
'start-date': date
'state': contains // => ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
'vote-type': contains // => ['missed_votes', 'party_votes', 'loneno', 'perfect'] ),
'version': // => must be v3
'year': numeric
'month': numeric

About

JS client for ProPublica Congress API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%