campaign_cash 1.6 → 1.7
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/Gemfile.lock +19 -0
- data/README.rdoc +9 -1
- data/campaign_cash.gemspec +1 -0
- data/lib/campaign_cash/base.rb +1 -1
- data/lib/campaign_cash/candidate.rb +18 -9
- data/lib/campaign_cash/committee.rb +7 -2
- data/lib/campaign_cash/filing.rb +1 -1
- data/lib/campaign_cash/independent_expenditure.rb +1 -1
- data/lib/campaign_cash/version.rb +1 -1
- data/test/campaign_cash/test_candidate.rb +2 -2
- metadata +19 -4
data/Gemfile.lock
ADDED
data/README.rdoc
CHANGED
@@ -8,7 +8,15 @@ Simple ruby wrapper for The New York Times Campaign Finance API[http://developer
|
|
8
8
|
|
9
9
|
== INSTALL:
|
10
10
|
|
11
|
-
|
11
|
+
Install Campaign Cash as a gem:
|
12
|
+
|
13
|
+
gem install campaign_cash
|
14
|
+
|
15
|
+
For use in a Rails 3 application, put the following in your Gemfile:
|
16
|
+
|
17
|
+
gem 'campaign_cash'
|
18
|
+
|
19
|
+
then issue the 'bundle install' command. Campaign Cash has been tested under Ruby 1.8.7 and 1.9.2.
|
12
20
|
|
13
21
|
== USAGE:
|
14
22
|
|
data/campaign_cash.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_runtime_dependency "json"
|
18
18
|
|
19
19
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
20
|
+
s.add_development_dependency "shoulda"
|
20
21
|
|
21
22
|
s.files = `git ls-files`.split("\n")
|
22
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/campaign_cash/base.rb
CHANGED
@@ -21,12 +21,12 @@ module CampaignCash
|
|
21
21
|
def self.create(params={})
|
22
22
|
self.new :name => params['name'],
|
23
23
|
:id => params['id'],
|
24
|
-
:state => params['state']
|
25
|
-
:office => parse_office(params['id']
|
24
|
+
:state => parse_state(params['state']),
|
25
|
+
:office => parse_office(params['id']),
|
26
26
|
:district => parse_district(params['district']),
|
27
27
|
:party => params['party'],
|
28
28
|
:fec_uri => params['fec_uri'],
|
29
|
-
:committee_id => params['committee']
|
29
|
+
:committee_id => parse_committee_id(params['committee']),
|
30
30
|
:mailing_city => params['mailing_city'],
|
31
31
|
:mailing_address => params['mailing_address'],
|
32
32
|
:mailing_state => params['mailing_state'],
|
@@ -49,18 +49,27 @@ module CampaignCash
|
|
49
49
|
def self.create_from_search_results(params={})
|
50
50
|
self.new :name => params['candidate']['name'],
|
51
51
|
:id => params['candidate']['id'],
|
52
|
-
:state => params['
|
53
|
-
:office => parse_office(params['candidate']['id']
|
52
|
+
:state => params['candidate']['id'][2..3],
|
53
|
+
:office => parse_office(params['candidate']['id'][0..0]),
|
54
54
|
:district => parse_district(params['district']),
|
55
55
|
:party => params['candidate']['party'],
|
56
|
-
:committee_id => params['committee']
|
56
|
+
:committee_id => parse_committee_id(params['committee'])
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
+
def self.parse_state(state)
|
61
|
+
state.split('/').last[0..1] if state
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.parse_committee_id(committee)
|
65
|
+
committee.nil? ? nil : committee.split('/').last[0..8]
|
66
|
+
end
|
67
|
+
|
60
68
|
def self.parse_office(id)
|
61
|
-
|
69
|
+
return nil unless id
|
70
|
+
if id[0..0] == "H"
|
62
71
|
'house'
|
63
|
-
elsif id
|
72
|
+
elsif id[0..0] == 'S'
|
64
73
|
'senate'
|
65
74
|
else
|
66
75
|
'president'
|
@@ -68,7 +77,7 @@ module CampaignCash
|
|
68
77
|
end
|
69
78
|
|
70
79
|
def self.parse_district(uri)
|
71
|
-
if uri.split('/').last.split('.').first.to_i > 0
|
80
|
+
if uri and uri.split('/').last.split('.').first.to_i > 0
|
72
81
|
uri.split('/').last.split('.').first.to_i
|
73
82
|
else
|
74
83
|
0
|
@@ -35,7 +35,7 @@ module CampaignCash
|
|
35
35
|
:end_cash => params['end_cash'],
|
36
36
|
:date_coverage_from => params['date_coverage_from'],
|
37
37
|
:date_coverage_to => params['date_coverage_to'],
|
38
|
-
:
|
38
|
+
:candidate_id => parse_candidate(params['candidate']),
|
39
39
|
:other_cycles => params['other_cycles'].map{|cycle| cycle['cycle']['fec_committee']['cycle']}
|
40
40
|
end
|
41
41
|
|
@@ -48,13 +48,18 @@ module CampaignCash
|
|
48
48
|
:district => params['district'],
|
49
49
|
:party => params['party'],
|
50
50
|
:relative_uri => params['relative_uri'],
|
51
|
-
:
|
51
|
+
:candidate_id => parse_candidate(params['candidate']),
|
52
52
|
:treasurer => params['treasurer'],
|
53
53
|
:fec_uri => params['fec_uri'],
|
54
54
|
:super_pac => params['super_pac'],
|
55
55
|
:sponsor_name => params['sponsor_name']
|
56
56
|
|
57
57
|
end
|
58
|
+
|
59
|
+
def self.parse_candidate(candidate)
|
60
|
+
return nil if candidate.nil?
|
61
|
+
candidate.split('/').last.split('.').first
|
62
|
+
end
|
58
63
|
|
59
64
|
def self.find(fecid, cycle=CURRENT_CYCLE)
|
60
65
|
reply = invoke("#{cycle}/committees/#{fecid}")
|
data/lib/campaign_cash/filing.rb
CHANGED
@@ -42,7 +42,7 @@ module CampaignCash
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.date(year, month, day)
|
45
|
-
cycle = cycle_from_date(Date.
|
45
|
+
cycle = cycle_from_date(Date.strptime("#{month}/#{day}/#{year}", '%m/%d/%Y'))
|
46
46
|
reply = Base.invoke("#{cycle}/filings/#{year}/#{month}/#{day}", {})
|
47
47
|
results = reply['results']
|
48
48
|
@filings = results.map{|c| Filing.create(c)}
|
@@ -32,7 +32,7 @@ module CampaignCash
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.date(date)
|
35
|
-
d = Date.
|
35
|
+
d = Date.strptime(date, '%m/%d/%Y')
|
36
36
|
cycle = cycle_from_date(d)
|
37
37
|
reply = Base.invoke("#{cycle}/independent_expenditures/#{d.year}/#{d.month}/#{d.day}")
|
38
38
|
results = reply['results']
|
@@ -14,7 +14,7 @@ class TestCampaignCash::TestCandidate < Test::Unit::TestCase
|
|
14
14
|
assert_kind_of(Candidate, @candidate)
|
15
15
|
end
|
16
16
|
|
17
|
-
%w(name id
|
17
|
+
%w(name id party fec_uri).each do |attr|
|
18
18
|
should "assign the value of the @#{attr} attribute from the '#{attr}' key in the hash" do
|
19
19
|
assert_equal(@result[attr], @candidate.send(attr))
|
20
20
|
end
|
@@ -37,7 +37,7 @@ class TestCampaignCash::TestCandidate < Test::Unit::TestCase
|
|
37
37
|
|
38
38
|
context "New Candidates" do
|
39
39
|
setup do
|
40
|
-
reply = Base.invoke('
|
40
|
+
reply = Base.invoke('2012/candidates/new', {})
|
41
41
|
results = reply['results']
|
42
42
|
@candidates = results.map{|c| Candidate.create(c)}
|
43
43
|
end
|
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:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: "1.
|
8
|
+
- 7
|
9
|
+
version: "1.7"
|
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-12-
|
17
|
+
date: 2011-12-20 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,20 @@ dependencies:
|
|
47
47
|
version: 1.0.0
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: shoulda
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :development
|
63
|
+
version_requirements: *id003
|
50
64
|
description: A thin client for The New York Times Campaign Finance API
|
51
65
|
email:
|
52
66
|
- dwillis@nytimes.com
|
@@ -59,6 +73,7 @@ extra_rdoc_files: []
|
|
59
73
|
files:
|
60
74
|
- .gitignore
|
61
75
|
- Gemfile
|
76
|
+
- Gemfile.lock
|
62
77
|
- LICENSE
|
63
78
|
- README.rdoc
|
64
79
|
- Rakefile
|