Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add FilingSummary class, fix IndividualContribution methods, put nyt_…

…api_key in its own file for testing so I don't accidentally commit it
  • Loading branch information...
commit 0f1468493f2776b6d44cd9064e3d51177531ec9d 1 parent 9097d6e
@ashaw ashaw authored
View
1  .gitignore
@@ -1,3 +1,4 @@
pkg/*
*.gem
.bundle
+*nyt_api_key.rb
View
2  lib/campaign_cash.rb
@@ -1,3 +1,3 @@
-%w(base candidate committee contribution individual_contribution filing form independent_expenditure president).each do |f|
+%w(base candidate committee contribution individual_contribution filing filing_summary form independent_expenditure president).each do |f|
require File.join(File.dirname(__FILE__), '../lib/campaign_cash', f)
end
View
7 lib/campaign_cash/filing.rb
@@ -14,7 +14,7 @@ def self.create(params={})
:date_coverage_from => date_parser(params['date_coverage_from']),
:date_coverage_to => date_parser(params['date_coverage_to']),
:committee => parse_committee(params['committee']),
- :report_title => params['report_title'].strip,
+ :report_title => params['report_title'] ? params['report_title'].strip : "",
:fec_uri => params['fec_uri'],
:amended => params['amended'],
:amended_uri => params['amended_uri'],
@@ -63,10 +63,5 @@ def self.by_type(cycle, form_type)
results = reply['results']
results.map{|c| Filing.create(c)}
end
-
- def self.by_id(id)
- cycle = CURRENT_CYCLE
- result = Filing.create(Base.invoke("#{cycle}/filings/#{id}"))
- end
end
end
View
23 lib/campaign_cash/filing_summary.rb
@@ -0,0 +1,23 @@
+module CampaignCash
+ class FilingSummary < Base
+
+ attr_reader :pac_contributions_period, :contributions_2300, :party_contributions_cycle, :fundraising_offsets_period, :primary_general, :pac_refunds_cycle, :created_at, :party_refunds_cycle, :fundraising_expenses_period, :net_party_contributions, :num_contributions_200_499, :individual_refunds_cycle, :candidate_contributions_period, :legal_offsets_cycle, :num_contributions_500_1499, :net_operating_expenses, :total_debts_owed, :refunds_200_499, :refunds_1500_2299, :transfers_out_period, :net_primary, :liquidate_period, :contributions_200_499, :operating_offsets_cycle, :num_contributions_1500_2299, :candidate_loan_repayments_period, :committee_uri, :federal_funds_cycle, :net_candidate_contributions, :candidate_loans_period, :filing_id, :net_pac_contributions, :num_refunds_200_499, :candidate_loan_repayments_cycle, :total_offsets_cycle, :party_contributions_period, :net_individual_contributions, :num_refunds_1500_2299, :net_general, :total_receipts_cycle, :federal_funds_period, :transfers_out_cycle, :cycle, :other_loan_repayments_period, :contributions_500_1499, :legal_offsets_period, :date_coverage_from, :contributions_less_than_200, :fec_form_type, :candidate_contributions_cycle, :cash_on_hand_beginning, :individual_refunds_period, :updated_at, :fundraising_expenses_cycle, :num_refunds_500_1499, :cash_on_hand_close, :num_contributions_less_than_200, :total_loans_cycle, :candidate_uri, :contributions_1500_2299, :refunds_2300, :flag_most_current_report, :total_loan_repayments_period, :other_loans_period, :operating_expenditures_cycle, :other_disbursements_period, :total_loans_period, :transfers_in_period, :transfers_in_cycle, :report, :legal_expenses_period, :candidate_loans_cycle, :individual_contributions_period, :other_disbursements_cycle, :total_disbursements_period, :other_loans_cycle, :net_transfers_in, :net_disbursements, :operating_expenditures_period, :fundraising_offsets_cycle, :date_coverage_to, :total_loan_repayments_cycle, :total_disbursements_cycle, :party_refunds_period, :individual_contributions_cycle, :net_total_contributions, :other_loan_repayments_cycle, :total_refunds_cycle, :total_receipts_period, :total_offsets_period, :total_contributions_period, :total_contributions_cycle, :refunds_500_1499, :pac_refunds_period, :flag_valid_report, :legal_expenses_cycle, :num_refunds_less_than_200, :refunds_less_than_200, :pac_contributions_cycle, :net_legal_expenses, :net_fundraising_expenses, :num_contributions_2300, :total_refunds_period, :operating_offsets_period, :num_refunds_2300
+
+ def initialize(params={})
+ params.each_pair do |k,v|
+ instance_variable_set("@#{k}", v)
+ end
+ end
+
+ def self.create(params={})
+ self.new(params)
+ end
+
+ def self.by_id(id)
+ cycle = CURRENT_CYCLE
+ result = FilingSummary.create(Base.invoke("#{cycle}/filings/#{id}")["results"]["filing_summary"])
+ end
+ end
+end
+
+
View
6 lib/campaign_cash/individual_contribution.rb
@@ -15,19 +15,19 @@ def self.create(params={})
def self.committee(fecid, offset=nil)
cycle = CURRENT_CYCLE
- results = invoke("#{cycle}/contributions/committee/#{fecid}", {:offset => offset})
+ results = invoke("#{cycle}/contributions/committee/#{fecid}", {:offset => offset})['results']
results.map{|c| IndividualContribution.create(c) }
end
def self.filing(form_id, offset=nil)
cycle = CURRENT_CYCLE
- results = invoke("#{cycle}/contributions/filing/#{form_id}", {:offset => offset})
+ results = invoke("#{cycle}/contributions/filing/#{form_id}", {:offset => offset})['results']
results.map{|c| IndividualContribution.create(c) }
end
def self.candidate(fecid, offset=nil)
cycle = CURRENT_CYCLE
- results = invoke("#{cycle}/contributions/candidate/#{fecid}", {:offset => offset})
+ results = invoke("#{cycle}/contributions/candidate/#{fecid}", {:offset => offset})['results']
results.map{|c| IndividualContribution.create(c) }
end
View
13 test/campaign_cash/test_filing.rb
@@ -37,16 +37,5 @@ class TestCampaignCash::TestFiling < Test::Unit::TestCase
assert_equal @filings.size, 20
assert_equal @filings.first.report_title, "STATEMENT OF ORGANIZATION"
end
- end
-
- context "individual filings" do
- setup do
- @filing = Filing.by_id(751678)
- end
- should "get a filing by form id" do
- assert_kind_of(Filing, @filing)
- end
- end
-
-
+ end
end
View
14 test/campaign_cash/test_filing_summary.rb
@@ -0,0 +1,14 @@
+require 'test_helper'
+
+class TestCampaignCash::TestFilingSummary < Test::Unit::TestCase
+ include CampaignCash
+
+ context "filing summaries" do
+ setup do
+ @filing_summary = FilingSummary.by_id(751678)
+ end
+ should "get a filing by form id" do
+ assert_kind_of(FilingSummary, @filing_summary)
+ end
+ end
+end
View
2  test/campaign_cash/test_individual_contribution.rb
@@ -3,7 +3,7 @@
class TestCampaignCash::TestIndividualContribution < Test::Unit::TestCase
include CampaignCash
- should "get contributions" do
+ context "get contributions" do
objs_collection = []
objs_collection << IndividualContribution.committee("C00496497")
objs_collection << IndividualContribution.filing("724196")
View
8 test/test_helper.rb
@@ -4,12 +4,14 @@
require 'json'
require 'ostruct'
-%w(base candidate committee contribution individual_contribution filing form independent_expenditure president).each do |f|
+%w(base candidate committee contribution individual_contribution filing filing_summary form independent_expenditure president).each do |f|
require File.join(File.dirname(__FILE__), '../lib/campaign_cash', f)
end
-# set your NYT Campaign Finance API key as an environment variable to run the tests
-API_KEY = ENV['NYT_CAMPFIN_API_KEY']
+require 'nyt_api_key'
+
+# Create a file called nyt_api_key.rb in test/campaign_cash with your API key:
+# API_KEY = "your_api_key"
CampaignCash::Base.api_key = API_KEY
module TestCampaignCash

0 comments on commit 0f14684

Please sign in to comment.
Something went wrong with that request. Please try again.