Skip to content
lobostome edited this page Jun 24, 2013 · 1 revision

To instantiate this provider use FurryBear\Provider\Source\SunlightCongress.

API key

The Sunlight Congress API requires a valid API key.

Output strategies

The result the API returns is in json format. The available strategies are:

  • FurryBear\Output\Strategy\JsonToArray
  • FurryBear\Output\Strategy\JsonToObject

Resources

The various Sunlight Foundation Congress API endpoints can be accessed via properties of the FurryBear\FurryBear object.

  • legislators: Current legislators' names, IDs, biography, and social media.
  • legislators_locate: Find representatives and senators for a latitude/longitude or zip.
  • districts_locate: Find congressional districts for a latitude/longitude or zip.
  • committees: Current committees, subcommittees, and their membership.
  • bills: Legislation in the House and Senate, back to 2009. Updated daily.
  • bills_search: Full text search over legislation.
  • votes: Roll call votes in Congress, back to 2009. Updated within minutes of votes.
  • floor_updates: To-the-minute updates from the floor of the House and Senate.
  • hearings: Committee hearings in Congress. Updated as hearings are announced.
  • upcoming_bills: Bills scheduled for debate in the future, as announced by party leadership.
  • bulk_data: Downloadable data: legislator spreadsheet, zip codes to congressional districts, and legislator photos

Example:

$fb->bills_search;

Setting parameters

Setting request criteria can be done in three different way. Choose the one you are most comfortable with:

  • Using setParams() method
$params = array('last_name'    => 'Smith',
                'fields'       => 'first_name,last_name,state,title',
                'order'        => 'state__asc,first_name__asc');
$fb->legislators->setParams($params);
$fb->legislators->get();
  • Passing them directly to the get() method
$params = array('last_name'    => 'Smith',
                'fields'       => 'first_name,last_name,state,title',
                'order'        => 'state__asc,first_name__asc');
$fb->legislators->get($params);
  • Using a chainable interface
$fb->bills_search->fields('official_title', 'chamber', 'introduced_on', 'search')
                 ->search('"health care" medicine')
                 ->filter('history.enacted', true)
                 ->order('introduced_on')
                 ->order('bill_id', 'asc')
                 ->highlight('<strong>', '</strong>', 300)
                 ->page(2, 25)
                 ->explain()
                 ->get()

Chainable interface methods

There are several methods provided for convenience which can be chained together:

  • fields($field1, [$field2, ..., $fieldN]) - Specifies the fields to return
  • search($query) - Sets up the search query
  • filter($field, $value, [$operator]) - Filter on fields with a key/value pair. If no operator specified, an equality operation will be used. If operator is specified, it should be one of the following values:
    • gte - the fiels is greater than or equal to this value
    • lt - the field is less than this value
    • lte - the field is less than or equal to this value
    • not - the field is not this value
    • all - the field is an array that contains all of these values (separated by "|")
    • in - the field is a string that is one of these values (separated by "|")
    • nin - the field is a string that is not one of these values (separated by "|")
    • exists - the field is both present and non-null (supply "true" or "false")
  • order($field, [$direction]) - Specifies the order of the result. The default direction is "desc".
  • highlight([$startTag, $endTag, $size]) - Turns on highlighted excerpts for search. The default tag is <em>, and the default size is 200.
  • page([$number, $size]) - Controls result pagination. The default page is 1, and the default results per page are 20.
  • explain() - Turns on how the API interpreted the query, and database-specific explain information.

Page Iteration

The library provides a convenient way to iterate over the result pages via a PageIterator. For more information and examples visit the Page Iteration page.

$params = array('query'     => 'committee of the whole',
                'chamber'   => 'house');

try {
    $fb->floor_updates->setParams($params);
    foreach ($fb->floor_updates as $page) {
        var_dump($page);
    }
} catch (\Exception $e) {
    echo $e->getMessage();
}

Bulk data

As of 0.3.0, there are a few convenience methods to retrieve the bulk data files via $fb->bulk_data.

  • downloadLegislatorSpreadsheet()
  • downloadZipToDistrict()
  • downloadLegislatorsPhotosSmall()
  • downloadLegislatorsPhotosMedium()
  • downloadLegislatorsPhotosLarge()

The use is simple. Specify the directory to download to and call the appropriate method:

$fb->bulk_data->setDirectory(__DIR__ . DIRECTORY_SEPARATOR . 'download')
              ->downloadLegislatorSpreadsheet();

Helpers

Some resources provide methods that ease development. Here are those helper methods by resource:

  1. legislators_locate
    • getByZip($zip) - Retrieve legislators based on a zip code.

      Example:

      $fb->legislators_locate->getByZip('94102');
    • getByAddress($address) - Retrieve legislators based on an address via a geocoding service.

      Example:

      $googleMaps = new FurryBear\Geocode\Provider\GoogleMaps();
      $fb->legislators_locate->via($googleMaps)->getByAddress($address);
Clone this wiki locally