Giter Site home page Giter Site logo

ruby-openstates's Introduction

Openstates

Ruby gem to interact with the Sunlight Labs OpenStates API.

Installation

Add this line to your application's Gemfile:

gem 'openstates'

And then execute:

$ bundle

Or install it yourself as:

$ gem install openstates

Configuration

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
end

If 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
end

Usage

OpenStates::Bill

You 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")

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.

OpenStates::Committee

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

OpenStates::District

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

OpenStates::Event

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

OpenStates::Legislator

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

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.