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 ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ campaign_cash (1.7)
5
+ json
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ json (1.6.3)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (>= 1.0.0)
18
+ campaign_cash!
19
+ shoulda
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
- * <tt>gem install campaign_cash</tt>
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
 
@@ -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")
@@ -42,7 +42,7 @@ module CampaignCash
42
42
  end
43
43
 
44
44
  def date_parser(date)
45
- date ? Date.parse(date) : nil
45
+ date ? Date.strptime(date, '%Y-%m-%d') : nil
46
46
  end
47
47
 
48
48
  # Returns the election cycle (even-numbered) from a date.
@@ -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'].split('/').last[0..1],
25
- :office => parse_office(params['id'].first),
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'].split('/').last[0..8],
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['state'].split('/').last[0..1],
53
- :office => parse_office(params['candidate']['id'].first),
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'].split('/').last[0..8]
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
- if id.first == "H"
69
+ return nil unless id
70
+ if id[0..0] == "H"
62
71
  'house'
63
- elsif id.first == 'S'
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
- :candidate => params['candidate'],
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
- :candidate => params['candidate'],
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}")
@@ -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.parse("#{month}/#{day}/#{year}"))
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.parse(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']
@@ -1,3 +1,3 @@
1
1
  module CampaignCash
2
- VERSION = "1.6"
2
+ VERSION = "1.7"
3
3
  end
@@ -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 state district party fec_uri committee).each do |attr|
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('2010/candidates/new', {})
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 6
9
- version: "1.6"
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-18 00:00:00 -05:00
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