Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (48 sloc) 2.55 KB Ruby Wrapper

By Wynn Netherland, Jeremy Hinegardner, and Luigi Montanez

Before using this library, please read the official API documentation. Query parameters and return formats are described there.


Get an API key from Sunlight Labs.

Required gems:

  • monster_mash
  • hashie

After a gem install transparency_data, you can do:

require 'transparency_data'
TransparencyData.api_key = 'YOUR_KEY_HERE'

Within a Rails app, create a config/initializers/transparency_data.rb and stick this in:

TransparencyData.configure do |config|
 config.api_key = 'YOUR_KEY_HERE'

Optionally, you can set TransparencyData.api_domain if you don't want to hit the production API at


See the official API docs for all parameters you can send in, and the schema docs for what you get back:

contributions = TransparencyData::Client.contributions(:contributor_ft => 'steve jobs')
contributions.each do |contribution|
  puts "Amount: #{contribution.amount}"
  puts "Date: #{}"

lobbyings = TransparencyData::Client.lobbying(:client_ft => "apple inc")
lobbyings.each do |lobbying|
  puts "Amount: #{lobbying.amount}"
  puts "Year: #{lobbying.year}"

As described in the API docs, the API supports a special syntax as the parameter value for specifying ranges and sets on amount, cycle, year, and date. You can either pass in strings, or use a more Rubyish approach:

# contributions with an amount greater than or equal to $1000
TransparencyData::Client.contributions(:contributor_ft => 'steve jobs', :amount => {:gte => 1000})

# contributions with an amount less than or equal to $500
TransparencyData::Client.contributions(:contributor_ft => 'bill gates', :amount => {:lte => 500})

# contributions in the 2006 or 2008 cycle
TransparencyData::Client.contributions(:contributor_ft => 'eric schmidt', :cycle => [2006,2008]})

# contributions to Obama made between in Q1 2008
TransparencyData::Client.contributions(:recipient_ft => 'barack obama',
                                       :date => {:between => ['2008-01-01','2008-03-31']})


Required gems for running tests:

  • mg
  • shoulda
  • jnunemaker-matchy
  • mocha
  • fakeweb
  • vcr

Run the test suite:

rake test