Skip to content

Sunlight Capitol Words

lobostome edited this page Jul 7, 2013 · 2 revisions

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

API key

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

  • dates: Find the popularity of a phrase over a period of time.
  • phrases: List the top phrases for a facet.
  • text: Full-text search.

Example:

$fb->dates;

Phrases Entities

Get the top (legislator|state|party|bioguide_id|volume|chamber)s for a phrase.

Example:

$fb->phrases->entity('legislator');

To clear the entity and use only the phrases resource, just call the entity() method with no arguments.

$fb->phrases->entity();

Setting parameters

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

  • Using setParams() method
$params = array('phrase' => 'free market');
$fb->phrases->entity('legislator')->setParams($params);
$fb->phrases->get();
  • Passing them directly to the get() method
$params = array('entity_type' => 'legislator',
                'entity_value' => 'L000551');
$fb->phrases->get($params);

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('phrase' => 'free market');

try {
    $fb->phrases->entity('legislator')->setParams($params);
    foreach ($fb->phrases as $page) {
        if (!is_null($page))
            var_dump($page);
    }
} catch (\Exception $e) {
    echo $e->getMessage();
}

The check if the page is not null is necessary for the phrases resource, but is not necessary for the text resource. This is due to the lack of pagination meta data for the phrases resource and its entities.

Clone this wiki locally