Node.js wrapper library for the Sunlight Labs API
A Node.js client library for the Sunlight Labs Congress API.
$ [sudo] npm install sunlight
Initialize the API by creating a client and passing your API key as a parameter. If you don't have an API key, you can get one here.
var SunlightClient = SunlightClient;var sunlight = "YOUR_API_KEY";
All available parameters can be found in the documentation.
To get the represenative that represents NC-4:
sunlightlegislators;// Rep. David Price
legislators.getList works much the same way, but reutrns a list. It is possible to do a more complex query, for instance, "all legislators from New York that are Republicans":
sunlightlegislators;// Rep. Pete King// Rep. Christopher Lee
legislators.search allows you to query the database with a less than perfect representation of a legislator's name.
The search is tolerant of use of nicknames, lastname-firstname juxtaposition, initials and minor misspellings. The return is a set of results that include legislator records as well as certainity scores between 0 and 1 (where 1 is most certain).
Search takes two optional parameters:
threshold: the minimum score you want to return, the default is 0.8 and you should rarely go lower than 0.7.
all_legislators: if True will search legislators in the API that are no longer in office (default is False)
An example use of search is as follows:
sunlightlegislators;// Sen. Robert Menendez
legislators.allForZip retrieves all legislators that represent a given zipcode.
This typically means two senators and one (or more) representatives.
To get all legislators that represent the 27511 zipcode:
sunlightlegislators;// Rep. David Price// Sen. Kay Hagan// Sen. Richard Burr// Rep. Brad Miller
legislators.allForLatLong retrieves all legislators representing a given point.
This is a shortcut for calling districts.getDistrictFromLatLong and then looking up the district representative and state senators.
To get all legislators that represent a location in western PA at 41.92, -80.14:
sunlightlegislators;// Sen. Bob Casey// Sen. Arlen Specter// Rep. Kathy Dahlkemper
committee.get gets full details for a given committee, including membership and subcommittees.
Example of getting details for a committee:
sunlightcommittee;// House Committee on Agriculture
committee.getList gets all committees for a given chamber (House, Senate, or Joint).
To see all joint committees for the current Congress:
sunlightcommittee;// Joint Economic Committee// Joint Committee on Printing// Joint Committee on Taxation// Joint Committee on the Library
All for legislator shows all of a legislator's committee and subcommittee memberships.
Showing all of a legislator's committees:
sunlightcommittees;// Senate Committee on Rules and Administration// Senate Committee on Finance// Joint Committee on the Library// Joint Economic Committee// Senate Committee on the Judiciary// Joint Committee on Printing// Senate Committee on Banking, Housing, and Urban Affairs
districts.getDistrictsFromZip fetches all districts that overlap a given zipcode.
To get all districts that overlap 14623:
sunlightdistricts;// NY-29// NY-28
districts.getDistrictFromLatLong finds the district that a given lat-long coordinate pair falls within.
To find out what district 61.13 N, 149.54 W falls within: