steveklabnik/sunlight-congress — pull request #27 by seanknox (2013-05-02 01:46:51+00:00)
Title: Create Base class for commonly used methods/config

Take 2!

Base class to handle methods and configuration used throughout the code_base,
like parsing responses from the Sunlight::Congress API.

- Used ```activesupport/configurable``` to store configuration options such as api_key and base_uri.
- Doesn't affect gem public API
- All tests pass
- All classes parse the Sunlight API response in the same way, so I added ```Sunlight::Congress::Base.parse_response``` to handle this. To use it, you pass in the API results to a new instance of ::Base. I added this helper method in most classes:

```ruby
class Sunlight::Congress::Legislator
def self.get_resource(uri)
response = JSON.load(Net::HTTP.get(uri))["results"]
Sunlight::Congress::Base.new(self).parse_response(response)
end
end
```

I don't love creating an instance of Base just to parse the result, but I need to get the calling class type in order to return objects of that type (Legislator, Bill, etc.). If you have a better way to go about this let me know.

BillQuery handles results a bit differently, so I didn't change it (aside from config options). I left FloorUpdates alone too, since it's code is already pretty concise, and I wasn't sure if switching to my code there was an improvement.

Let me know what you think!