campaign_cash 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/campaign_cash.rb CHANGED
@@ -1,10 +1,15 @@
1
+ # A Ruby wrapper for [The New York Times Campaign Finance API](http://developer.nytimes.com/docs/read/campaign_finance_api).
2
+
1
3
  $:.unshift(File.dirname(__FILE__)) unless
2
4
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
5
 
4
6
  require "campaign_cash/base"
7
+ # [Candidate methods](candidate.html)
5
8
  require "campaign_cash/candidate"
9
+ # [Committee methods](committee.html)
6
10
  require "campaign_cash/committee"
7
- require "campaign_cash/contribution"
11
+ # [Filing methods](filing.html)
8
12
  require "campaign_cash/filing"
13
+ require "campaign_cash/contribution"
9
14
  require "campaign_cash/form"
10
15
  require "campaign_cash/version"
@@ -44,6 +44,7 @@ module CampaignCash
44
44
  date ? Date.parse(date) : nil
45
45
  end
46
46
 
47
+ # Returns the election cycle (even-numbered) from a date.
47
48
  def cycle_from_date(date=Date.today)
48
49
  date.year.even? ? date.year : date.year+1
49
50
  end
@@ -1,6 +1,9 @@
1
1
  module CampaignCash
2
2
  class Candidate < Base
3
3
 
4
+ # Represents a candidate object based on the FEC's candidate and candidate summary files.
5
+ # A candidate is a person seeking a particular office within a particular two-year election
6
+ # cycle. Each candidate is assigned a unique ID within a cycle.
4
7
  attr_reader :name, :id, :state, :district, :party, :fec_uri, :committee,
5
8
  :mailing_city, :mailing_address, :mailing_state, :mailing_zip,
6
9
  :total_receipts, :total_contributions, :total_from_individuals,
@@ -14,6 +17,7 @@ module CampaignCash
14
17
  end
15
18
  end
16
19
 
20
+ # Creates a new candidate object from a JSON API response.
17
21
  def self.create(params={})
18
22
  self.new :name => params['name'],
19
23
  :id => params['id'],
@@ -51,31 +55,42 @@ module CampaignCash
51
55
  :committee => params['committee']
52
56
 
53
57
  end
54
-
58
+
59
+ # Retrieve a candidate object via its FEC candidate id within a cycle.
60
+ # Defaults to the current cycle.
55
61
  def self.find(fecid, cycle=CURRENT_CYCLE)
56
62
  reply = invoke("#{cycle}/candidates/#{fecid}")
57
63
  result = reply['results']
58
64
  self.create(result.first) if result.first
59
65
  end
60
66
 
67
+ # Returns leading candidates for given categories from campaign filings within a cycle.
68
+ # See [the API docs](http://developer.nytimes.com/docs/read/campaign_finance_api#h3-candidate-leaders) for
69
+ # a list of acceptable categories to pass in. Defaults to the current cycle.
61
70
  def self.leaders(category, cycle=CURRENT_CYCLE)
62
71
  reply = invoke("#{cycle}/candidates/leaders/#{category}",{})
63
72
  results = reply['results']
64
73
  results.map{|c| self.create(c)}
65
74
  end
66
75
 
76
+ # Returns an array of candidates matching a search term within a cycle. Defaults to the
77
+ # current cycle.
67
78
  def self.search(name, cycle=CURRENT_CYCLE)
68
79
  reply = invoke("#{cycle}/candidates/search", {:query => name})
69
80
  results = reply['results']
70
81
  results.map{|c| self.create_from_search_results(c)}
71
82
  end
72
83
 
84
+ # Returns an array of newly created FEC candidates within a current cycle. Defaults to the
85
+ # current cycle.
73
86
  def self.new_candidates(cycle=CURRENT_CYCLE)
74
87
  reply = invoke("#{cycle}/candidates/new",{})
75
88
  results = reply['results']
76
89
  results.map{|c| self.create(c)}
77
90
  end
78
91
 
92
+ # Returns an array of candidates for a given state and chamber within a cycle, with an optional
93
+ # district parameter. For example, House candidates from New York. Defaults to the current cycle.
79
94
  def self.state_chamber(state, chamber, district=nil, cycle=CURRENT_CYCLE)
80
95
  district ? path = "#{cycle}/seats/#{state}/#{chamber}/#{district}" : path = "#{cycle}/seats/#{state}/#{chamber}"
81
96
  reply = invoke(path,{})
@@ -64,7 +64,7 @@ module CampaignCash
64
64
  results.map{|c| self.create_from_api_search_results(c)}
65
65
  end
66
66
 
67
- def self.new_candidates(cycle=CURRENT_CYCLE)
67
+ def self.new_committees(cycle=CURRENT_CYCLE)
68
68
  reply = invoke("#{cycle}/committees/new",{})
69
69
  results = reply['results']
70
70
  results.map{|c| self.create_from_api(c)}
@@ -1,3 +1,3 @@
1
1
  module CampaignCash
2
- VERSION = "1.0"
2
+ VERSION = "1.1"
3
3
  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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
- version: "1.0"
8
+ - 1
9
+ version: "1.1"
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-02-11 00:00:00 -05:00
17
+ date: 2011-05-14 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  requirements: []
108
108
 
109
109
  rubyforge_project: campaign_cash
110
- rubygems_version: 1.4.1
110
+ rubygems_version: 1.4.2
111
111
  signing_key:
112
112
  specification_version: 3
113
113
  summary: Following the money.