Class: GovKit::FollowTheMoney::Contribution

Inherits:
GovKit::FollowTheMoneyResource show all
Defined in:
lib/gov_kit/follow_the_money.rb

Overview

Wrap contributions to a candidate. See the FollowTheMoney API.

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #raw_response

Class Method Summary collapse

Methods inherited from GovKit::FollowTheMoneyResource

get_xml, stringify_values_of

Methods inherited from Resource

#initialize, instantiate, instantiate_collection, parse, #to_md5, #unload

Constructor Details

This class inherits a constructor from GovKit::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GovKit::Resource

Class Method Details

.find(nimsp_id) ⇒ Contribution

Return contributions to a candidate. See the FollowTheMoney API.

Parameters:

  • nimsp_id (Integer)

    the candidate id.

Returns:

  • (Contribution)

    a Contribution object, or array of Contribution objects, representing the contributions.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/gov_kit/follow_the_money.rb', line 92

def self.find(nimsp_id)
  next_page, result, page_num = "yes", [], 0

  until next_page != "yes"
    doc = get_xml("/candidates.contributions.php", :query => {"imsp_candidate_id" => nimsp_id, :page => page_num})

    next_page = doc.children.first.attributes['next_page'].value

    page_num += 1

    result += doc.search('//contribution').collect { |x| x.attributes }
  end

  stringify_values_of(result)
  parse(result)
end

.top(nimsp_id) ⇒ [Contribution]

Return a list of the top contributors to a candidate. See the FollowTheMoney API.

Parameters:

  • nimsp_id (Integer)

    the candidate id.

Returns:



114
115
116
117
118
119
120
# File 'lib/gov_kit/follow_the_money.rb', line 114

def self.top(nimsp_id)
  doc = get_xml("/candidates.top_contributor.php", :query => {"imsp_candidate_id" => nimsp_id})
  result = doc.search('//top_contributor').collect { |x| x.attributes }

  stringify_values_of(result)
  parse(result)
end