campaign_cash 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/campaign_cash/version", __FILE__)
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "campaign_cash/version"
3
4
 
4
5
  Gem::Specification.new do |s|
5
6
  s.name = "campaign_cash"
@@ -17,7 +18,8 @@ Gem::Specification.new do |s|
17
18
 
18
19
  s.add_development_dependency "bundler", ">= 1.0.0"
19
20
 
20
- s.files = `git ls-files`.split("\n")
21
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
22
- s.require_path = 'lib'
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
23
25
  end
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
  require 'open-uri'
3
3
  require 'json'
4
4
  require 'date'
5
+ require 'ostruct'
5
6
 
6
7
  module CampaignCash
7
8
  class Base
@@ -6,7 +6,7 @@ module CampaignCash
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
9
+ :date_coverage_to, :date_coverage_from, :other_cycles
10
10
 
11
11
  def initialize(params={})
12
12
  params.each_pair do |k,v|
@@ -35,7 +35,8 @@ 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 => params['candidate'],
39
+ :other_cycles => params['other_cycles'].map{|cycle| cycle['cycle']['fec_committee']['cycle']}
39
40
  end
40
41
 
41
42
  def self.create_from_search_results(params={})
@@ -55,19 +56,24 @@ module CampaignCash
55
56
  def self.find(fecid, cycle=CURRENT_CYCLE)
56
57
  reply = invoke("#{cycle}/committees/#{fecid}")
57
58
  result = reply['results']
58
- self.create_from_api(result.first) if result.first
59
+ create(result.first) if result.first
59
60
  end
60
61
 
61
62
  def self.search(name, cycle=CURRENT_CYCLE)
62
63
  reply = invoke("#{cycle}/committees/search", {:query => name})
63
64
  results = reply['results']
64
- results.map{|c| self.create_from_api_search_results(c)}
65
+ results.map{|c| create_from_search_results(c)}
65
66
  end
66
67
 
67
68
  def self.new_committees(cycle=CURRENT_CYCLE)
68
69
  reply = invoke("#{cycle}/committees/new",{})
69
70
  results = reply['results']
70
- results.map{|c| self.create_from_api(c)}
71
+ results.map{|c| create(c)}
72
+ end
73
+
74
+ def contributions
75
+ reply = invoke("#{cycle}/committees/#{id}/contributions")
76
+
71
77
  end
72
78
 
73
79
  end
@@ -1,7 +1,7 @@
1
1
  module CampaignCash
2
2
  class Contribution < Base
3
3
 
4
- attr_reader :date, :candidate_uri, :primary_general, :amount, :state, :name, :image_uri, :party, :district
4
+ attr_reader :date, :candidate_uri, :primary_general, :amount, :state, :name, :image_uri, :party, :district, :committee_uri, :results, :total_results, :total_amount, :cycle
5
5
 
6
6
  def initialize(params={})
7
7
  params.each_pair do |k,v|
@@ -9,18 +9,32 @@ module CampaignCash
9
9
  end
10
10
  end
11
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
12
+ def self.create(params={})
13
+ self.new :committee_uri => params['committee'],
14
+ :total_results => params['total_results'],
15
+ :cycle => params['cycle'],
16
+ :total_amount => params['total_amount'],
17
+ :results => params['results'].map{|c| OpenStruct.new({
18
+ :date => date_parser(c['date']),
19
+ :candidate_uri => c['candidate_uri'],
20
+ :primary_general => c['primary_general'],
21
+ :amount => c['amount'],
22
+ :state => c['state'],
23
+ :name => c['name'],
24
+ :image_uri => c['image_uri'],
25
+ :party => c['party'],
26
+ :district => c['district']})}
27
+
24
28
  end
29
+
30
+ def self.find(fecid, cycle=CURRENT_CYCLE, candidate=nil)
31
+ if candidate
32
+ reply = invoke("#{cycle}/committees/#{fecid}/contributions/candidates/#{candidate}")
33
+ else
34
+ reply = invoke("#{cycle}/committees/#{fecid}/contributions")
35
+ end
36
+ create(reply)
37
+ end
38
+
25
39
  end
26
40
  end
@@ -1,3 +1,3 @@
1
1
  module CampaignCash
2
- VERSION = "1.2"
2
+ VERSION = "1.3"
3
3
  end
data/lib/campaign_cash.rb CHANGED
@@ -1,15 +1,3 @@
1
- # A Ruby wrapper for [The New York Times Campaign Finance API](http://developer.nytimes.com/docs/read/campaign_finance_api).
2
-
3
- $:.unshift(File.dirname(__FILE__)) unless
4
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
-
6
- require "campaign_cash/base"
7
- # [Candidate methods](candidate.html)
8
- require "campaign_cash/candidate"
9
- # [Committee methods](committee.html)
10
- require "campaign_cash/committee"
11
- # [Filing methods](filing.html)
12
- require "campaign_cash/filing"
13
- require "campaign_cash/contribution"
14
- require "campaign_cash/form"
15
- require "campaign_cash/version"
1
+ %w(base candidate committee contribution filing form).each do |f|
2
+ require File.join(File.dirname(__FILE__), '../lib/campaign_cash', f)
3
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
1
+ require 'test_helper'
2
2
 
3
3
  class TestCampaignCash::TestCandidate < Test::Unit::TestCase
4
4
  include CampaignCash
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
1
+ require 'test_helper'
2
2
 
3
3
  class TestCampaignCash::TestCommittee < Test::Unit::TestCase
4
4
  include CampaignCash
@@ -56,40 +56,45 @@ class TestCampaignCash::TestCommittee < Test::Unit::TestCase
56
56
  @filings = results.map{|f| Filing.create_from_filings(f)}
57
57
  end
58
58
 
59
- should "return 20 filings" do
60
- assert_equal @filings.size, 20
59
+ should "return 11 filings" do
60
+ assert_equal @filings.size, 11
61
+ end
62
+ end
63
+
64
+ context "committee detail" do
65
+ setup do
66
+ @committee = Committee.find('C00084475', 2012)
67
+ end
68
+
69
+ should "return 16 other cycles" do
70
+ assert_equal @committee.other_cycles.size, 16
61
71
  end
62
72
  end
63
73
 
64
74
  context "committee contributions" do
65
75
  setup do
66
- reply = Base.invoke('2010/committees/C00458588/contributions', {})
67
- results = reply['results']
68
- @committee = reply['committee']
69
- @num_records = reply['total_results']
70
- @total_amount = reply['total_amount']
71
- @contributions = results.map{|c| Contribution.create(@committee, c)}
76
+ @contribution = Contribution.find('C00458588', 2010)
72
77
  end
73
78
 
74
79
  should "return 125 total results" do
75
- assert_equal @num_records, 125
80
+ assert_equal @contribution.total_results, 125
81
+ end
82
+
83
+ should "return a $5,000 contribution to Renee Ellmers" do
84
+ assert_equal @contribution.results.detect{|c| c.candidate_uri == "/candidates/H0NC02059.json"}.amount, 5000
76
85
  end
86
+
77
87
  end
78
88
 
79
89
  context "committee contributions to a candidate" do
80
90
  setup do
81
91
  reply = Base.invoke('2010/committees/C00458588/contributions/candidates/H0NC02059', {})
82
- results = reply['results']
83
- @cycle = reply['cycle']
84
- @committee = reply['committee']
85
- @candidate = reply['candidate']
86
- @total_amount = reply['total_amount']
87
- @contributions = results.map{|c| Contribution.create(@cycle, @committee, c, @candidate)}
92
+ @contribution = Contribution.create(reply)
88
93
  end
89
94
 
90
95
  should "return 2 results totaling $10,000" do
91
- assert_equal @contributions.size, 2
92
- assert_equal @total_amount, 10000
96
+ assert_equal @contribution.results.size, 2
97
+ assert_equal @contribution.total_amount, 10000
93
98
  end
94
99
  end
95
100
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
1
+ require 'test_helper'
2
2
 
3
3
  class TestCampaignCash::TestFiling < Test::Unit::TestCase
4
4
  include CampaignCash
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
1
+ require 'test_helper'
2
2
 
3
3
  class TestCampaignCash::TestForm < Test::Unit::TestCase
4
4
  include CampaignCash
data/test/test_helper.rb CHANGED
@@ -1,25 +1,18 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
3
  require 'shoulda'
4
- require 'mocha'
5
4
  require 'json'
5
+ require 'ostruct'
6
6
 
7
- require File.dirname(__FILE__) + '/../lib/campaign_cash'
8
- require File.dirname(__FILE__) + '/../lib/campaign_cash/base'
9
- require File.dirname(__FILE__) + '/../lib/campaign_cash/candidate'
10
- require File.dirname(__FILE__) + '/../lib/campaign_cash/committee'
11
- require File.dirname(__FILE__) + '/../lib/campaign_cash/contribution'
12
- require File.dirname(__FILE__) + '/../lib/campaign_cash/filing'
13
- require File.dirname(__FILE__) + '/../lib/campaign_cash/form'
7
+ %w(base candidate committee contribution filing form).each do |f|
8
+ require File.join(File.dirname(__FILE__), '../lib/campaign_cash', f)
9
+ end
10
+
11
+ include CampaignCash
14
12
 
15
13
  # set your NYT Campaign Finance API key as an environment variable to run the tests
16
14
  API_KEY = ENV['NYT_CAMPFIN_API_KEY']
17
15
  CampaignCash::Base.api_key = API_KEY
18
16
 
19
- def api_url_for(path, params = {})
20
- full_params = params.merge 'api-key' => API_KEY
21
- CampaignCash::Base.build_request_url(path, full_params).to_s
22
- end
23
-
24
17
  module TestCampaignCash
25
18
  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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- version: "1.2"
8
+ - 3
9
+ version: "1.3"
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-05-15 00:00:00 -04:00
17
+ date: 2011-07-03 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -111,5 +111,9 @@ rubygems_version: 1.4.2
111
111
  signing_key:
112
112
  specification_version: 3
113
113
  summary: Following the money.
114
- test_files: []
115
-
114
+ test_files:
115
+ - test/campaign_cash/test_candidate.rb
116
+ - test/campaign_cash/test_committee.rb
117
+ - test/campaign_cash/test_filing.rb
118
+ - test/campaign_cash/test_form.rb
119
+ - test/test_helper.rb