Class: OpenCongressApi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/opencongress_api/fetcher/base.rb

Direct Known Subclasses

Fetcher::Bills, Fetcher::People

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



19
20
21
# File 'lib/opencongress_api/fetcher/base.rb', line 19

def initialize
  @type = nil
end

Instance Method Details

#fetch(options = {}) ⇒ Object

Fetch and parse a response based on a set of options Override this method to ensure necessary options are passed for the request



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/opencongress_api/fetcher/base.rb', line 28

def fetch(options = {})
  url = build_url(options)
  puts "Getting #{url}"

  json = get_response(url)

  if self.is_json?
    data = JSON.parse(json)
  else
    data = XmlSimple.xml_in(json)
  end

  # TODO: Raise hell if there is a problem

  collection = OpenCongressApi::Collection.build(json_result(data))
  collection.map!{|result| format_result(result)}
end