Skip to content

Sunlight Open States

lobostome edited this page Aug 21, 2013 · 7 revisions

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

API key

The Sunlight Open States 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 Open States API endpoints can be accessed via properties of the FurryBear\FurryBear object.

All resources have the following method:

  • fields([$field[, $field, [$...]]]) - On essentially every method in the API it is possible to specify a custom subset of fields.

Metadata Overview

Get a list of all states with data available and basic metadata about their status with the metadata property.

Example:

$fb->metadata->get();

State Metadata

Get detailed metadata for a particular state with the metadata_state property.

Example:

$fb->metadata_state->tx->get();

Bill Search

Search bills by (almost) any of their attributes, or full text with the bills property.

Chainable interface methods

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

  • filter($field, $value) - Filter on fields with a field/value pair.
  • filter(array $filters) - This method overrides the previous one by allowing to pass all filters at once as an array, rather than individually with multiple filter calls.
  • sort($by) - Sort-order of results, defaults to 'last'.
  • page([$page [, $perPage]]) - Control result pagination. $page defaults to 1, and $perPage defaults to 50.

Example:

$fb->bills->filter('state', 'dc')
          ->filter('q', 'taxi')
          ->sort('created_at')
          ->page(1, 5)
          ->get();

Alternatively,

$fb->bills->filter(array('state' => 'dc', 'q' => 'taxi'))
          ->sort('created_at')
          ->page(1, 5)
          ->get();

Result Iteration

The library provides a convenient way to iterate over the result pages:

$fb->bills->filter(array('state' => 'dc', 'q' => 'taxi'))
foreach ($fb->bills as $page) {
    if (!is_null($page))
        var_dump($page);
}

Bill Detail

Get full detail for bill, including any actions, votes, etc. with the bill_detail property (alias bills_detail). The following methods are used to specify lookup criteria:

  • criteria($state, $session, $billId) - Specify the state, session, and bill id.
  • criteria($billId) - Alternatively, specify the open states bill id.

Example:

$fb->bill_detail->criteria('CAB00004148')->get();

Legislator Search

Search legislators by their attributes with the legislators property.

Example:

$params = array('state' => 'dc', 'chamber' => 'upper');
$fb->legislators->get($params);

Alternatively,

$params = array('state' => 'dc', 'chamber' => 'upper');
$fb->legislators->setParams($params)->get();

Legislator Detail

Get full detail for a legislator, including all roles with the legislator_detail property (alias legislators_detail). The method id($legislatorId) specifies which legislator to return.

Example:

$fb->legislator_detail->id('DCL000012')->get();

Geo Lookup

Lookup all legislators that serve districts containing a given point with the geo_lookup property. The method coords($latitude, $longitude) specifies the geo coordinates to query.

Example:

$fb->geo_lookup->coords(35.79, -78.78)->get();

Committee Search

Search committees by any of their attributes with the committees property.

Example:

$params = array('state' => 'dc');
$fb->committees->get($params);

Committee Detail

Get full detail for committee, including all members with the committee_detail property (alias committees_detail). The method id($committeeId) specifies which committee to query.

Example:

$fb->committee_detail->id('DCC000029')->get();

Event Search

Search events by state and type with the events property.

Example:

$params = array('state' => 'dc');
$fb->events->get($params);

Event Detail

Get full detail for event with the event_detail property (alias events_detail). The method id($eventId) specifies the event id to return.

Example:

$fb->event_detail->id('TXE00026474')->get();

District Search

List districts for state (and optionally filtered by chamber) with the districts property. The query parameters are specified with the following method:

  • criteria($state [, $chamber]) - Specify a state and optionally also a chamber.

Example:

$fb->districts->criteria('nc', 'lower')->get();

District Boundary Lookup

Get geographic boundary for a district with the district_boundary property. The method id($boundaryId) specifies the boundary.

Example:

$fb->district_boundary->id('sldl/nc-120')->get();