Ruby gem to interact with the Sunlight Labs OpenStates API.
Add this line to your application's Gemfile:
gem 'openstates'
And then execute:
$ bundle
Or install it yourself as:
$ gem install openstates
You will need to register for an API key with Sunlight Labs.
If you intend to use this gem in a rails project, you should add the
following in config/initializers/openstates.rb
OpenStates.configure do |config|
config.api_key ='yourkeyhere'
config.logger = Rails.logger
endIf your project is not rails based, you just need to include the above configuration somewhere in your ruby environment with single change.
OpenStates.configure do |config|
config.api_key ='yourkeyhere'
config.logger = ::Logger.new(STDOUT)
config.logger.level = ::Logger::DEBUG
endYou can search for bills using the where class method on
OpenStates::Bill.
bills = OpenStates::Bill.where(state: 'tx', q: 'taxi')You can also search for a specific bill by it's bill_id.
bill = OpenStates::Bill.find("12345")Or by its OpenStates id.
bill = OpenStates::Bill.find_by_openstates_id("KS00012345")And lastly, you can get bill details by using the bill_details class
method on OpenStates::Bill.
bill = OpenStates::Bill.bill_details('fl', '2013', '12345')You can find a list of all query parameters for Bills here.
You can search for committees using the where class method on
OpenStates::Committee.
committees = OpenStates::Committee.where(state: 'ny')You can also search for a specific committee by it's id.
committee = OpenStates::Committee.find("NYC000099")You can find a list of all query parameters for Committees here
You can search for districts using the where class method on
OpenStates::District.
districts = OpenStates::District.where(state: 'nj')You can also search for a specific district by it's boundary_id.
district = OpenStates::District.find('12345')You can find a list of all query parameters for Districts here
You can search for events using the where class method on
OpenStates::Event.
events = OpenStates::Event.where(state: 'ok')You can also search for a specific event by it's event_id.
event = OpenStates::Event.find('1234567')You can find a list of all query parameters for Events here
You can search for legislators using the where class method on
OpenStates::Legislator.
legislators = OpenStates::Legislator.where(state: 'ga')You can also search for a specific legislator by their leg_id.
legislator = OpenStates::Legislator.find('12345')And lastly, you can search for legislators by geolocation details.
legislators = OpenStates::Legislator.by_location(45.13, -85.10)You can find a list of all query parameters for Legislators here
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request