Class: GovKit::FollowTheMoneyResource
- Defined in:
- lib/gov_kit/follow_the_money.rb
Overview
Subclass of Resource for FollowTheMoney data. This is subclassed further for each of the different types of record returned by FollowTheMoney.
For the details on the FollowTheMoney queries, see the FollowTheMoney API documentation.
Direct Known Subclasses
GovKit::FollowTheMoney::Business, GovKit::FollowTheMoney::Contribution
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.get_xml(path, options) ⇒ Nokogiri::XML::Document
Common method used by subclasses to get data from the service.
-
.stringify_values_of(result) ⇒ Array
Convert the hash array returned by Nokogiri, which has Nokogiri::XML::Attr objects as values, to an array of hashes with string values.
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
.get_xml(path, options) ⇒ Nokogiri::XML::Document
Common method used by subclasses to get data from the service.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gov_kit/follow_the_money.rb', line 21 def self.get_xml(path, ) doc = Nokogiri::XML(get(path, )) e = doc.search("//error") # Deal with whatever error comes back if e.size > 0 raise case e.first.attributes['code'].value when "100" GovKit::NotAuthorized when "300" GovKit::InvalidRequest when "200" GovKit::ResourceNotFound else GovKit::InvalidRequest end, e.first.attributes['text'].value end doc end |
.stringify_values_of(result) ⇒ Array
Convert the hash array returned by Nokogiri, which has Nokogiri::XML::Attr objects as values, to an array of hashes with string values.
48 49 50 |
# File 'lib/gov_kit/follow_the_money.rb', line 48 def self.stringify_values_of(result) result.collect! { |r| r.inject({}) {|h, (k, v)| h[k] = v.to_s; h } } end |