campaign_cash 2.6.2 → 2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,8 @@ module CampaignCash
2
2
  class Contribution < Base
3
3
 
4
4
  attr_reader :date, :candidate_uri, :primary_general, :amount, :state, :name,
5
- :image_uri, :party, :district, :committee_uri, :results, :total_results, :total_amount,
6
- :cycle, :record_number, :transaction_id, :transaction_type
5
+ :image_uri, :party, :district, :committee_uri, :results, :total_results, :total_amount,
6
+ :cycle, :record_number, :transaction_id, :transaction_type
7
7
 
8
8
  def initialize(params={})
9
9
  params.each_pair do |k,v|
@@ -12,44 +12,44 @@ module CampaignCash
12
12
  end
13
13
 
14
14
  def self.to_candidate(params={})
15
- self.new :committee => parse_committee(params['committee']),
16
- :cycle => params['cycle'].to_i,
17
- :total_amount => params['total_amount'].to_f,
18
- :results => params['results'].map{|c| OpenStruct.new({
19
- :candidate => parse_candidate(params['candidate_uri']),
20
- :date => date_parser(c['date']),
21
- :primary_general => c['primary_general'],
22
- :amount => c['amount'].to_f,
23
- :state => c['state'],
24
- :name => c['name'],
25
- :image_uri => c['image_uri'],
26
- :party => c['party'],
27
- :district => c['district'],
28
- :record_number => c['record_number'],
29
- :transaction_type => c['transaction_type'],
30
- :transaction_id => c['transaction_id']
15
+ self.new committee: parse_committee(params['committee']),
16
+ cycle: params['cycle'].to_i,
17
+ total_amount: params['total_amount'].to_f,
18
+ results: params['results'].map{|c| OpenStruct.new({
19
+ candidate: parse_candidate(params['candidate_uri']),
20
+ date: date_parser(c['date']),
21
+ primary_general: c['primary_general'],
22
+ amount: c['amount'].to_f,
23
+ state: c['state'],
24
+ name: c['name'],
25
+ image_uri: c['image_uri'],
26
+ party: c['party'],
27
+ district: c['district'],
28
+ record_number: c['record_number'],
29
+ transaction_type: c['transaction_type'],
30
+ transaction_id: c['transaction_id']
31
31
  })}
32
32
 
33
33
  end
34
34
 
35
35
  def self.all_candidates(params={})
36
- self.new :committee => parse_committee(params['committee']),
37
- :cycle => params['cycle'].to_i,
38
- :total_amount => params['total_amount'].to_f,
39
- :total_results => params['total_results'].to_i,
40
- :results => params['results'].map{|c| OpenStruct.new({
41
- :date => date_parser(c['date']),
42
- :candidate => parse_candidate(c['candidate_uri']),
43
- :primary_general => c['primary_general'],
44
- :amount => c['amount'].to_f,
45
- :state => c['state'],
46
- :name => c['name'],
47
- :image_uri => c['image_uri'],
48
- :party => c['party'],
49
- :district => c['district'],
50
- :record_number => c['record_number'],
51
- :transaction_type => c['transaction_type'],
52
- :transaction_id => c['transaction_id']
36
+ self.new committee: parse_committee(params['committee']),
37
+ cycle: params['cycle'].to_i,
38
+ total_amount: params['total_amount'].to_f,
39
+ total_results: params['total_results'].to_i,
40
+ results: params['results'].map{|c| OpenStruct.new({
41
+ date: date_parser(c['date']),
42
+ candidate: parse_candidate(c['candidate_uri']),
43
+ primary_general: c['primary_general'],
44
+ amount: c['amount'].to_f,
45
+ state: c['state'],
46
+ name: c['name'],
47
+ image_uri: c['image_uri'],
48
+ party: c['party'],
49
+ district: c['district'],
50
+ record_number: c['record_number'],
51
+ transaction_type: c['transaction_type'],
52
+ transaction_id: c['transaction_id']
53
53
  })}
54
54
 
55
55
  end
@@ -14,20 +14,20 @@ module CampaignCash
14
14
 
15
15
  def self.latest(offset = nil)
16
16
  cycle = CURRENT_CYCLE
17
- results = invoke("#{cycle}/electioneering_communications", {:offset => offset})['results']
17
+ results = invoke("#{cycle}/electioneering_communications", {offset: offset})['results']
18
18
  results.map {|obj| ElectioneeringCommunication.create(obj)}
19
19
  end
20
20
 
21
21
  def self.committee(committee_id, offset = nil)
22
22
  cycle = CURRENT_CYCLE
23
- results = invoke("#{cycle}/committees/#{committee_id}/electioneering_communications", {:offset => offset})['results']
23
+ results = invoke("#{cycle}/committees/#{committee_id}/electioneering_communications", {offset: offset})['results']
24
24
  results.map {|obj| ElectioneeringCommunication.create(obj)}
25
25
  end
26
26
 
27
27
  def self.date(date, offset = nil)
28
28
  cycle = CURRENT_CYCLE
29
29
  d = Date.strptime(date, '%m/%d/%Y')
30
- results = invoke("#{cycle}/electioneering_communications/#{d.year}/#{d.month}/#{d.day}", {:offset => offset})['results']
30
+ results = invoke("#{cycle}/electioneering_communications/#{d.year}/#{d.month}/#{d.day}", {offset: offset})['results']
31
31
  results.map {|obj| ElectioneeringCommunication.create(obj)}
32
32
  end
33
33
  end
@@ -2,8 +2,8 @@ module CampaignCash
2
2
  class Filing < Base
3
3
 
4
4
  attr_reader :committee_name, :date_coverage_from, :amended_uri, :fec_uri, :date_coverage_to, :committee, :report_title, :amended, :date_filed,
5
- :cycle, :form_type, :original_filing, :original_uri, :paper, :committee_type, :filing_id, :receipts_total, :disbursements_total, :cash_on_hand,
6
- :is_amendment
5
+ :cycle, :form_type, :original_filing, :original_uri, :paper, :committee_type, :filing_id, :receipts_total, :disbursements_total, :cash_on_hand,
6
+ :is_amendment
7
7
 
8
8
  def initialize(params={})
9
9
  params.each_pair do |k,v|
@@ -12,37 +12,37 @@ module CampaignCash
12
12
  end
13
13
 
14
14
  def self.create(params={}, name=nil)
15
- self.new :date_coverage_from => date_parser(params['date_coverage_from']),
16
- :date_coverage_to => date_parser(params['date_coverage_to']),
17
- :committee => parse_committee(params['committee']),
18
- :report_title => params['report_title'].strip,
19
- :fec_uri => params['fec_uri'],
20
- :amended => params['amended'],
21
- :amended_uri => params['amended_uri'],
22
- :original_filing => params['original_filing'],
23
- :original_uri => params['original_uri'],
24
- :paper => params['paper'],
25
- :form_type => params['form_type'],
26
- :filing_id => params['filing_id'],
27
- :committee_type => Committee.get_committee_type(params['committee_type']),
28
- :committee_name => params['committee_name'],
29
- :receipts_total => params['receipts_total'],
30
- :contributions_total => params['contributions_total'],
31
- :disbursements_total => params['disbursements_total'],
32
- :cash_on_hand => params['cash_on_hand'],
33
- :is_amendment => params['is_amendment']
15
+ self.new date_coverage_from: date_parser(params['date_coverage_from']),
16
+ date_coverage_to: date_parser(params['date_coverage_to']),
17
+ committee: parse_committee(params['committee']),
18
+ report_title: params['report_title'].strip,
19
+ fec_uri: params['fec_uri'],
20
+ amended: params['amended'],
21
+ amended_uri: params['amended_uri'],
22
+ original_filing: params['original_filing'],
23
+ original_uri: params['original_uri'],
24
+ paper: params['paper'],
25
+ form_type: params['form_type'],
26
+ filing_id: params['filing_id'],
27
+ committee_type: Committee.get_committee_type(params['committee_type']),
28
+ committee_name: params['committee_name'],
29
+ receipts_total: params['receipts_total'],
30
+ contributions_total: params['contributions_total'],
31
+ disbursements_total: params['disbursements_total'],
32
+ cash_on_hand: params['cash_on_hand'],
33
+ is_amendment: params['is_amendment']
34
34
  end
35
35
 
36
36
  def self.today(offset=nil)
37
37
  cycle=CURRENT_CYCLE
38
- reply = Base.invoke("#{cycle}/filings", {:offset => offset})
38
+ reply = Base.invoke("#{cycle}/filings", {offset: offset})
39
39
  results = reply['results']
40
40
  results.map{|c| Filing.create(c)}
41
41
  end
42
42
 
43
43
  def self.date(year, month, day, offset=nil)
44
44
  cycle = cycle_from_date(Date.strptime("#{month}/#{day}/#{year}", '%m/%d/%Y'))
45
- reply = Base.invoke("#{cycle}/filings/#{year}/#{month}/#{day}", {:offset => offset})
45
+ reply = Base.invoke("#{cycle}/filings/#{year}/#{month}/#{day}", {offset: offset})
46
46
  results = reply['results']
47
47
  results.map{|c| Filing.create(c)}
48
48
  end
@@ -51,12 +51,12 @@ module CampaignCash
51
51
  cycle=CURRENT_CYCLE
52
52
  reply = Base.invoke("#{cycle}/filings/types",{})
53
53
  results = reply['results']
54
- results.map{|ft| OpenStruct.new({:id => ft['id'], :name => ft['name'].strip})}
54
+ results.map{|ft| OpenStruct.new({id: ft['id'], name: ft['name'].strip})}
55
55
  end
56
56
 
57
57
  def self.amendments(offset=nil)
58
58
  cycle=CURRENT_CYCLE
59
- reply = Base.invoke("#{cycle}/filings/amendments", {:offset => offset})
59
+ reply = Base.invoke("#{cycle}/filings/amendments", {offset: offset})
60
60
  results = reply['results']
61
61
  results.map{|c| Filing.create(c)}
62
62
  end
@@ -10,8 +10,8 @@ module CampaignCash
10
10
  end
11
11
 
12
12
  def self.create(params={})
13
- self.new :id => params['id'],
14
- :name => params['name']
13
+ self.new id: params['id'],
14
+ name: params['name']
15
15
  end
16
16
 
17
17
  def self.form_types
@@ -2,8 +2,8 @@ module CampaignCash
2
2
  class IndependentExpenditure < Base
3
3
 
4
4
  attr_reader :committee, :district, :state, :committee_name, :purpose, :candidate, :candidate_name,
5
- :support_or_oppose, :date, :amount, :office, :amendment, :date_received, :payee, :fec_uri,
6
- :transaction_id, :unique_id, :filing_id, :amended_from
5
+ :support_or_oppose, :date, :amount, :office, :amendment, :date_received, :payee, :fec_uri,
6
+ :transaction_id, :unique_id, :filing_id, :amended_from
7
7
 
8
8
  def initialize(params={})
9
9
  params.each_pair do |k,v|
@@ -12,32 +12,32 @@ module CampaignCash
12
12
  end
13
13
 
14
14
  def self.create(params={})
15
- self.new :committee => parse_committee(params['fec_committee']),
16
- :committee_name => params['fec_committee_name'],
17
- :candidate => parse_candidate(params['fec_candidate']),
18
- :office => params['office'],
19
- :state => params['state'] ? params['state'].strip : nil,
20
- :district => params['district'],
21
- :date => date_parser(params['date']),
22
- :support_or_oppose => params['support_or_oppose'],
23
- :payee => params['payee'],
24
- :purpose => params['purpose'],
25
- :amount => params['amount'].to_f,
26
- :fec_uri => params['fec_uri'],
27
- :date_received => date_parser(params['date_received']),
28
- :amendment => params['amendment'],
29
- :transaction_id => params['transaction_id'],
30
- :candidate_name => params['candidate_name'],
31
- :filing_id => params['filing_id'].to_i,
32
- :amended_from => params['amended_from'], # <= original filing ID will be nil if amendment is false
15
+ self.new committee: parse_committee(params['fec_committee']),
16
+ committee_name: params['fec_committee_name'],
17
+ candidate: parse_candidate(params['fec_candidate']),
18
+ office: params['office'],
19
+ state: params['state'] ? params['state'].strip : nil,
20
+ district: params['district'],
21
+ date: date_parser(params['date']),
22
+ support_or_oppose: params['support_or_oppose'],
23
+ payee: params['payee'],
24
+ purpose: params['purpose'],
25
+ amount: params['amount'].to_f,
26
+ fec_uri: params['fec_uri'],
27
+ date_received: date_parser(params['date_received']),
28
+ amendment: params['amendment'],
29
+ transaction_id: params['transaction_id'],
30
+ candidate_name: params['candidate_name'],
31
+ filing_id: params['filing_id'].to_i,
32
+ amended_from: params['amended_from'], # <= original filing ID will be nil if amendment is false
33
33
  # unique_id is a SHA1 of filing_id and transaction_id
34
34
  # If the expenditure is amended, the unique_id will be amended_from + transaction_id
35
35
  # so it can be used as an overrideable unique key
36
- :unique_id => params['unique_id']
36
+ unique_id: params['unique_id']
37
37
  end
38
38
 
39
39
  def self.latest(offset=nil)
40
- reply = Base.invoke("#{Base::CURRENT_CYCLE}/independent_expenditures",{:offset => offset})
40
+ reply = Base.invoke("#{Base::CURRENT_CYCLE}/independent_expenditures",{offset: offset})
41
41
  results = reply['results']
42
42
  results.map{|c| IndependentExpenditure.create(c)}
43
43
  end
@@ -45,14 +45,14 @@ module CampaignCash
45
45
  def self.date(date,offset=nil)
46
46
  d = Date.strptime(date, '%m/%d/%Y')
47
47
  cycle = cycle_from_date(d)
48
- reply = Base.invoke("#{cycle}/independent_expenditures/#{d.year}/#{d.month}/#{d.day}", {:offset => offset})
48
+ reply = Base.invoke("#{cycle}/independent_expenditures/#{d.year}/#{d.month}/#{d.day}", {offset: offset})
49
49
  results = reply['results']
50
50
  results.map{|c| IndependentExpenditure.create(c)}
51
51
  end
52
52
 
53
53
  def self.committee(id, cycle, offset=nil)
54
54
  independent_expenditures = []
55
- reply = Base.invoke("#{cycle}/committees/#{id}/independent_expenditures",{:offset => offset})
55
+ reply = Base.invoke("#{cycle}/committees/#{id}/independent_expenditures",{offset: offset})
56
56
  results = reply['results']
57
57
  comm = reply['fec_committee']
58
58
  results.each do |result|
@@ -64,7 +64,7 @@ module CampaignCash
64
64
 
65
65
  def self.candidate(id, cycle, offset=nil)
66
66
  independent_expenditures = []
67
- reply = Base.invoke("#{cycle}/candidates/#{id}/independent_expenditures",{:offset => offset})
67
+ reply = Base.invoke("#{cycle}/candidates/#{id}/independent_expenditures",{offset: offset})
68
68
  results = reply['results']
69
69
  cand = reply['fec_candidate']
70
70
  results.each do |result|
@@ -75,7 +75,7 @@ module CampaignCash
75
75
  end
76
76
 
77
77
  def self.president(cycle=CURRENT_CYCLE,offset=nil)
78
- reply = Base.invoke("#{cycle}/president/independent_expenditures",{:offset => offset})
78
+ reply = Base.invoke("#{cycle}/president/independent_expenditures",{offset: offset})
79
79
  results = reply['results']
80
80
  results.map{|c| IndependentExpenditure.create(c)}
81
81
  end
@@ -15,21 +15,14 @@ module CampaignCash
15
15
 
16
16
  def self.committee(fecid, offset=nil)
17
17
  cycle = CURRENT_CYCLE
18
- results = invoke("#{cycle}/contributions/committee/#{fecid}", {:offset => offset})['results']
18
+ results = invoke("#{cycle}/contributions/committee/#{fecid}", {offset: offset})['results']
19
19
  results.map{|c| IndividualContribution.create(c) }
20
20
  end
21
21
 
22
22
  def self.filing(form_id, offset=nil)
23
23
  cycle = CURRENT_CYCLE
24
- results = invoke("#{cycle}/contributions/filing/#{form_id}", {:offset => offset})['results']
24
+ results = invoke("#{cycle}/contributions/filing/#{form_id}", {offset: offset})['results']
25
25
  results.map{|c| IndividualContribution.create(c) }
26
26
  end
27
-
28
- def self.candidate(fecid, offset=nil)
29
- cycle = CURRENT_CYCLE
30
- results = invoke("#{cycle}/contributions/candidate/#{fecid}", {:offset => offset})['results']
31
- results.map{|c| IndividualContribution.create(c) }
32
- end
33
-
34
27
  end
35
28
  end
@@ -2,9 +2,9 @@ module CampaignCash
2
2
  class LateContribution < Base
3
3
 
4
4
  attr_reader :contribution_date, :contributor_prefix, :contributor_zip, :contributor_suffix, :contributor_state,
5
- :entity_type, :contributor_employer, :contributor_occupation, :fec_committee_id, :transaction_id, :contributor_last_name,
6
- :office_state, :contributor_fec_id, :contribution_amount, :contributor_street_1, :contributor_street_2, :contributor_city,
7
- :contributor_middle_name, :cycle, :fec_filing_id, :fec_candidate_id, :contributor_first_name, :contributor_organization_name
5
+ :entity_type, :contributor_employer, :contributor_occupation, :fec_committee_id, :transaction_id, :contributor_last_name,
6
+ :office_state, :contributor_fec_id, :contribution_amount, :contributor_street_1, :contributor_street_2, :contributor_city,
7
+ :contributor_middle_name, :cycle, :fec_filing_id, :fec_candidate_id, :contributor_first_name, :contributor_organization_name
8
8
 
9
9
  def initialize(params={})
10
10
  params.each_pair do |k,v|
@@ -18,19 +18,19 @@ module CampaignCash
18
18
 
19
19
  def self.latest(offset = nil)
20
20
  cycle = CURRENT_CYCLE
21
- results = invoke("#{cycle}/contributions/48hour", {:offset => offset})['results']
21
+ results = invoke("#{cycle}/contributions/48hour", {offset: offset})['results']
22
22
  results.map {|obj| create(obj)}
23
23
  end
24
24
 
25
25
  def self.candidate(candidate_id, offset = nil)
26
26
  cycle = CURRENT_CYCLE
27
- results = invoke("#{cycle}/candidates/#{candidate_id}/48hour", {:offset => offset})['results']
27
+ results = invoke("#{cycle}/candidates/#{candidate_id}/48hour", {offset: offset})['results']
28
28
  results.map {|obj| create(obj)}
29
29
  end
30
30
 
31
31
  def self.committee(committee_id, offset = nil)
32
32
  cycle = CURRENT_CYCLE
33
- results = invoke("#{cycle}/committees/#{committee_id}/48hour", {:offset => offset})['results']
33
+ results = invoke("#{cycle}/committees/#{committee_id}/48hour", {offset: offset})['results']
34
34
  results.map {|obj| create(obj)}
35
35
  end
36
36
  end
@@ -2,10 +2,10 @@ module CampaignCash
2
2
  class President < Base
3
3
 
4
4
  attr_reader :committee_id, :name, :id, :party, :office, :date_coverage_from, :date_coverage_to, :total_receipts, :total_disbursements,
5
- :end_cash, :total_refunds, :total_contributions, :net_individual_contributions, :net_pac_contributions, :transfers_in,
6
- :net_party_contributions, :net_candidate_contributions, :net_primary_contributions, :net_general_contributions,
7
- :federal_funds, :contributions_less_than_200, :contributions_200_499, :contributions_500_1499, :contributions_1500_2499,
8
- :contributions_max
5
+ :end_cash, :total_refunds, :total_contributions, :net_individual_contributions, :net_pac_contributions, :transfers_in,
6
+ :net_party_contributions, :net_candidate_contributions, :net_primary_contributions, :net_general_contributions,
7
+ :federal_funds, :contributions_less_than_200, :contributions_200_499, :contributions_500_1499, :contributions_1500_2499,
8
+ :contributions_max
9
9
 
10
10
  def initialize(params={})
11
11
  params.each_pair do |k,v|
@@ -15,45 +15,45 @@ module CampaignCash
15
15
 
16
16
  # Creates a new president summary object from a JSON API presidential response.
17
17
  def self.create_summary(params={})
18
- self.new :name => params['name'],
19
- :id => params['candidate_id'],
20
- :party => get_party(params['party']),
21
- :office => 'president',
22
- :committee_id => params['committee_id'],
23
- :total_receipts => params['total_receipts'],
24
- :total_disbursements => params['total_disbursements'],
25
- :end_cash => params['cash_on_hand'],
26
- :date_coverage_from => params['date_coverage_from'],
27
- :date_coverage_to => params['date_coverage_to']
18
+ self.new name: params['name'],
19
+ id: params['candidate_id'],
20
+ party: get_party(params['party']),
21
+ office: 'president',
22
+ committee_id: params['committee_id'],
23
+ total_receipts: params['total_receipts'],
24
+ total_disbursements: params['total_disbursements'],
25
+ end_cash: params['cash_on_hand'],
26
+ date_coverage_from: params['date_coverage_from'],
27
+ date_coverage_to: params['date_coverage_to']
28
28
  end
29
29
 
30
30
  # Creates a detailed president object
31
31
  def self.create_detail(params={})
32
- self.new :name => params['candidate_name'],
33
- :id => params['candidate_id'],
34
- :party => get_party(params['party']),
35
- :office => 'president',
36
- :committee_id => params['committee_id'],
37
- :total_receipts => params['total_receipts'],
38
- :total_contributions => params['total_contributions'],
39
- :total_disbursements => params['total_disbursements'],
40
- :end_cash => params['cash_on_hand'],
41
- :date_coverage_from => params['date_coverage_from'],
42
- :date_coverage_to => params['date_coverage_to'],
43
- :total_refunds => params['total_refunds'],
44
- :net_individual_contributions => params['net_individual_contributions'],
45
- :net_pac_contributions => params['net_pac_contributions'],
46
- :net_party_contributions => params['net_party_contributions'],
47
- :net_candidate_contributions => params['net_candidate_contributions'],
48
- :net_primary_contributions => params['net_primary_contributions'],
49
- :net_general_contributions => params['net_general_contributions'],
50
- :federal_funds => params['federal_funds'],
51
- :transfers_in => params['transfers_in'],
52
- :contributions_less_than_200 => params['total_contributions_less_than_200'],
53
- :contributions_200_499 => params['contributions_200_499'],
54
- :contributions_500_1499 => params['contributions_500_1499'],
55
- :contributions_1500_2499 => params['contributions_1500_2499'],
56
- :contributions_max => params['total_contributions_max']
32
+ self.new name: params['candidate_name'],
33
+ id: params['candidate_id'],
34
+ party: get_party(params['party']),
35
+ office: 'president',
36
+ committee_id: params['committee_id'],
37
+ total_receipts: params['total_receipts'],
38
+ total_contributions: params['total_contributions'],
39
+ total_disbursements: params['total_disbursements'],
40
+ end_cash: params['cash_on_hand'],
41
+ date_coverage_from: params['date_coverage_from'],
42
+ date_coverage_to: params['date_coverage_to'],
43
+ total_refunds: params['total_refunds'],
44
+ net_individual_contributions: params['net_individual_contributions'],
45
+ net_pac_contributions: params['net_pac_contributions'],
46
+ net_party_contributions: params['net_party_contributions'],
47
+ net_candidate_contributions: params['net_candidate_contributions'],
48
+ net_primary_contributions: params['net_primary_contributions'],
49
+ net_general_contributions: params['net_general_contributions'],
50
+ federal_funds: params['federal_funds'],
51
+ transfers_in: params['transfers_in'],
52
+ contributions_less_than_200: params['total_contributions_less_than_200'],
53
+ contributions_200_499: params['contributions_200_499'],
54
+ contributions_500_1499: params['contributions_500_1499'],
55
+ contributions_1500_2499: params['contributions_1500_2499'],
56
+ contributions_max: params['total_contributions_max']
57
57
  end
58
58
 
59
59
  # Returns an array of presidential candidates for a given cycle, defaults to the current cycle.