Class: OpenFec::Resources::ContributionAggregates

Inherits:
Base
  • Object
show all
Defined in:
lib/open_fec/resources/contribution_aggregates.rb

Overview

Aggregated contribution data (by employer, occupation, size, state, zip). All endpoints use offset-based pagination.

Examples:

Top employer donors to a committee

OpenFec.contribution_aggregates.by_employer(
  committee_id: 'C00213512', cycle: 2024, sort: '-total', per_page: 10
)

Donations by zip code

OpenFec.contribution_aggregates.by_zip(
  committee_id: 'C00555888', cycle: 2024, sort: '-total', per_page: 10
)

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from OpenFec::Resources::Base

Instance Method Details

#by_employer(committee_id:, cycle:, **params) ⇒ OpenFec::Response

Contributions aggregated by employer. Returns: employer, total, count, cycle.

Parameters:

  • committee_id (String)

    FEC committee ID

  • cycle (Integer)

    election cycle year

  • params (Hash)

    additional params (:sort, :per_page, etc.)

Returns:



25
26
27
28
# File 'lib/open_fec/resources/contribution_aggregates.rb', line 25

def by_employer(committee_id:, cycle:, **params)
  get('schedules/schedule_a/by_employer/',
      params.merge(committee_id: committee_id, cycle: cycle))
end

#by_occupation(committee_id:, cycle:, **params) ⇒ OpenFec::Response

Contributions aggregated by occupation.

Parameters:

  • committee_id (String)

    FEC committee ID

  • cycle (Integer)

    election cycle year

  • params (Hash)

    additional params

Returns:



36
37
38
39
# File 'lib/open_fec/resources/contribution_aggregates.rb', line 36

def by_occupation(committee_id:, cycle:, **params)
  get('schedules/schedule_a/by_occupation/',
      params.merge(committee_id: committee_id, cycle: cycle))
end

#by_size(candidate_id:, cycle:, **params) ⇒ OpenFec::Response

Contributions aggregated by size (small/medium/large dollar).

Parameters:

  • candidate_id (String)

    FEC candidate ID

  • cycle (Integer)

    election cycle year

  • params (Hash)

    additional params

Returns:



47
48
49
50
# File 'lib/open_fec/resources/contribution_aggregates.rb', line 47

def by_size(candidate_id:, cycle:, **params)
  get('schedules/schedule_a/by_size/by_candidate/',
      params.merge(candidate_id: candidate_id, cycle: cycle))
end

#by_state(candidate_id:, cycle:, **params) ⇒ OpenFec::Response

Contributions aggregated by state.

Parameters:

  • candidate_id (String)

    FEC candidate ID

  • cycle (Integer)

    election cycle year

  • params (Hash)

    additional params

Returns:



58
59
60
61
# File 'lib/open_fec/resources/contribution_aggregates.rb', line 58

def by_state(candidate_id:, cycle:, **params)
  get('schedules/schedule_a/by_state/by_candidate/',
      params.merge(candidate_id: candidate_id, cycle: cycle))
end

#by_zip(committee_id:, cycle:, **params) ⇒ OpenFec::Response

Contributions aggregated by zip code. Returns: zip, total, count, cycle.

Parameters:

  • committee_id (String)

    FEC committee ID

  • cycle (Integer)

    election cycle year

  • params (Hash)

    additional params (:sort, :per_page, etc.)

Returns:



70
71
72
73
# File 'lib/open_fec/resources/contribution_aggregates.rb', line 70

def by_zip(committee_id:, cycle:, **params)
  get('schedules/schedule_a/by_zip/',
      params.merge(committee_id: committee_id, cycle: cycle))
end

#each_employer_page(committee_id:, cycle:, **params) {|OpenFec::Response| ... } ⇒ Object

Paginate through employer contribution aggregates.

Parameters:

  • committee_id (String)

    FEC committee ID

  • cycle (Integer)

    election cycle year

  • params (Hash)

    additional params

Yields:



81
82
83
84
# File 'lib/open_fec/resources/contribution_aggregates.rb', line 81

def each_employer_page(committee_id:, cycle:, **params, &)
  client.paginate('schedules/schedule_a/by_employer/',
                  params.merge(committee_id: committee_id, cycle: cycle), &)
end