Skip to content

andybrucenet/Abr.CodeLibrary.SunlightLabs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

README - Abr.CodeLibrary.SunlightLabs
-------------------------------------
Last Modified: 26 AUG 2010, ABr

This project allows you to integrate with the Sunlight Labs Congress API
(see http://services.sunlightlabs.com/docs/Sunlight_Congress_API/).

To use the project:

1. Download the code from GitHub

2. Precompiled DotNet 35 binaries are under the bin folder. All you
   need is the Abr.CodeLibrary.SunlightLabs.dll assembly. Just put a
   reference to it in your own project. For Silverlight, use the
   Abr.CodeLibrary.SunlightLabs.Sl.dll assembly (it works just the
   same as DotNet 35 version).

3. You can open the source code and rebuild the project if you want.
   The DotNet 35 solution is under the src\Deployment\Abr.CodeLibrary.SunlightLabs
   folder. It's called Abr.CodeLibrary.SunlightLabs.sln.

4. I built NUnit tests, you'll need to download the NUnit package if
   you want to run the tests (the test assembly is in the bin folder). Also, 
   Abr.CodeLibrary.SunlightLabs.Test.dll.config will need to be updated with
   *your* Sunlight Labs API key. Just open the file and you'll see where to
   put the key. I do not have tests for the Silverlight version (but I'm
   using it in production code anyway).

Usage of the API is really simple. To read legislative data (for example,
to look for Barack Obama):

using Abr.CodeLibrary.SunlightLabs;
using Abr.CodeLibrary.SunlightLabs.DataStructures;

public class ReadBaracksData {
  public static void Main(string[] args) {
    // create the request object
    var req = new Legislators("your API key here");

    // call the Get function for all legislators (not just current ones)
    var rsp = req.Get(true, Legislator.Props.lastname, "obama");
    System.Console.WriteLine("We found: {0} {1}", rsp.firstname, rsp.lastname);
  }
}

Please note for Silverlight that you must call this from a *separate
thread* than the UI thread. The call to req.Get above blocks until the
Web service returns.

That's it--if you go to the Sunlight Labs Web site and look at the API
documentation they use, you'll find that I tried to keep the C# code as close
to their examples as possible. The JSON data returned from the API calls is
translated to C# objects using JSON.Net (http://json.codeplex.com/).

I have C# support for all the APIs (Legislators, Districts, and Committees)
from the Sunlight Labs site. The only problem I've seen is that the district
lookup by state and district number only seems to work for the Sunlight example
of NY-29 (I couldn't get any other states or congressional district numbers to
return data). Perhaps you can have better luck.

Enjoy!

Andy

Releases

No releases published

Packages

No packages published

Languages