campaign_cash 0.0.5 → 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +3 -3
- data/lib/campaign_cash/base.rb +1 -1
- data/lib/campaign_cash/candidate.rb +7 -7
- data/lib/campaign_cash/committee.rb +2 -2
- data/lib/campaign_cash/contribution.rb +26 -0
- data/lib/campaign_cash/filing.rb +27 -7
- data/lib/campaign_cash/form.rb +24 -0
- data/lib/campaign_cash/version.rb +1 -1
- data/lib/campaign_cash.rb +2 -0
- data/test/campaign_cash/test_candidate.rb +5 -5
- data/test/campaign_cash/test_committee.rb +47 -3
- data/test/campaign_cash/test_filing.rb +10 -0
- data/test/campaign_cash/test_form.rb +15 -0
- data/test/test_helper.rb +2 -0
- metadata +9 -7
data/README.rdoc
CHANGED
@@ -23,9 +23,9 @@ You'll want to set your API key as an environment variable in order to run the t
|
|
23
23
|
Currently there are methods to support retrieving candidates and committees, and every method requires at least one parameter,
|
24
24
|
the election cycle. Some examples (provided you've done include CampaignCash):
|
25
25
|
|
26
|
-
Candidate.
|
27
|
-
Committee.search(
|
28
|
-
Candidate.search(
|
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.
|
28
|
+
Candidate.search("Udall", 2010) # find all candidates in the 2010 cycle with the name 'Udall'
|
29
29
|
|
30
30
|
Check out the tests for further examples.
|
31
31
|
|
data/lib/campaign_cash/base.rb
CHANGED
@@ -14,7 +14,7 @@ module CampaignCash
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.
|
17
|
+
def self.create(params={})
|
18
18
|
self.new :name => params['name'],
|
19
19
|
:id => params['id'],
|
20
20
|
:state => params['state'],
|
@@ -41,7 +41,7 @@ module CampaignCash
|
|
41
41
|
:date_coverage_to => params['date_coverage_to']
|
42
42
|
end
|
43
43
|
|
44
|
-
def self.
|
44
|
+
def self.create_from_search_results(params={})
|
45
45
|
self.new :name => params['candidate']['name'],
|
46
46
|
:id => params['candidate']['id'],
|
47
47
|
:state => params['state'],
|
@@ -55,32 +55,32 @@ module CampaignCash
|
|
55
55
|
def self.find(fecid, cycle=CURRENT_CYCLE)
|
56
56
|
reply = invoke("#{cycle}/candidates/#{fecid}")
|
57
57
|
result = reply['results']
|
58
|
-
self.
|
58
|
+
self.create(result.first) if result.first
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.leaders(category, cycle=CURRENT_CYCLE)
|
62
62
|
reply = invoke("#{cycle}/candidates/leaders/#{category}",{})
|
63
63
|
results = reply['results']
|
64
|
-
results.map{|c| self.
|
64
|
+
results.map{|c| self.create(c)}
|
65
65
|
end
|
66
66
|
|
67
67
|
def self.search(name, cycle=CURRENT_CYCLE)
|
68
68
|
reply = invoke("#{cycle}/candidates/search", {:query => name})
|
69
69
|
results = reply['results']
|
70
|
-
results.map{|c| self.
|
70
|
+
results.map{|c| self.create_from_search_results(c)}
|
71
71
|
end
|
72
72
|
|
73
73
|
def self.new_candidates(cycle=CURRENT_CYCLE)
|
74
74
|
reply = invoke("#{cycle}/candidates/new",{})
|
75
75
|
results = reply['results']
|
76
|
-
results.map{|c| self.
|
76
|
+
results.map{|c| self.create(c)}
|
77
77
|
end
|
78
78
|
|
79
79
|
def self.state_chamber(state, chamber, district=nil, cycle=CURRENT_CYCLE)
|
80
80
|
district ? path = "#{cycle}/seats/#{state}/#{chamber}/#{district}" : path = "#{cycle}/seats/#{state}/#{chamber}"
|
81
81
|
reply = invoke(path,{})
|
82
82
|
results = reply['results']
|
83
|
-
results.map{|c| self.
|
83
|
+
results.map{|c| self.create_from_search_results(c)}
|
84
84
|
end
|
85
85
|
|
86
86
|
end
|
@@ -14,7 +14,7 @@ module CampaignCash
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.
|
17
|
+
def self.create(params={})
|
18
18
|
self.new :name => params['name'],
|
19
19
|
:id => params['id'],
|
20
20
|
:state => params['state'],
|
@@ -38,7 +38,7 @@ module CampaignCash
|
|
38
38
|
:candidate => params['candidate']
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.
|
41
|
+
def self.create_from_search_results(params={})
|
42
42
|
self.new :name => params['name'],
|
43
43
|
:id => params['id'],
|
44
44
|
:city => params['city'],
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CampaignCash
|
2
|
+
class Contribution < Base
|
3
|
+
|
4
|
+
attr_reader :date, :candidate_uri, :primary_general, :amount, :state, :name, :image_uri, :party, :district
|
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(cycle, committee, params={}, candidate = params['candidate'])
|
13
|
+
self.new :date => date_parser(params[:date]),
|
14
|
+
:candidate_uri => candidate,
|
15
|
+
:committee_uri => committee,
|
16
|
+
:primary_general => params[:primary_general],
|
17
|
+
:amount => params[:amount],
|
18
|
+
:state => params[:state],
|
19
|
+
:name => params[:name],
|
20
|
+
:image_uri => params[:image_uri],
|
21
|
+
:party => params[:party],
|
22
|
+
:district => params[:district],
|
23
|
+
:cycle => cycle
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/campaign_cash/filing.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module CampaignCash
|
2
2
|
class Filing < Base
|
3
3
|
|
4
|
-
attr_reader :committee_name, :date_coverage_from, :amended_uri, :fec_uri, :date_coverage_to, :committee, :report_title, :amended
|
4
|
+
attr_reader :committee_name, :date_coverage_from, :amended_uri, :fec_uri, :date_coverage_to, :committee, :report_title, :amended, :date_filed, :cycle, :form_type
|
5
5
|
|
6
6
|
def initialize(params={})
|
7
7
|
params.each_pair do |k,v|
|
@@ -9,30 +9,50 @@ module CampaignCash
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.
|
12
|
+
def self.create(params={})
|
13
13
|
self.new :committee_name => params['committee_name'],
|
14
14
|
:date_coverage_from => date_parser(params['date_coverage_from']),
|
15
15
|
:date_coverage_to => date_parser(params['date_coverage_to']),
|
16
16
|
:committee => params['committee'],
|
17
|
-
:report_title => params['report_title'],
|
17
|
+
:report_title => params['report_title'].strip,
|
18
18
|
:fec_uri => params['fec_uri'],
|
19
19
|
:amended => params['amended'],
|
20
|
-
:amended_uri => params['amended_uri']
|
20
|
+
:amended_uri => params['amended_uri'],
|
21
|
+
:form_type => params['form_type']
|
21
22
|
end
|
22
23
|
|
24
|
+
def self.create_from_filings(params={})
|
25
|
+
self.new :date_coverage_from => date_parser(params['date_coverage_from']),
|
26
|
+
:date_coverage_to => date_parser(params['date_coverage_to']),
|
27
|
+
:report_title => params['report_title'].strip,
|
28
|
+
:fec_uri => params['fec_uri'],
|
29
|
+
:amended => params['amended'],
|
30
|
+
:amended_uri => params['amended_uri'],
|
31
|
+
:cycle => params['cycle'],
|
32
|
+
:form_type => params['form_type'],
|
33
|
+
:date_filed => date_parser(params['date_filed'])
|
34
|
+
end
|
35
|
+
|
36
|
+
|
23
37
|
def self.today
|
24
38
|
cycle=CURRENT_CYCLE
|
25
39
|
reply = Base.invoke("#{cycle}/filings", {})
|
26
40
|
results = reply['results']
|
27
|
-
@filings = results.map{|c| Filing.
|
41
|
+
@filings = results.map{|c| Filing.create(c)}
|
28
42
|
end
|
29
43
|
|
30
44
|
def self.date(year, month, day)
|
31
45
|
cycle = cycle_from_date(Date.parse("#{month}/#{day}/#{year}"))
|
32
46
|
reply = Base.invoke("#{cycle}/filings/#{year}/#{month}/#{day}", {})
|
33
47
|
results = reply['results']
|
34
|
-
@filings = results.map{|c| Filing.
|
48
|
+
@filings = results.map{|c| Filing.create(c)}
|
35
49
|
end
|
36
50
|
|
37
|
-
|
51
|
+
def self.by_type(cycle, form_type)
|
52
|
+
cycle = cycle
|
53
|
+
reply = Base.invoke("#{cycle}/filings/types/#{form_type}")
|
54
|
+
results = reply['results']
|
55
|
+
@filings = results.map{|c| Filing.create(c)}
|
56
|
+
end
|
57
|
+
end
|
38
58
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CampaignCash
|
2
|
+
class Form < Base
|
3
|
+
|
4
|
+
attr_reader :id, :name
|
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 :id => params['id'],
|
14
|
+
:name => params['name']
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.form_types
|
18
|
+
reply = Base.invoke("#{Base::CURRENT_CYCLE}/filings/types")
|
19
|
+
results = reply['results']
|
20
|
+
@forms = results.map{|c| Form.create(c)}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/campaign_cash.rb
CHANGED
@@ -4,5 +4,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
4
4
|
require "campaign_cash/base"
|
5
5
|
require "campaign_cash/candidate"
|
6
6
|
require "campaign_cash/committee"
|
7
|
+
require "campaign_cash/contribution"
|
7
8
|
require "campaign_cash/filing"
|
9
|
+
require "campaign_cash/form"
|
8
10
|
require "campaign_cash/version"
|
@@ -3,11 +3,11 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
|
|
3
3
|
class TestCampaignCash::TestCandidate < Test::Unit::TestCase
|
4
4
|
include CampaignCash
|
5
5
|
|
6
|
-
context "Candidate.
|
6
|
+
context "Candidate.create" do
|
7
7
|
setup do
|
8
8
|
reply = Base.invoke('2010/candidates/H4NY07011', {})
|
9
9
|
@result = reply['results'].first
|
10
|
-
@candidate = Candidate.
|
10
|
+
@candidate = Candidate.create(@result)
|
11
11
|
end
|
12
12
|
|
13
13
|
should "return an object of the Candidate type" do
|
@@ -25,7 +25,7 @@ class TestCampaignCash::TestCandidate < Test::Unit::TestCase
|
|
25
25
|
setup do
|
26
26
|
reply = Base.invoke('2010/candidates/search', {:query => "Udall"})
|
27
27
|
results = reply['results']
|
28
|
-
@candidates = results.map{|c| Candidate.
|
28
|
+
@candidates = results.map{|c| Candidate.create_from_search_results(c)}
|
29
29
|
end
|
30
30
|
|
31
31
|
should "return two candidate objects" do
|
@@ -39,7 +39,7 @@ class TestCampaignCash::TestCandidate < Test::Unit::TestCase
|
|
39
39
|
setup do
|
40
40
|
reply = Base.invoke('2010/candidates/new', {})
|
41
41
|
results = reply['results']
|
42
|
-
@candidates = results.map{|c| Candidate.
|
42
|
+
@candidates = results.map{|c| Candidate.create(c)}
|
43
43
|
end
|
44
44
|
|
45
45
|
should "return 20 new candidates" do
|
@@ -53,7 +53,7 @@ class TestCampaignCash::TestCandidate < Test::Unit::TestCase
|
|
53
53
|
setup do
|
54
54
|
reply = Base.invoke('2010/candidates/leaders/end_cash', {})
|
55
55
|
results = reply['results']
|
56
|
-
@candidates = results.map{|c| Candidate.
|
56
|
+
@candidates = results.map{|c| Candidate.create(c)}
|
57
57
|
end
|
58
58
|
|
59
59
|
should "return 20 candidates each with a greater end_cash value than the next" do
|
@@ -7,7 +7,7 @@ class TestCampaignCash::TestCommittee < Test::Unit::TestCase
|
|
7
7
|
setup do
|
8
8
|
reply = Base.invoke('2010/committees/C00312223', {})
|
9
9
|
@result = reply['results'].first
|
10
|
-
@committee = Committee.
|
10
|
+
@committee = Committee.create(@result)
|
11
11
|
end
|
12
12
|
|
13
13
|
should "return an object of the Committee type" do
|
@@ -25,7 +25,7 @@ class TestCampaignCash::TestCommittee < Test::Unit::TestCase
|
|
25
25
|
setup do
|
26
26
|
reply = Base.invoke('2010/committees/search', {:query => "Boeing"})
|
27
27
|
results = reply['results']
|
28
|
-
@committees = results.map{|c| Committee.
|
28
|
+
@committees = results.map{|c| Committee.create_from_search_results(c)}
|
29
29
|
end
|
30
30
|
|
31
31
|
should "return two committee objects" do
|
@@ -39,7 +39,7 @@ class TestCampaignCash::TestCommittee < Test::Unit::TestCase
|
|
39
39
|
setup do
|
40
40
|
reply = Base.invoke('2010/committees/new', {})
|
41
41
|
results = reply['results']
|
42
|
-
@committees = results.map{|c| Committee.
|
42
|
+
@committees = results.map{|c| Committee.create_from_search_results(c)}
|
43
43
|
end
|
44
44
|
|
45
45
|
should "return 20 new committees" do
|
@@ -56,4 +56,48 @@ class TestCampaignCash::TestCommittee < Test::Unit::TestCase
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
context "committee filings" do
|
61
|
+
setup do
|
62
|
+
reply = Base.invoke('2010/committees/C00312223/filings', {})
|
63
|
+
results = reply['results']
|
64
|
+
@filings = results.map{|f| Filing.create_from_filings(f)}
|
65
|
+
end
|
66
|
+
|
67
|
+
should "return 10 filings" do
|
68
|
+
assert_equal @filings.size, 10
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "committee contributions" do
|
73
|
+
setup do
|
74
|
+
reply = Base.invoke('2010/committees/C00458588/contributions', {})
|
75
|
+
results = reply['results']
|
76
|
+
@committee = reply['committee']
|
77
|
+
@num_records = reply['total_results']
|
78
|
+
@total_amount = reply['total_amount']
|
79
|
+
@contributions = results.map{|c| Contribution.create(@committee, c)}
|
80
|
+
end
|
81
|
+
|
82
|
+
should "return 125 total results" do
|
83
|
+
assert_equal @num_records, 125
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "committee contributions to a candidate" do
|
88
|
+
setup do
|
89
|
+
reply = Base.invoke('2010/committees/C00458588/contributions/candidates/H0NC02059', {})
|
90
|
+
results = reply['results']
|
91
|
+
@cycle = reply['cycle']
|
92
|
+
@committee = reply['committee']
|
93
|
+
@candidate = reply['candidate']
|
94
|
+
@total_amount = reply['total_amount']
|
95
|
+
@contributions = results.map{|c| Contribution.create(@cycle, @committee, c, @candidate)}
|
96
|
+
end
|
97
|
+
|
98
|
+
should "return 2 results totaling $10,000" do
|
99
|
+
assert_equal @contributions.size, 2
|
100
|
+
assert_equal @total_amount, 10000
|
101
|
+
end
|
102
|
+
end
|
59
103
|
end
|
@@ -24,4 +24,14 @@ class TestCampaignCash::TestFiling < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
context "recent statements of organization" do
|
28
|
+
setup do
|
29
|
+
@filings = Filing.by_type(2012, "F1")
|
30
|
+
end
|
31
|
+
|
32
|
+
should "return a list of the 20 most recent Filings that are statements of organization" do
|
33
|
+
assert_equal @filings.size, 20
|
34
|
+
assert_equal @filings.first.report_title, "STATEMENT OF ORGANIZATION"
|
35
|
+
end
|
36
|
+
end
|
27
37
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class TestCampaignCash::TestForm < Test::Unit::TestCase
|
4
|
+
include CampaignCash
|
5
|
+
|
6
|
+
context "form types" do
|
7
|
+
setup do
|
8
|
+
@forms = Form.form_types
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return a list of objects of the Filing type" do
|
12
|
+
assert_kind_of(Form, @forms.first)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -8,7 +8,9 @@ require File.dirname(__FILE__) + '/../lib/campaign_cash'
|
|
8
8
|
require File.dirname(__FILE__) + '/../lib/campaign_cash/base'
|
9
9
|
require File.dirname(__FILE__) + '/../lib/campaign_cash/candidate'
|
10
10
|
require File.dirname(__FILE__) + '/../lib/campaign_cash/committee'
|
11
|
+
require File.dirname(__FILE__) + '/../lib/campaign_cash/contribution'
|
11
12
|
require File.dirname(__FILE__) + '/../lib/campaign_cash/filing'
|
13
|
+
require File.dirname(__FILE__) + '/../lib/campaign_cash/form'
|
12
14
|
|
13
15
|
# set your NYT Campaign Finance API key as an environment variable to run the tests
|
14
16
|
API_KEY = ENV['NYT_CAMPFIN_API_KEY']
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: campaign_cash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
- 5
|
10
|
-
version: 0.0.5
|
9
|
+
version: "1.0"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Derek Willis
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-02-11 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -67,11 +66,14 @@ files:
|
|
67
66
|
- lib/campaign_cash/base.rb
|
68
67
|
- lib/campaign_cash/candidate.rb
|
69
68
|
- lib/campaign_cash/committee.rb
|
69
|
+
- lib/campaign_cash/contribution.rb
|
70
70
|
- lib/campaign_cash/filing.rb
|
71
|
+
- lib/campaign_cash/form.rb
|
71
72
|
- lib/campaign_cash/version.rb
|
72
73
|
- test/campaign_cash/test_candidate.rb
|
73
74
|
- test/campaign_cash/test_committee.rb
|
74
75
|
- test/campaign_cash/test_filing.rb
|
76
|
+
- test/campaign_cash/test_form.rb
|
75
77
|
- test/test_helper.rb
|
76
78
|
has_rdoc: true
|
77
79
|
homepage: http://rubygems.org/gems/campaign_cash
|
@@ -105,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
107
|
requirements: []
|
106
108
|
|
107
109
|
rubyforge_project: campaign_cash
|
108
|
-
rubygems_version: 1.
|
110
|
+
rubygems_version: 1.4.1
|
109
111
|
signing_key:
|
110
112
|
specification_version: 3
|
111
113
|
summary: Following the money.
|