Sunlight Labs Extension

    Table of contents
    1. 1. Examples

    The following illustrates how to use the functionality available via the Sunlight Labs extension, now available in the Extensions menu.

     

    Sunlight Labs has developed an API that allows users to retrieve data regarding legislators in Washington. In order to use this extension, an API key must be obtained from Sunlight Labs at http://services.sunlightlabs.com/api/. Next, install the Sunlight Labs script (attached at the bottom of the page) as a script in the control panel, and create a key entitled api-key, with the API key retrieved from Sunlight Labs as the key value.

     

    Examples

    The following Dekiscript:

    {{ sunlight.legislator{lastname: "boxer"} }}

    returns a map, consisting of data regarding the legislator (such as phone number, address, party, etc.):

    { result : "Profile does not exist" }

     

    Since that data set isn't particularly readable to the average end user, there is an extension that formats that data into a table. For example,

    {{ sunlight.legislatorTable{lastname: "boxer"} }}

    returns

    Profile for "boxer" does not exist. Please check the spelling of the politician entered.

     

    That's certainly more readable!

    Let's say, for example, I wanted more information about legislators that are relevant to me and my neighbors. Using the following Dekiscript, I can get the data for legislators that are responsible for representing my zip code (formatted as a table):

    {{ sunlight.zipTable{zip: "92101"} }}

    That returns:

     

    The following legislators are representatives for the zip code 92101:

     

    That information is good to know!

    The real power, however, comes from the extensibility of MindTouch Deki and Dekiscript. The data retrieved from the extension, while informative on its own, can be mashed up with other extensions and APIs!

    For example, we can extract the Twitter ID obtained in the first dataset using:

    {{ 
        var twitterID = (sunlight.legislator{lastname: "boxer"}.twitter_id) 
    }}

    This returns:

     

    We can then take that twitter ID (shown again in the top line), and get the last 5 tweets via the Twitter API. Note that I'm also formatting the tweets in an unordered list, using the foreach statement:

    {{
        var twitterID = (sunlight.legislator{lastname: "boxer"}.twitter_id); 
        var tweets = web.json('http://search.twitter.com/search.json?q=from:'..twitterID..'&rpp=5').results; 
        foreach (var tweet in tweets)
            {
                web.html('<ul><p>'..tweet.text..'</p></ul>')
            }
    }}

    The end result is:

    Tag page

    Files 1

    FileVersionSizeModified 
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by