campaign_cash 1.3 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2011 The New York Times Company
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this library except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.rdoc CHANGED
@@ -1,7 +1,6 @@
1
1
  = campaign_cash
2
2
 
3
- * Docs[http://dwillis.github.com/campaign_cash/]
4
- * Source[http://github.com/dwillis/campaign_cash]
3
+ * Source[http://github.com/nytimes/campaign_cash]
5
4
 
6
5
  == DESCRIPTION:
7
6
 
@@ -9,7 +8,7 @@ Simple ruby wrapper for The New York Times Campaign Finance API[http://developer
9
8
 
10
9
  == INSTALL:
11
10
 
12
- * <tt>sudo gem install campaign_cash</tt>
11
+ * <tt>gem install campaign_cash</tt>
13
12
 
14
13
  == USAGE:
15
14
 
@@ -20,12 +19,14 @@ You'll want to set your API key as an environment variable in order to run the t
20
19
 
21
20
  Base.api_key = YOUR_API_KEY
22
21
 
23
- Currently there are methods to support retrieving candidates and committees, and every method requires at least one parameter,
24
- the election cycle. Some examples (provided you've done include CampaignCash):
22
+ Currently there are methods to support retrieving candidates, committees, electronic filings, committee contributions and independent expenditures. Almost every method requires at least one parameter, the election cycle. Some examples (provided you've done include CampaignCash):
25
23
 
26
- Candidate.find("H4NY07011", 2010) # find Gary Ackerman's details for the 2010 cycle
27
- Committee.search("Growth", 2010) # find all committees in the 2010 cycle with the word 'Growth' in the name.
24
+ Candidate.find("H4NY07011", 2012) # find Gary Ackerman's details for the 2012 cycle
25
+ Committee.search("Growth", 2012) # find all committees in the 2012 cycle with the word 'Growth' in the name.
28
26
  Candidate.search("Udall", 2010) # find all candidates in the 2010 cycle with the name 'Udall'
27
+ Filing.today # find all the electronic filings made today.
28
+ Contribution.find("C00458588",2010,"H0NC02059") # find all contributions by the committee to the candidate in the 2010 cycle.
29
+ IndependentExpenditure.candidate("P60003654", 2012) # find independent expenditures about Newt Gingrich in the 2012 cycle.
29
30
 
30
31
  Check out the tests for further examples.
31
32
 
@@ -39,27 +40,10 @@ Check out the tests for further examples.
39
40
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
40
41
  * Send me a pull request. Bonus points for topic branches.
41
42
 
42
- == LICENSE:
43
+ == Authors
43
44
 
44
- (The MIT License)
45
+ Derek Willis, dwillis@nytimes.com
45
46
 
46
- Copyright (c) 2010 Derek Willis
47
+ == Copyright
47
48
 
48
- Permission is hereby granted, free of charge, to any person obtaining
49
- a copy of this software and associated documentation files (the
50
- 'Software'), to deal in the Software without restriction, including
51
- without limitation the rights to use, copy, modify, merge, publish,
52
- distribute, sublicense, and/or sell copies of the Software, and to
53
- permit persons to whom the Software is furnished to do so, subject to
54
- the following conditions:
55
-
56
- The above copyright notice and this permission notice shall be
57
- included in all copies or substantial portions of the Software.
58
-
59
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
60
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
61
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
62
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
63
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
64
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
65
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+ Copyright (c) 2011 The New York Times Company. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'bundler'
2
+ include Rake::DSL
2
3
  Bundler::GemHelper.install_tasks
3
4
 
4
5
  require 'rake/testtask'
@@ -9,13 +10,3 @@ Rake::TestTask.new(:test) do |test|
9
10
  end
10
11
 
11
12
  task :default => :test
12
-
13
- require 'rake/rdoctask'
14
- Rake::RDocTask.new do |rdoc|
15
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
16
-
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = "campaign_cash #{version}"
19
- rdoc.rdoc_files.include('README*')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
@@ -2,11 +2,11 @@ module CampaignCash
2
2
  class Committee < Base
3
3
 
4
4
  attr_reader :name, :id, :state, :district, :party, :fec_uri, :candidate,
5
- :city, :address, :state, :zip, :relative_uri,
5
+ :city, :address, :state, :zip, :relative_uri, :sponsor_name,
6
6
  :total_receipts, :total_contributions, :total_from_individuals,
7
7
  :total_from_pacs, :candidate_loans, :total_disbursements,
8
8
  :total_refunds, :debts_owed, :begin_cash, :end_cash,
9
- :date_coverage_to, :date_coverage_from, :other_cycles
9
+ :date_coverage_to, :date_coverage_from, :other_cycles, :super_pac
10
10
 
11
11
  def initialize(params={})
12
12
  params.each_pair do |k,v|
@@ -49,7 +49,10 @@ module CampaignCash
49
49
  :party => params['party'],
50
50
  :relative_uri => params['relative_uri'],
51
51
  :candidate => params['candidate'],
52
- :treasurer => params['treasurer']
52
+ :treasurer => params['treasurer'],
53
+ :fec_uri => params['fec_uri'],
54
+ :super_pac => params['super_pac'],
55
+ :sponsor_name => params['sponsor_name']
53
56
 
54
57
  end
55
58
 
@@ -71,9 +74,10 @@ module CampaignCash
71
74
  results.map{|c| create(c)}
72
75
  end
73
76
 
74
- def contributions
75
- reply = invoke("#{cycle}/committees/#{id}/contributions")
76
-
77
+ def self.superpacs(cycle=CURRENT_CYCLE)
78
+ reply = invoke("#{cycle}/committees/superpacs")
79
+ results = reply['results']
80
+ results.map{|c| create_from_search_results(c)}
77
81
  end
78
82
 
79
83
  end
@@ -0,0 +1,73 @@
1
+ module CampaignCash
2
+ class IndependentExpenditure < Base
3
+
4
+ attr_reader :fec_committee_id, :district, :state, :fec_committee_name, :purpose, :fec_candidate_id, :support_or_oppose, :date, :amount, :office, :amendment, :date_received, :payee, :fec_uri
5
+
6
+ def initialize(params={})
7
+ params.each_pair do |k,v|
8
+ instance_variable_set("@#{k}", v)
9
+ end
10
+ end
11
+
12
+ def self.create(params={})
13
+ self.new :fec_committee_id => params['fec_committee'].split('/').last.split('.').first,
14
+ :fec_committee_name => params['fec_committee_name'],
15
+ :fec_candidate_id => params['fec_candidate'].split('/').last.split('.').first,
16
+ :office => params['office'],
17
+ :state => params['state'].strip,
18
+ :district => params['district'],
19
+ :date => date_parser(params['date']),
20
+ :support_or_oppose => params['support_or_oppose'],
21
+ :payee => params['payee'],
22
+ :purpose => params['purpose'],
23
+ :amount => params['amount'],
24
+ :fec_uri => params['fec_uri'],
25
+ :date_received => date_parser(params['date_received'])
26
+ end
27
+
28
+ def self.latest
29
+ reply = Base.invoke("#{Base::CURRENT_CYCLE}/independent_expenditures")
30
+ results = reply['results']
31
+ @independent_expenditures = results.map{|c| IndependentExpenditure.create(c)}
32
+ end
33
+
34
+ def self.date(date)
35
+ d = Date.parse(date)
36
+ cycle = cycle_from_date(d)
37
+ reply = Base.invoke("#{cycle}/independent_expenditures/#{d.year}/#{d.month}/#{d.day}")
38
+ results = reply['results']
39
+ @independent_expenditures = results.map{|c| IndependentExpenditure.create(c)}
40
+ end
41
+
42
+ def self.committee(id, cycle)
43
+ @independent_expenditures = []
44
+ reply = Base.invoke("#{cycle}/committees/#{id}/independent_expenditures")
45
+ results = reply['results']
46
+ comm = reply['fec_committee']
47
+ results.each do |result|
48
+ result['fec_committee'] = comm
49
+ @independent_expenditures << IndependentExpenditure.create(result)
50
+ end
51
+ @independent_expenditures
52
+ end
53
+
54
+ def self.candidate(id, cycle)
55
+ @independent_expenditures = []
56
+ reply = Base.invoke("#{cycle}/candidates/#{id}/independent_expenditures")
57
+ results = reply['results']
58
+ cand = reply['fec_candidate']
59
+ results.each do |result|
60
+ result['fec_candidate'] = cand
61
+ @independent_expenditures << IndependentExpenditure.create(result)
62
+ end
63
+ @independent_expenditures
64
+ end
65
+
66
+ def self.president(cycle=Base::CURRENT_CYCLE)
67
+ reply = Base.invoke("#{cycle}/president/independent_expenditures")
68
+ results = reply['results']
69
+ @independent_expenditures = results.map{|c| IndependentExpenditure.create(c)}
70
+ end
71
+
72
+ end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module CampaignCash
2
- VERSION = "1.3"
2
+ VERSION = "1.5"
3
3
  end
data/lib/campaign_cash.rb CHANGED
@@ -1,3 +1,3 @@
1
- %w(base candidate committee contribution filing form).each do |f|
1
+ %w(base candidate committee contribution filing form independent_expenditure).each do |f|
2
2
  require File.join(File.dirname(__FILE__), '../lib/campaign_cash', f)
3
3
  end
@@ -97,4 +97,17 @@ class TestCampaignCash::TestCommittee < Test::Unit::TestCase
97
97
  assert_equal @contribution.total_amount, 10000
98
98
  end
99
99
  end
100
+
101
+ context "superpacs" do
102
+ setup do
103
+ reply = Base.invoke('2012/committees/superpacs')
104
+ @committees = reply['results'].map{|c| Committee.create_from_search_results(c) }
105
+ end
106
+
107
+ should "return an array of super pacs" do
108
+ assert_equal([true], @committees.map{|c| c.super_pac }.uniq)
109
+ end
110
+
111
+ end
112
+
100
113
  end
@@ -19,8 +19,12 @@ class TestCampaignCash::TestFiling < Test::Unit::TestCase
19
19
  @filings = Filing.today
20
20
  end
21
21
 
22
- should "return a list of objects of the Filing type" do
23
- assert_kind_of(Filing, @filings.first)
22
+ should "return a list of objects of the Filing type or an empty list" do
23
+ if @filings.size > 0
24
+ assert_kind_of(Filing, @filings.first)
25
+ else
26
+ assert_equal([], @filings)
27
+ end
24
28
  end
25
29
  end
26
30
 
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class TestCampaignCash::TestIndependentExpenditure < Test::Unit::TestCase
4
+ include CampaignCash
5
+
6
+ context "latest independent expenditures" do
7
+ setup do
8
+ @independent_expenditures = IndependentExpenditure.latest
9
+ end
10
+
11
+ should "return a list of objects of the IndependentExpenditure type" do
12
+ assert_kind_of(IndependentExpenditure, @independent_expenditures.first)
13
+ end
14
+ end
15
+
16
+ context "independent expenditures by date" do
17
+ setup do
18
+ @independent_expenditures = IndependentExpenditure.date("12/13/2011")
19
+ end
20
+
21
+ should "return at least one independent expenditure against Barack Obama" do
22
+ assert_equal("P80003338", @independent_expenditures.first.fec_candidate_id)
23
+ end
24
+ end
25
+
26
+ context "a committee's independent expenditures in a cycle" do
27
+ setup do
28
+ @independent_expenditures = IndependentExpenditure.committee("C00490045", 2012)
29
+ end
30
+
31
+ should "return an array of IEs in the presidential race" do
32
+ assert_equal("President", @independent_expenditures.first.office)
33
+ end
34
+ end
35
+
36
+ context "independent expenditures about a given candidate" do
37
+ setup do
38
+ @independent_expenditures = IndependentExpenditure.candidate("P60003654", 2012)
39
+ @candidate = Candidate.find('P60003654')
40
+ end
41
+
42
+ should "return an array of IEs about presidential candidate Newt Gingrich" do
43
+ assert_equal("President", @independent_expenditures.first.office)
44
+ assert_equal(@candidate.name, "GINGRICH, NEWT")
45
+ end
46
+ end
47
+
48
+ context "independent expenditures in the presidential campaign" do
49
+ setup do
50
+ @independent_expenditures = IndependentExpenditure.president
51
+ end
52
+
53
+ should "return an array of IEs about the presidential campaign" do
54
+ assert_equal(['President'], @independent_expenditures.map{|i| i.office }.uniq)
55
+ end
56
+ end
57
+
58
+ end
data/test/test_helper.rb CHANGED
@@ -4,12 +4,10 @@ require 'shoulda'
4
4
  require 'json'
5
5
  require 'ostruct'
6
6
 
7
- %w(base candidate committee contribution filing form).each do |f|
7
+ %w(base candidate committee contribution filing form independent_expenditure).each do |f|
8
8
  require File.join(File.dirname(__FILE__), '../lib/campaign_cash', f)
9
9
  end
10
10
 
11
- include CampaignCash
12
-
13
11
  # set your NYT Campaign Finance API key as an environment variable to run the tests
14
12
  API_KEY = ENV['NYT_CAMPFIN_API_KEY']
15
13
  CampaignCash::Base.api_key = API_KEY
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: campaign_cash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 3
9
- version: "1.3"
8
+ - 5
9
+ version: "1.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Derek Willis
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-03 00:00:00 -04:00
17
+ date: 2011-12-17 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,7 @@ extra_rdoc_files: []
59
59
  files:
60
60
  - .gitignore
61
61
  - Gemfile
62
+ - LICENSE
62
63
  - README.rdoc
63
64
  - Rakefile
64
65
  - campaign_cash.gemspec
@@ -69,11 +70,13 @@ files:
69
70
  - lib/campaign_cash/contribution.rb
70
71
  - lib/campaign_cash/filing.rb
71
72
  - lib/campaign_cash/form.rb
73
+ - lib/campaign_cash/independent_expenditure.rb
72
74
  - lib/campaign_cash/version.rb
73
75
  - test/campaign_cash/test_candidate.rb
74
76
  - test/campaign_cash/test_committee.rb
75
77
  - test/campaign_cash/test_filing.rb
76
78
  - test/campaign_cash/test_form.rb
79
+ - test/campaign_cash/test_independent_expenditure.rb
77
80
  - test/test_helper.rb
78
81
  has_rdoc: true
79
82
  homepage: http://rubygems.org/gems/campaign_cash
@@ -107,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
110
  requirements: []
108
111
 
109
112
  rubyforge_project: campaign_cash
110
- rubygems_version: 1.4.2
113
+ rubygems_version: 1.6.2
111
114
  signing_key:
112
115
  specification_version: 3
113
116
  summary: Following the money.
@@ -116,4 +119,5 @@ test_files:
116
119
  - test/campaign_cash/test_committee.rb
117
120
  - test/campaign_cash/test_filing.rb
118
121
  - test/campaign_cash/test_form.rb
122
+ - test/campaign_cash/test_independent_expenditure.rb
119
123
  - test/test_helper.rb