Class: GovKit::FollowTheMoneyResource

Inherits:
Resource
  • Object
show all
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.

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #raw_response

Class Method Summary collapse

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.

Examples:

doc = get_xml("/base_level.industries.list.php", :query => {:page => page_num})

Parameters:

  • path (String)

    query path that specifies the required data

  • options (Hash)

    query options

Returns:



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, options)
  doc = Nokogiri::XML(get(path, options))

  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.

Parameters:

  • result (Array)

    array of hashes, with object values.

Returns:

  • (Array)

    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